diff --git a/pandas/core/series.py b/pandas/core/series.py index f8875555fdf97..93e1579738a50 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4726,6 +4726,13 @@ def rename( errors=errors, ) else: + # since _set_name supports only inplace and not copy param + # we determine inplace based on copy (if inplace is False) + # 1) If inplace is True, the value of copy is ignored + # 2) If inplace is False/not supplied(default case), then + # inplace is determined based on copy (opposite of copy) + if not inplace: + inplace = not copy return self._set_name(index, inplace=inplace) @Appender( diff --git a/pandas/tests/series/methods/test_rename.py b/pandas/tests/series/methods/test_rename.py index 93c4fbb7f3c46..1179cd762cde8 100644 --- a/pandas/tests/series/methods/test_rename.py +++ b/pandas/tests/series/methods/test_rename.py @@ -174,3 +174,9 @@ def test_rename_copy_false(self, using_copy_on_write): else: assert ser[0] == shallow_copy[0] assert ser[1] == shallow_copy[9] + + def test_rename_scalar_copy_false(self): + # GH 52450 + ser = Series([1]) + shallow_copy = ser.rename("series_a", copy=False) + assert id(ser) == id(shallow_copy)