Skip to content

Revert #47934 #48201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down
16 changes: 4 additions & 12 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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
-------
Expand Down Expand Up @@ -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`.

Expand All @@ -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
-------
Expand Down Expand Up @@ -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(
Expand Down
53 changes: 0 additions & 53 deletions pandas/tests/frame/methods/test_add_prefix_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)