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
15 changes: 10 additions & 5 deletions narwhals/_pandas_like/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ def from_arrow(cls, data: IntoArrowTable, /, *, context: _LimitedContext) -> Sel
tbl = _into_arrow_table(data, context)
if implementation.is_pandas():
native = tbl.to_pandas()
elif implementation.is_modin(): # pragma: no cover
from modin.pandas.utils import (
from_arrow as mpd_from_arrow, # pyright: ignore[reportAttributeAccessIssue]
)

elif implementation.is_modin():
# NOTE: Function moved + deprecated (0.26.0), then old path removed (0.31.0)
# https://github.com/modin-project/modin/pull/6806
# https://github.com/modin-project/modin/pull/7274
if implementation._backend_version() >= (0, 26, 0):
from modin.pandas.io import from_arrow as mpd_from_arrow
else: # pragma: no cover
from modin.pandas.utils import (
from_arrow as mpd_from_arrow, # pyright: ignore[reportAttributeAccessIssue]
)
Comment on lines +122 to +131
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know ordering the branches the other way would appease coverage

They're this way around so that the known type comes before Unknown

native = mpd_from_arrow(tbl)
elif implementation.is_cudf(): # pragma: no cover
native = implementation.to_native_namespace().DataFrame.from_arrow(tbl)
Expand Down
7 changes: 7 additions & 0 deletions tests/frame/from_arrow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def test_dataframe_from_arrow_to_polars_no_pandas(
assert "pandas" not in sys.modules


def test_dataframe_from_arrow_modin(table: pa.Table, data: dict[str, Any]) -> None:
pytest.importorskip("modin.pandas")
result = nw.DataFrame.from_arrow(table, backend="modin")
assert result.implementation.is_modin()
assert_equal_data(result, data)


def test_dataframe_from_arrow_invalid(table: pa.Table, data: dict[str, Any]) -> None:
with pytest.raises(TypeError, match="PyCapsule"):
nw.DataFrame.from_arrow(data, backend=pa) # type: ignore[arg-type]
Expand Down
Loading