Skip to content

Commit

Permalink
another strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Oct 26, 2024
1 parent e6e82e0 commit 77cb4b7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions narwhals/_pandas_like/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,19 @@ def _from_native_frame(self, df: PandasLikeDataFrame) -> PandasLikeDataFrame:
)

def __iter__(self) -> Iterator[tuple[Any, PandasLikeDataFrame]]:
indices = self._grouped.indices
with warnings.catch_warnings():
# we already use `tupleify` above, so we're already opting in to
# the new behaviour
warnings.filterwarnings(
"ignore",
message="In a future version of pandas, a length 1 tuple will be returned",
message="When grouping with a length-1",
category=FutureWarning,
)
iterator = self._grouped.__iter__()
yield from ((key, self._from_native_frame(sub_df)) for (key, sub_df) in iterator)
yield from (
(key, self._from_native_frame(self._grouped.get_group(key)))
for key in indices
)


def agg_pandas( # noqa: PLR0915
Expand Down

0 comments on commit 77cb4b7

Please sign in to comment.