Skip to content

Commit 72562b4

Browse files
authored
Merge branch 'main' into autofilter-feature
2 parents 3bc720f + f918172 commit 72562b4

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ Other
12781278
- 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`)
12791279
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
12801280
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
1281+
- 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`)
12811282
- Deprecated the keyword ``check_datetimelike_compat`` in :meth:`testing.assert_frame_equal` and :meth:`testing.assert_series_equal` (:issue:`55638`)
12821283
- 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`)
12831284
- 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`)

pandas/core/frame.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12195,6 +12195,7 @@ def _get_data() -> DataFrame:
1219512195
# simple case where we can use BlockManager.reduce
1219612196
res = df._mgr.reduce(blk_func)
1219712197
out = df._constructor_from_mgr(res, axes=res.axes).iloc[0]
12198+
out.name = None
1219812199
if out_dtype is not None and out.dtype != "boolean":
1219912200
out = out.astype(out_dtype)
1220012201
elif (df._mgr.get_dtypes() == object).any() and name not in ["any", "all"]:

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6667,8 +6667,8 @@ def copy(self, deep: bool = True) -> Self:
66676667
)
66686668

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

66736673
@final
66746674
def __deepcopy__(self, memo=None) -> Self:

pandas/core/indexes/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,8 @@ def copy(
14131413
return new_index
14141414

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

14191419
@final
14201420
def __deepcopy__(self, memo=None) -> Self:

pandas/core/internals/blocks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def apply(self, func, **kwargs) -> list[Block]:
350350
return self._split_op_result(result)
351351

352352
@final
353-
def reduce(self, func) -> list[Block]:
353+
def reduce(self, func) -> Block:
354354
# We will apply the function and reshape the result into a single-row
355355
# Block with the same mgr_locs; squeezing will be done at a higher level
356356
assert self.ndim == 2
@@ -362,8 +362,7 @@ def reduce(self, func) -> list[Block]:
362362
else:
363363
res_values = result.reshape(-1, 1)
364364

365-
nb = self.make_block(res_values)
366-
return [nb]
365+
return self.make_block(res_values)
367366

368367
@final
369368
def _split_op_result(self, result: ArrayLike) -> list[Block]:

pandas/core/internals/managers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,12 +1651,8 @@ def reduce(self, func: Callable) -> Self:
16511651
# If 2D, we assume that we're operating column-wise
16521652
assert self.ndim == 2
16531653

1654-
res_blocks: list[Block] = []
1655-
for blk in self.blocks:
1656-
nbs = blk.reduce(func)
1657-
res_blocks.extend(nbs)
1658-
1659-
index = Index([None]) # placeholder
1654+
res_blocks = [blk.reduce(func) for blk in self.blocks]
1655+
index = default_index(1) # placeholder
16601656
new_mgr = type(self).from_blocks(res_blocks, [self.items, index])
16611657
return new_mgr
16621658

pandas/core/reshape/concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ def _make_concat_multiindex(indexes, keys, levels=None, names=None) -> MultiInde
840840
if (levels is None and isinstance(keys[0], tuple)) or (
841841
levels is not None and len(levels) > 1
842842
):
843-
zipped = list(zip(*keys))
843+
zipped = list(zip(*keys, strict=True))
844844
if names is None:
845845
names = [None] * len(zipped)
846846

pandas/tests/generic/test_generic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ def test_copy_and_deepcopy(self, frame_or_series, shape, func):
307307
assert obj_copy is not obj
308308
tm.assert_equal(obj_copy, obj)
309309

310+
def test_stdlib_copy_shallow_copies(self, frame_or_series):
311+
obj = frame_or_series(range(3))
312+
obj_copy = copy(obj)
313+
assert tm.shares_memory(obj, obj_copy)
314+
310315

311316
class TestNDFrame:
312317
# tests that don't fit elsewhere

0 commit comments

Comments
 (0)