Skip to content
Open
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
15 changes: 6 additions & 9 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def index(request):
- ...
"""
# copy to avoid mutation, e.g. setting .name
return indices_dict[request.param].copy()
return indices_dict[request.param].copy(deep=False)


@pytest.fixture(
Expand All @@ -735,7 +735,7 @@ def index_flat(request):
index fixture, but excluding MultiIndex cases.
"""
key = request.param
return indices_dict[key].copy()
return indices_dict[key].copy(deep=False)


@pytest.fixture(
Expand All @@ -758,18 +758,15 @@ def index_with_missing(request):

MultiIndex is excluded because isna() is not defined for MultiIndex.
"""

# GH 35538. Use deep copy to avoid illusive bug on np-dev
# GHA pipeline that writes into indices_dict despite copy
ind = indices_dict[request.param].copy(deep=True)
vals = ind.values.copy()
ind = indices_dict[request.param]
if request.param in ["tuples", "mi-with-dt64tz-level", "multi"]:
# For setting missing values in the top level of MultiIndex
vals = ind.tolist()
vals[0] = (None,) + vals[0][1:]
vals[-1] = (None,) + vals[-1][1:]
return MultiIndex.from_tuples(vals)
else:
vals = ind.values.copy()
vals[0] = None
vals[-1] = None
return type(ind)(vals)
Expand Down Expand Up @@ -850,7 +847,7 @@ def index_or_series_obj(request):
Fixture for tests on indexes, series and series with a narrow dtype
copy to avoid mutation, e.g. setting .name
"""
return _index_or_series_objs[request.param].copy(deep=True)
return _index_or_series_objs[request.param].copy(deep=False)


_typ_objects_series = {
Expand All @@ -873,7 +870,7 @@ def index_or_series_memory_obj(request):
series with empty objects type
copy to avoid mutation, e.g. setting .name
"""
return _index_or_series_memory_objs[request.param].copy(deep=True)
return _index_or_series_memory_objs[request.param].copy(deep=False)


# ----------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions pandas/tests/arrays/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def test_shift_datetime(self):
class TestSetitem:
def test_set_na(self, left_right_dtypes):
left, right = left_right_dtypes
left = left.copy(deep=True)
right = right.copy(deep=True)
result = IntervalArray.from_arrays(left, right)
result = IntervalArray.from_arrays(left, right, copy=True)

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

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

# The expected results below are only valid if monotonic
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/base/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_fillna_null(null_obj, index_or_series_obj):
elif isinstance(obj, MultiIndex):
pytest.skip(f"MultiIndex can't hold '{null_obj}'")

obj = obj.copy(deep=True)
values = obj._values
fill_value = values[0]
expected = values.copy()
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/base/test_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_unique_null(null_obj, index_or_series_obj, using_nan_is_na):
):
pytest.skip("NaN is not a valid NA for this dtype.")

obj = obj.copy(deep=True)
values = obj._values
values[0:2] = null_obj

Expand Down Expand Up @@ -87,6 +88,7 @@ def test_nunique_null(null_obj, index_or_series_obj):
elif isinstance(obj, pd.MultiIndex):
pytest.skip(f"MultiIndex can't hold '{null_obj}'")

obj = obj.copy(deep=True)
values = obj._values
values[0:2] = null_obj

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/base/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def test_value_counts(index_or_series_obj):
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
def test_value_counts_null(null_obj, index_or_series_obj):
orig = index_or_series_obj
obj = orig.copy()

if not allow_na_ops(obj):
if not allow_na_ops(orig):
pytest.skip("type doesn't allow for NA operations")
elif len(obj) < 1:
elif len(orig) < 1:
pytest.skip("Test doesn't make sense on empty data")
elif isinstance(orig, MultiIndex):
pytest.skip(f"MultiIndex can't hold '{null_obj}'")

obj = orig.copy(deep=True)
values = obj._values
values[0:2] = null_obj

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/copy_view/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def test_to_frame():
],
ids=["shallow-copy", "reset_index", "rename", "select_dtypes"],
)
def test_chained_methods(request, method, idx):
def test_chained_methods(method, idx):
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})
df_orig = df.copy()

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def test_unique(self, index_flat):
if not index._can_hold_na:
pytest.skip("Skip na-check if index cannot hold na")

vals = index._values[[0] * 5]
vals = index._values.copy()[[0] * 5]
vals[0] = np.nan

vals_unique = vals[:2]
Expand Down
Loading