Skip to content

Commit 6125cab

Browse files
authored
CoW: Clean up some copy usage (pandas-dev#57513)
1 parent b71d0ea commit 6125cab

File tree

5 files changed

+6
-7
lines changed

5 files changed

+6
-7
lines changed

pandas/core/computation/eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def eval(
378378
try:
379379
target = env.target
380380
if isinstance(target, NDFrame):
381-
target = target.copy(deep=None)
381+
target = target.copy(deep=False)
382382
else:
383383
target = target.copy()
384384
except AttributeError as err:

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7488,7 +7488,7 @@ def replace(
74887488
if not self.size:
74897489
if inplace:
74907490
return None
7491-
return self.copy(deep=None)
7491+
return self.copy(deep=False)
74927492

74937493
if is_dict_like(to_replace):
74947494
if is_dict_like(value): # {'A' : NA} -> {'A' : 0}
@@ -10279,7 +10279,7 @@ def shift(
1027910279
fill_value = lib.no_default
1028010280

1028110281
if periods == 0:
10282-
return self.copy(deep=None)
10282+
return self.copy(deep=False)
1028310283

1028410284
if is_list_like(periods) and isinstance(self, ABCSeries):
1028510285
return self.to_frame().shift(

pandas/core/internals/managers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def _combine(self, blocks: list[Block], index: Index | None = None) -> Self:
702702
def nblocks(self) -> int:
703703
return len(self.blocks)
704704

705-
def copy(self, deep: bool | None | Literal["all"] = True) -> Self:
705+
def copy(self, deep: bool | Literal["all"] = True) -> Self:
706706
"""
707707
Make deep or shallow copy of BlockManager
708708
@@ -716,7 +716,6 @@ def copy(self, deep: bool | None | Literal["all"] = True) -> Self:
716716
-------
717717
BlockManager
718718
"""
719-
deep = deep if deep is not None else False
720719
# this preserves the notion of view copying of axes
721720
if deep:
722721
# hit in e.g. tests.io.json.test_pandas

pandas/tests/copy_view/test_internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_iset_splits_blocks_inplace(locs, arr, dtype):
7070
)
7171
arr = arr.astype(dtype)
7272
df_orig = df.copy()
73-
df2 = df.copy(deep=None) # Trigger a CoW (if enabled, otherwise makes copy)
73+
df2 = df.copy(deep=False) # Trigger a CoW (if enabled, otherwise makes copy)
7474
df2._mgr.iset(locs, arr, inplace=True)
7575

7676
tm.assert_frame_equal(df, df_orig)

pandas/tests/copy_view/test_methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def test_interpolate_creates_copy():
12431243
def test_isetitem():
12441244
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]})
12451245
df_orig = df.copy()
1246-
df2 = df.copy(deep=None) # Trigger a CoW
1246+
df2 = df.copy(deep=False) # Trigger a CoW
12471247
df2.isetitem(1, np.array([-1, -2, -3])) # This is inplace
12481248
assert np.shares_memory(get_array(df, "c"), get_array(df2, "c"))
12491249
assert np.shares_memory(get_array(df, "a"), get_array(df2, "a"))

0 commit comments

Comments
 (0)