From 928318c7d5636e7972677c64feedb6ef3ec62a64 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 22 Aug 2022 12:57:17 -0700 Subject: [PATCH] Revert #47934 --- doc/source/whatsnew/v1.5.0.rst | 1 - pandas/core/generic.py | 16 ++---- .../frame/methods/test_add_prefix_suffix.py | 53 ------------------- 3 files changed, 4 insertions(+), 66 deletions(-) diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index c197f3df45814..cbe40cc6a2ea2 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -331,7 +331,6 @@ Other enhancements - :meth:`DataFrame.quantile` gained a ``method`` argument that can accept ``table`` to evaluate multi-column quantiles (:issue:`43881`) - :class:`Interval` now supports checking whether one interval is contained by another interval (:issue:`46613`) - Added ``copy`` keyword to :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` to allow user to set axis on a new object without necessarily copying the underlying data (:issue:`47932`) -- :meth:`Series.add_suffix`, :meth:`DataFrame.add_suffix`, :meth:`Series.add_prefix` and :meth:`DataFrame.add_prefix` support a ``copy`` argument. If ``False``, the underlying data is not copied in the returned object (:issue:`47934`) - :meth:`DataFrame.set_index` now supports a ``copy`` keyword. If ``False``, the underlying data is not copied when a new :class:`DataFrame` is returned (:issue:`48043`) - The method :meth:`.ExtensionArray.factorize` accepts ``use_na_sentinel=False`` for determining how null values are to be treated (:issue:`46601`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8ed3ba02991bc..8b1a427e1658a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4619,7 +4619,7 @@ def _update_inplace(self, result, verify_is_copy: bool_t = True) -> None: self._maybe_update_cacher(verify_is_copy=verify_is_copy, inplace=True) @final - def add_prefix(self: NDFrameT, prefix: str, copy: bool_t = True) -> NDFrameT: + def add_prefix(self: NDFrameT, prefix: str) -> NDFrameT: """ Prefix labels with string `prefix`. @@ -4630,10 +4630,6 @@ def add_prefix(self: NDFrameT, prefix: str, copy: bool_t = True) -> NDFrameT: ---------- prefix : str The string to add before each label. - copy : bool, default True - Whether to copy the underlying data. - - .. versionadded:: 1.5.0 Returns ------- @@ -4684,10 +4680,10 @@ def add_prefix(self: NDFrameT, prefix: str, copy: bool_t = True) -> NDFrameT: # expected "NDFrameT") # error: Argument 1 to "rename" of "NDFrame" has incompatible type # "**Dict[str, partial[str]]"; expected "Union[str, int, None]" - return self._rename(**mapper, copy=copy) # type: ignore[return-value, arg-type] + return self._rename(**mapper) # type: ignore[return-value, arg-type] @final - def add_suffix(self: NDFrameT, suffix: str, copy: bool_t = True) -> NDFrameT: + def add_suffix(self: NDFrameT, suffix: str) -> NDFrameT: """ Suffix labels with string `suffix`. @@ -4698,10 +4694,6 @@ def add_suffix(self: NDFrameT, suffix: str, copy: bool_t = True) -> NDFrameT: ---------- suffix : str The string to add after each label. - copy : bool, default True - Whether to copy the underlying data. - - .. versionadded:: 1.5.0 Returns ------- @@ -4752,7 +4744,7 @@ def add_suffix(self: NDFrameT, suffix: str, copy: bool_t = True) -> NDFrameT: # expected "NDFrameT") # error: Argument 1 to "rename" of "NDFrame" has incompatible type # "**Dict[str, partial[str]]"; expected "Union[str, int, None]" - return self._rename(**mapper, copy=copy) # type: ignore[return-value, arg-type] + return self._rename(**mapper) # type: ignore[return-value, arg-type] @overload def sort_values( diff --git a/pandas/tests/frame/methods/test_add_prefix_suffix.py b/pandas/tests/frame/methods/test_add_prefix_suffix.py index cc36a3caf6ec7..ea75e9ff51552 100644 --- a/pandas/tests/frame/methods/test_add_prefix_suffix.py +++ b/pandas/tests/frame/methods/test_add_prefix_suffix.py @@ -18,56 +18,3 @@ def test_add_prefix_suffix(float_frame): with_pct_suffix = float_frame.add_suffix("%") expected = Index([f"{c}%" for c in float_frame.columns]) tm.assert_index_equal(with_pct_suffix.columns, expected) - - -def test_add_prefix_suffix_copy(float_frame): - # GH#47934 - ser = float_frame.iloc[0] - - with_prefix = float_frame.add_prefix("foo#", copy=True) - expected = Index([f"foo#{c}" for c in float_frame.columns]) - tm.assert_index_equal(with_prefix.columns, expected) - assert not any( - tm.shares_memory(float_frame.iloc[:, i], with_prefix.iloc[:, i]) - for i in range(float_frame.shape[1]) - ) - - ser_with_prefix = ser.add_prefix("foo#", copy=True) - tm.assert_index_equal(ser_with_prefix.index, expected) - assert not tm.shares_memory(ser_with_prefix, ser) - - with_prefix = float_frame.add_prefix("foo#", copy=False) - expected = Index([f"foo#{c}" for c in float_frame.columns]) - tm.assert_index_equal(with_prefix.columns, expected) - assert all( - tm.shares_memory(float_frame.iloc[:, i], with_prefix.iloc[:, i]) - for i in range(float_frame.shape[1]) - ) - - ser_with_prefix = ser.add_prefix("foo#", copy=False) - tm.assert_index_equal(ser_with_prefix.index, expected) - assert tm.shares_memory(ser_with_prefix, ser) - - with_suffix = float_frame.add_suffix("#foo", copy=True) - expected = Index([f"{c}#foo" for c in float_frame.columns]) - tm.assert_index_equal(with_suffix.columns, expected) - assert not any( - tm.shares_memory(float_frame.iloc[:, i], with_suffix.iloc[:, i]) - for i in range(float_frame.shape[1]) - ) - - ser_with_suffix = ser.add_suffix("#foo", copy=True) - tm.assert_index_equal(ser_with_suffix.index, expected) - assert not tm.shares_memory(ser_with_suffix, ser) - - with_suffix = float_frame.add_suffix("#foo", copy=False) - expected = Index([f"{c}#foo" for c in float_frame.columns]) - tm.assert_index_equal(with_suffix.columns, expected) - assert all( - tm.shares_memory(float_frame.iloc[:, i], with_suffix.iloc[:, i]) - for i in range(float_frame.shape[1]) - ) - - ser_with_suffix = ser.add_suffix("#foo", copy=False) - tm.assert_index_equal(ser_with_suffix.index, expected) - assert tm.shares_memory(ser_with_suffix, ser)