Skip to content
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: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ Other
- Bug in ``divmod`` and ``rdivmod`` with :class:`DataFrame`, :class:`Series`, and :class:`Index` with ``bool`` dtypes failing to raise, which was inconsistent with ``__floordiv__`` behavior (:issue:`46043`)
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
- Bug when calling :py:func:`copy.copy` on a :class:`DataFrame` or :class:`Series` which would return a deep copy instead of a shallow copy (:issue:`62971`)
- Deprecated the keyword ``check_datetimelike_compat`` in :meth:`testing.assert_frame_equal` and :meth:`testing.assert_series_equal` (:issue:`55638`)
- Fixed bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when trying to replace :class:`NA` values in a :class:`Float64Dtype` object with ``np.nan``; this now works with ``pd.set_option("mode.nan_is_na", False)`` and is irrelevant otherwise (:issue:`55127`)
- Fixed bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when trying to replace :class:`np.nan` values in a :class:`Int64Dtype` object with :class:`NA`; this is now a no-op with ``pd.set_option("mode.nan_is_na", False)`` and is irrelevant otherwise (:issue:`51237`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6680,8 +6680,8 @@ def copy(self, deep: bool = True) -> Self:
)

@final
def __copy__(self, deep: bool = True) -> Self:
return self.copy(deep=deep)
def __copy__(self) -> Self:
return self.copy(deep=False)

@final
def __deepcopy__(self, memo=None) -> Self:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,8 @@ def copy(
return new_index

@final
def __copy__(self, **kwargs) -> Self:
return self.copy(**kwargs)
def __copy__(self) -> Self:
return self.copy(deep=False)

@final
def __deepcopy__(self, memo=None) -> Self:
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ def test_copy_and_deepcopy(self, frame_or_series, shape, func):
assert obj_copy is not obj
tm.assert_equal(obj_copy, obj)

def test_stdlib_copy_shallow_copies(self, frame_or_series):
obj = frame_or_series(range(3))
obj_copy = copy(obj)
assert tm.shares_memory(obj, obj_copy)


class TestNDFrame:
# tests that don't fit elsewhere
Expand Down
Loading