Skip to content

Commit 7d5a457

Browse files
authored
fix: Use updated from_arrow import for modin (#2919)
1 parent 2dacbb2 commit 7d5a457

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

narwhals/_pandas_like/dataframe.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ def from_arrow(cls, data: IntoArrowTable, /, *, context: _LimitedContext) -> Sel
119119
tbl = _into_arrow_table(data, context)
120120
if implementation.is_pandas():
121121
native = tbl.to_pandas()
122-
elif implementation.is_modin(): # pragma: no cover
123-
from modin.pandas.utils import (
124-
from_arrow as mpd_from_arrow, # pyright: ignore[reportAttributeAccessIssue]
125-
)
126-
122+
elif implementation.is_modin():
123+
# NOTE: Function moved + deprecated (0.26.0), then old path removed (0.31.0)
124+
# https://github.com/modin-project/modin/pull/6806
125+
# https://github.com/modin-project/modin/pull/7274
126+
if implementation._backend_version() >= (0, 26, 0):
127+
from modin.pandas.io import from_arrow as mpd_from_arrow
128+
else: # pragma: no cover
129+
from modin.pandas.utils import (
130+
from_arrow as mpd_from_arrow, # pyright: ignore[reportAttributeAccessIssue]
131+
)
127132
native = mpd_from_arrow(tbl)
128133
elif implementation.is_cudf(): # pragma: no cover
129134
native = implementation.to_native_namespace().DataFrame.from_arrow(tbl)

tests/frame/from_arrow_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ def test_dataframe_from_arrow_to_polars_no_pandas(
7676
assert "pandas" not in sys.modules
7777

7878

79+
def test_dataframe_from_arrow_modin(table: pa.Table, data: dict[str, Any]) -> None:
80+
pytest.importorskip("modin.pandas")
81+
result = nw.DataFrame.from_arrow(table, backend="modin")
82+
assert result.implementation.is_modin()
83+
assert_equal_data(result, data)
84+
85+
7986
def test_dataframe_from_arrow_invalid(table: pa.Table, data: dict[str, Any]) -> None:
8087
with pytest.raises(TypeError, match="PyCapsule"):
8188
nw.DataFrame.from_arrow(data, backend=pa) # type: ignore[arg-type]

0 commit comments

Comments
 (0)