Skip to content

Commit 2856ce1

Browse files
authored
Revert #47934 (#48201)
1 parent e65a30e commit 2856ce1

File tree

3 files changed

+4
-66
lines changed

3 files changed

+4
-66
lines changed

doc/source/whatsnew/v1.5.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ Other enhancements
331331
- :meth:`DataFrame.quantile` gained a ``method`` argument that can accept ``table`` to evaluate multi-column quantiles (:issue:`43881`)
332332
- :class:`Interval` now supports checking whether one interval is contained by another interval (:issue:`46613`)
333333
- 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`)
334-
- :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`)
335334
- :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`)
336335
- The method :meth:`.ExtensionArray.factorize` accepts ``use_na_sentinel=False`` for determining how null values are to be treated (:issue:`46601`)
337336

pandas/core/generic.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -4619,7 +4619,7 @@ def _update_inplace(self, result, verify_is_copy: bool_t = True) -> None:
46194619
self._maybe_update_cacher(verify_is_copy=verify_is_copy, inplace=True)
46204620

46214621
@final
4622-
def add_prefix(self: NDFrameT, prefix: str, copy: bool_t = True) -> NDFrameT:
4622+
def add_prefix(self: NDFrameT, prefix: str) -> NDFrameT:
46234623
"""
46244624
Prefix labels with string `prefix`.
46254625
@@ -4630,10 +4630,6 @@ def add_prefix(self: NDFrameT, prefix: str, copy: bool_t = True) -> NDFrameT:
46304630
----------
46314631
prefix : str
46324632
The string to add before each label.
4633-
copy : bool, default True
4634-
Whether to copy the underlying data.
4635-
4636-
.. versionadded:: 1.5.0
46374633
46384634
Returns
46394635
-------
@@ -4684,10 +4680,10 @@ def add_prefix(self: NDFrameT, prefix: str, copy: bool_t = True) -> NDFrameT:
46844680
# expected "NDFrameT")
46854681
# error: Argument 1 to "rename" of "NDFrame" has incompatible type
46864682
# "**Dict[str, partial[str]]"; expected "Union[str, int, None]"
4687-
return self._rename(**mapper, copy=copy) # type: ignore[return-value, arg-type]
4683+
return self._rename(**mapper) # type: ignore[return-value, arg-type]
46884684

46894685
@final
4690-
def add_suffix(self: NDFrameT, suffix: str, copy: bool_t = True) -> NDFrameT:
4686+
def add_suffix(self: NDFrameT, suffix: str) -> NDFrameT:
46914687
"""
46924688
Suffix labels with string `suffix`.
46934689
@@ -4698,10 +4694,6 @@ def add_suffix(self: NDFrameT, suffix: str, copy: bool_t = True) -> NDFrameT:
46984694
----------
46994695
suffix : str
47004696
The string to add after each label.
4701-
copy : bool, default True
4702-
Whether to copy the underlying data.
4703-
4704-
.. versionadded:: 1.5.0
47054697
47064698
Returns
47074699
-------
@@ -4752,7 +4744,7 @@ def add_suffix(self: NDFrameT, suffix: str, copy: bool_t = True) -> NDFrameT:
47524744
# expected "NDFrameT")
47534745
# error: Argument 1 to "rename" of "NDFrame" has incompatible type
47544746
# "**Dict[str, partial[str]]"; expected "Union[str, int, None]"
4755-
return self._rename(**mapper, copy=copy) # type: ignore[return-value, arg-type]
4747+
return self._rename(**mapper) # type: ignore[return-value, arg-type]
47564748

47574749
@overload
47584750
def sort_values(

pandas/tests/frame/methods/test_add_prefix_suffix.py

-53
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,3 @@ def test_add_prefix_suffix(float_frame):
1818
with_pct_suffix = float_frame.add_suffix("%")
1919
expected = Index([f"{c}%" for c in float_frame.columns])
2020
tm.assert_index_equal(with_pct_suffix.columns, expected)
21-
22-
23-
def test_add_prefix_suffix_copy(float_frame):
24-
# GH#47934
25-
ser = float_frame.iloc[0]
26-
27-
with_prefix = float_frame.add_prefix("foo#", copy=True)
28-
expected = Index([f"foo#{c}" for c in float_frame.columns])
29-
tm.assert_index_equal(with_prefix.columns, expected)
30-
assert not any(
31-
tm.shares_memory(float_frame.iloc[:, i], with_prefix.iloc[:, i])
32-
for i in range(float_frame.shape[1])
33-
)
34-
35-
ser_with_prefix = ser.add_prefix("foo#", copy=True)
36-
tm.assert_index_equal(ser_with_prefix.index, expected)
37-
assert not tm.shares_memory(ser_with_prefix, ser)
38-
39-
with_prefix = float_frame.add_prefix("foo#", copy=False)
40-
expected = Index([f"foo#{c}" for c in float_frame.columns])
41-
tm.assert_index_equal(with_prefix.columns, expected)
42-
assert all(
43-
tm.shares_memory(float_frame.iloc[:, i], with_prefix.iloc[:, i])
44-
for i in range(float_frame.shape[1])
45-
)
46-
47-
ser_with_prefix = ser.add_prefix("foo#", copy=False)
48-
tm.assert_index_equal(ser_with_prefix.index, expected)
49-
assert tm.shares_memory(ser_with_prefix, ser)
50-
51-
with_suffix = float_frame.add_suffix("#foo", copy=True)
52-
expected = Index([f"{c}#foo" for c in float_frame.columns])
53-
tm.assert_index_equal(with_suffix.columns, expected)
54-
assert not any(
55-
tm.shares_memory(float_frame.iloc[:, i], with_suffix.iloc[:, i])
56-
for i in range(float_frame.shape[1])
57-
)
58-
59-
ser_with_suffix = ser.add_suffix("#foo", copy=True)
60-
tm.assert_index_equal(ser_with_suffix.index, expected)
61-
assert not tm.shares_memory(ser_with_suffix, ser)
62-
63-
with_suffix = float_frame.add_suffix("#foo", copy=False)
64-
expected = Index([f"{c}#foo" for c in float_frame.columns])
65-
tm.assert_index_equal(with_suffix.columns, expected)
66-
assert all(
67-
tm.shares_memory(float_frame.iloc[:, i], with_suffix.iloc[:, i])
68-
for i in range(float_frame.shape[1])
69-
)
70-
71-
ser_with_suffix = ser.add_suffix("#foo", copy=False)
72-
tm.assert_index_equal(ser_with_suffix.index, expected)
73-
assert tm.shares_memory(ser_with_suffix, ser)

0 commit comments

Comments
 (0)