Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docarray/array/doc_list/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def to_csv(
writer.writerow(doc_dict)

@classmethod
def from_pandas(cls, df: 'pd.DataFrame') -> 'DocList':
def from_dataframe(cls, df: 'pd.DataFrame') -> 'DocList':
"""
Load a DocList from a `pandas.DataFrame` following the schema
defined in the :attr:`~docarray.DocList.doc_type` attribute.
Expand Down Expand Up @@ -456,7 +456,7 @@ class Person(BaseDoc):
data=[['Maria', 12345], ['Jake', 54321]], columns=['name', 'follower']
)

docs = DocList[Person].from_pandas(df)
docs = DocList[Person].from_dataframe(df)

assert docs.name == ['Maria', 'Jake']
assert docs.follower == [12345, 54321]
Expand Down Expand Up @@ -499,7 +499,7 @@ class Person(BaseDoc):

return docs

def to_pandas(self) -> 'pd.DataFrame':
def to_dataframe(self) -> 'pd.DataFrame':
"""
Save a DocList to a `pandas.DataFrame`.
The field names will be stored as column names. Each row of the dataframe corresponds
Expand Down
8 changes: 4 additions & 4 deletions tests/units/array/test_array_from_to_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_to_from_pandas_df(nested_doc_cls):
nested_doc_cls(text='hello world', image=ImageDoc()),
]
)
df = da.to_pandas()
df = da.to_dataframe()
assert isinstance(df, pd.DataFrame)
assert len(df) == 2
assert (
Expand All @@ -47,7 +47,7 @@ def test_to_from_pandas_df(nested_doc_cls):
]
).all()

da_from_df = DocList[nested_doc_cls].from_pandas(df)
da_from_df = DocList[nested_doc_cls].from_dataframe(df)
for doc1, doc2 in zip(da, da_from_df):
assert doc1 == doc2

Expand Down Expand Up @@ -76,12 +76,12 @@ def test_from_pandas_without_schema_raise_exception():
df = pd.DataFrame(
columns=['title', 'count'], data=[['title 0', 0], ['title 1', 1]]
)
DocList.from_pandas(df=df)
DocList.from_dataframe(df=df)


def test_from_pandas_with_wrong_schema_raise_exception(nested_doc):
with pytest.raises(ValueError, match='Column names do not match the schema'):
df = pd.DataFrame(
columns=['title', 'count'], data=[['title 0', 0], ['title 1', 1]]
)
DocList[nested_doc.__class__].from_pandas(df=df)
DocList[nested_doc.__class__].from_dataframe(df=df)