Skip to content

Commit e3a0a1e

Browse files
committed
Reduce deep copies in the test suite
1 parent c3bace8 commit e3a0a1e

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

pandas/conftest.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def index(request):
720720
- ...
721721
"""
722722
# copy to avoid mutation, e.g. setting .name
723-
return indices_dict[request.param].copy()
723+
return indices_dict[request.param].copy(deep=False)
724724

725725

726726
@pytest.fixture(
@@ -733,7 +733,7 @@ def index_flat(request):
733733
index fixture, but excluding MultiIndex cases.
734734
"""
735735
key = request.param
736-
return indices_dict[key].copy()
736+
return indices_dict[key].copy(deep=False)
737737

738738

739739
@pytest.fixture(
@@ -756,18 +756,15 @@ def index_with_missing(request):
756756
757757
MultiIndex is excluded because isna() is not defined for MultiIndex.
758758
"""
759-
760-
# GH 35538. Use deep copy to avoid illusive bug on np-dev
761-
# GHA pipeline that writes into indices_dict despite copy
762-
ind = indices_dict[request.param].copy(deep=True)
763-
vals = ind.values.copy()
759+
ind = indices_dict[request.param]
764760
if request.param in ["tuples", "mi-with-dt64tz-level", "multi"]:
765761
# For setting missing values in the top level of MultiIndex
766762
vals = ind.tolist()
767763
vals[0] = (None,) + vals[0][1:]
768764
vals[-1] = (None,) + vals[-1][1:]
769765
return MultiIndex.from_tuples(vals)
770766
else:
767+
vals = ind.values.copy()
771768
vals[0] = None
772769
vals[-1] = None
773770
return type(ind)(vals)
@@ -848,7 +845,7 @@ def index_or_series_obj(request):
848845
Fixture for tests on indexes, series and series with a narrow dtype
849846
copy to avoid mutation, e.g. setting .name
850847
"""
851-
return _index_or_series_objs[request.param].copy(deep=True)
848+
return _index_or_series_objs[request.param].copy(deep=False)
852849

853850

854851
_typ_objects_series = {
@@ -871,7 +868,7 @@ def index_or_series_memory_obj(request):
871868
series with empty objects type
872869
copy to avoid mutation, e.g. setting .name
873870
"""
874-
return _index_or_series_memory_objs[request.param].copy(deep=True)
871+
return _index_or_series_memory_objs[request.param].copy(deep=False)
875872

876873

877874
# ----------------------------------------------------------------

pandas/tests/arrays/interval/test_interval.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def test_shift_datetime(self):
115115
class TestSetitem:
116116
def test_set_na(self, left_right_dtypes):
117117
left, right = left_right_dtypes
118-
left = left.copy(deep=True)
119-
right = right.copy(deep=True)
120-
result = IntervalArray.from_arrays(left, right)
118+
result = IntervalArray.from_arrays(left, right, copy=True)
121119

122120
if result.dtype.subtype.kind not in ["m", "M"]:
123121
msg = "'value' should be an interval type, got <.*NaTType'> instead."
@@ -168,8 +166,6 @@ def test_setitem_mismatched_closed(self):
168166
class TestReductions:
169167
def test_min_max_invalid_axis(self, left_right_dtypes):
170168
left, right = left_right_dtypes
171-
left = left.copy(deep=True)
172-
right = right.copy(deep=True)
173169
arr = IntervalArray.from_arrays(left, right)
174170

175171
msg = "`axis` must be fewer than the number of dimensions"
@@ -188,8 +184,6 @@ def test_min_max_invalid_axis(self, left_right_dtypes):
188184
def test_min_max(self, left_right_dtypes, index_or_series_or_array):
189185
# GH#44746
190186
left, right = left_right_dtypes
191-
left = left.copy(deep=True)
192-
right = right.copy(deep=True)
193187
arr = IntervalArray.from_arrays(left, right)
194188

195189
# The expected results below are only valid if monotonic

pandas/tests/copy_view/test_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def test_to_frame():
560560
],
561561
ids=["shallow-copy", "reset_index", "rename", "select_dtypes"],
562562
)
563-
def test_chained_methods(request, method, idx):
563+
def test_chained_methods(method, idx):
564564
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})
565565
df_orig = df.copy()
566566

0 commit comments

Comments
 (0)