Skip to content

Commit c4d494a

Browse files
committed
refactor: Re-use partition_by in ArrowGroupBy.__iter__
1 parent ac779dd commit c4d494a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

narwhals/_plan/arrow/group_by.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from narwhals._plan._dispatch import get_dispatch_name
1010
from narwhals._plan._guards import is_agg_expr, is_function_expr
1111
from narwhals._plan.arrow import acero, functions as fn, options
12-
from narwhals._plan.common import temp
1312
from narwhals._plan.compliant.group_by import EagerDataFrameGroupBy
1413
from narwhals._plan.expressions import aggregation as agg
1514
from narwhals._utils import Implementation
@@ -157,15 +156,14 @@ def compliant(self) -> Frame:
157156
return self._df
158157

159158
def __iter__(self) -> Iterator[tuple[Any, Frame]]:
160-
temp_name = temp.column_name(self.compliant)
161-
native = self.compliant.native
162-
composite_values = concat_str(acero.select_names_table(native, self.key_names))
163-
re_keyed = native.add_column(0, temp_name, composite_values)
159+
from narwhals._plan.arrow.dataframe import partition_by
160+
161+
by = self.key_names
164162
from_native = self.compliant._with_native
165-
for v in composite_values.unique():
166-
t = from_native(acero.filter_table(re_keyed, pc.field(temp_name) == v))
163+
for partition in partition_by(self.compliant.native, by):
164+
t = from_native(partition)
167165
yield (
168-
t.select_names(*self.key_names).row(0),
166+
t.select_names(*by).row(0),
169167
t.select_names(*self._column_names_original),
170168
)
171169

0 commit comments

Comments
 (0)