Skip to content

Commit 920e0d1

Browse files
authored
chore: take reset_index(inplace=True) out of _select_results (#2828)
chore: take `reset_index(inplace=True)` out of `_select_results`, skip decimal test for polars pre 1.20
1 parent b2afcea commit 920e0d1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

narwhals/_pandas_like/group_by.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ def agg(self, *exprs: PandasLikeExpr) -> PandasLikeDataFrame:
219219
raise empty_results_error()
220220
else:
221221
result = self._apply_aggs(exprs)
222+
# NOTE: Keep `inplace=True` to avoid making a redundant copy.
223+
# This may need updating, depending on https://github.com/pandas-dev/pandas/pull/51466/files
224+
result.reset_index(inplace=True) # noqa: PD002
222225
return self._select_results(result, agg_exprs)
223226

224227
def _select_results(
@@ -228,9 +231,6 @@ def _select_results(
228231
229232
See `ParseKeysGroupBy`.
230233
"""
231-
# NOTE: Keep `inplace=True` to avoid making a redundant copy.
232-
# This may need updating, depending on https://github.com/pandas-dev/pandas/pull/51466/files
233-
df.reset_index(inplace=True) # noqa: PD002
234234
new_names = chain.from_iterable(e.aliases for e in agg_exprs)
235235
return (
236236
self.compliant._with_native(df, validate_column_names=False)

tests/frame/group_by_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def test_group_by_no_preserve_dtype(
604604
if (
605605
"polars" in str(constructor_eager)
606606
and isinstance(low, Decimal)
607-
and POLARS_VERSION < (1, 0, 0)
607+
and POLARS_VERSION < (1, 21, 0)
608608
):
609609
pytest.skip("Decimal support in group_by for polars didn't stabilize until 1.0.0")
610610
data = {

0 commit comments

Comments
 (0)