Skip to content

Commit 46282e8

Browse files
committed
revert: try rename with copy=True
24eb873
1 parent 24eb873 commit 46282e8

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

narwhals/_pandas_like/dataframe.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,10 @@ def with_columns(self, *exprs: PandasLikeExpr) -> Self:
459459
df.columns.name = self.native.columns.name
460460
return self._with_native(df, validate_column_names=False)
461461

462-
def rename(self, mapping: Mapping[str, str], *, copy: bool = False) -> Self:
462+
def rename(self, mapping: Mapping[str, str]) -> Self:
463463
if mapping:
464464
return self._with_native(
465-
rename(
466-
self.native,
467-
columns=mapping,
468-
implementation=self._implementation,
469-
copy=copy,
470-
)
465+
rename(self.native, columns=mapping, implementation=self._implementation)
471466
)
472467
return self._with_native(self.native, validate_column_names=False)
473468

narwhals/_pandas_like/group_by.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from functools import lru_cache
55
from itertools import chain
66
from operator import methodcaller
7-
from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast, overload
7+
from typing import TYPE_CHECKING, Any, ClassVar, Literal, overload
88

99
from narwhals._compliant import EagerGroupBy
1010
from narwhals._expression_parsing import evaluate_output_names_and_aliases
@@ -255,9 +255,7 @@ def __init__(
255255
frame, self._keys, self._output_key_names = self._parse_keys(df, keys=keys)
256256
self._exclude: tuple[str, ...] = (*self._keys, *self._output_key_names)
257257
self._remap_non_str_columns = _remap_non_str(self)
258-
self._compliant_frame = cast("PandasLikeDataFrame", frame).rename(
259-
self._remap_non_str_columns, copy=True
260-
)
258+
self._compliant_frame = frame.rename(self._remap_non_str_columns)
261259
# Drop index to avoid potential collisions:
262260
# https://github.com/narwhals-dev/narwhals/issues/1907.
263261
native = self.compliant.native

narwhals/_pandas_like/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,14 @@ def set_index(
182182

183183

184184
def rename(
185-
obj: NativeNDFrameT,
186-
*args: Any,
187-
implementation: Implementation,
188-
copy: bool = False,
189-
**kwargs: Any,
185+
obj: NativeNDFrameT, *args: Any, implementation: Implementation, **kwargs: Any
190186
) -> NativeNDFrameT:
191187
"""Wrapper around pandas' rename so that we can set `copy` based on implementation/version."""
192188
if implementation is Implementation.PANDAS and (
193189
implementation._backend_version() >= (3,)
194190
): # pragma: no cover
195191
return obj.rename(*args, **kwargs, inplace=False)
196-
return obj.rename(*args, **kwargs, copy=copy, inplace=False)
192+
return obj.rename(*args, **kwargs, copy=False, inplace=False)
197193

198194

199195
@functools.lru_cache(maxsize=16)

0 commit comments

Comments
 (0)