Skip to content

Commit 425dbe4

Browse files
authored
fix: support groupby.iter for cudf (#1265)
1 parent 33c9527 commit 425dbe4

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

narwhals/_pandas_like/group_by.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ def _from_native_frame(self, df: PandasLikeDataFrame) -> PandasLikeDataFrame:
103103

104104
def __iter__(self) -> Iterator[tuple[Any, PandasLikeDataFrame]]:
105105
indices = self._grouped.indices
106-
for key in indices:
107-
if (
108-
self._df._implementation is Implementation.PANDAS
109-
and self._df._backend_version < (2, 2)
110-
): # pragma: no cover
111-
pass
112-
else: # pragma: no cover
106+
if (
107+
self._df._implementation is Implementation.PANDAS
108+
and self._df._backend_version < (2, 2)
109+
) or (self._df._implementation is Implementation.CUDF): # pragma: no cover
110+
for key in indices:
111+
yield (key, self._from_native_frame(self._grouped.get_group(key)))
112+
else:
113+
for key in indices:
113114
key = tupleify(key) # noqa: PLW2901
114-
yield (key, self._from_native_frame(self._grouped.get_group(key)))
115+
yield (key, self._from_native_frame(self._grouped.get_group(key)))
115116

116117

117118
def agg_pandas( # noqa: PLR0915

tests/group_by_test.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ def test_invalid_group_by() -> None:
7474
)
7575

7676

77-
def test_group_by_iter(
78-
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
79-
) -> None:
80-
if "cudf" in str(constructor_eager):
81-
# https://github.com/rapidsai/cudf/issues/17187
82-
request.applymarker(pytest.mark.xfail)
77+
def test_group_by_iter(constructor_eager: ConstructorEager) -> None:
8378
df = nw.from_native(constructor_eager(data), eager_only=True)
8479
expected_keys = [(1,), (3,)]
8580
keys = []

0 commit comments

Comments
 (0)