Skip to content

Commit c9490bd

Browse files
phoflpmhatre1
authored andcommitted
CoW: Remove more using_copy_on_write fixtures (pandas-dev#57368)
1 parent 3b0318f commit c9490bd

15 files changed

+475
-993
lines changed

pandas/tests/copy_view/index/test_datetimeindex.py

+10-17
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,43 @@
1414

1515

1616
@pytest.mark.parametrize("box", [lambda x: x, DatetimeIndex])
17-
def test_datetimeindex(using_copy_on_write, box):
17+
def test_datetimeindex(box):
1818
dt = date_range("2019-12-31", periods=3, freq="D")
1919
ser = Series(dt)
2020
idx = box(DatetimeIndex(ser))
2121
expected = idx.copy(deep=True)
2222
ser.iloc[0] = Timestamp("2020-12-31")
23-
if using_copy_on_write:
24-
tm.assert_index_equal(idx, expected)
23+
tm.assert_index_equal(idx, expected)
2524

2625

27-
def test_datetimeindex_tz_convert(using_copy_on_write):
26+
def test_datetimeindex_tz_convert():
2827
dt = date_range("2019-12-31", periods=3, freq="D", tz="Europe/Berlin")
2928
ser = Series(dt)
3029
idx = DatetimeIndex(ser).tz_convert("US/Eastern")
3130
expected = idx.copy(deep=True)
3231
ser.iloc[0] = Timestamp("2020-12-31", tz="Europe/Berlin")
33-
if using_copy_on_write:
34-
tm.assert_index_equal(idx, expected)
32+
tm.assert_index_equal(idx, expected)
3533

3634

37-
def test_datetimeindex_tz_localize(using_copy_on_write):
35+
def test_datetimeindex_tz_localize():
3836
dt = date_range("2019-12-31", periods=3, freq="D")
3937
ser = Series(dt)
4038
idx = DatetimeIndex(ser).tz_localize("Europe/Berlin")
4139
expected = idx.copy(deep=True)
4240
ser.iloc[0] = Timestamp("2020-12-31")
43-
if using_copy_on_write:
44-
tm.assert_index_equal(idx, expected)
41+
tm.assert_index_equal(idx, expected)
4542

4643

47-
def test_datetimeindex_isocalendar(using_copy_on_write):
44+
def test_datetimeindex_isocalendar():
4845
dt = date_range("2019-12-31", periods=3, freq="D")
4946
ser = Series(dt)
5047
df = DatetimeIndex(ser).isocalendar()
5148
expected = df.index.copy(deep=True)
5249
ser.iloc[0] = Timestamp("2020-12-31")
53-
if using_copy_on_write:
54-
tm.assert_index_equal(df.index, expected)
50+
tm.assert_index_equal(df.index, expected)
5551

5652

57-
def test_index_values(using_copy_on_write):
53+
def test_index_values():
5854
idx = date_range("2019-12-31", periods=3, freq="D")
5955
result = idx.values
60-
if using_copy_on_write:
61-
assert result.flags.writeable is False
62-
else:
63-
assert result.flags.writeable is True
56+
assert result.flags.writeable is False

pandas/tests/copy_view/index/test_index.py

+23-49
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@ def index_view(index_data):
1919
return idx, view
2020

2121

22-
def test_set_index_update_column(using_copy_on_write):
22+
def test_set_index_update_column():
2323
df = DataFrame({"a": [1, 2], "b": 1})
2424
df = df.set_index("a", drop=False)
2525
expected = df.index.copy(deep=True)
2626
df.iloc[0, 0] = 100
27-
if using_copy_on_write:
28-
tm.assert_index_equal(df.index, expected)
29-
else:
30-
tm.assert_index_equal(df.index, Index([100, 2], name="a"))
27+
tm.assert_index_equal(df.index, expected)
3128

3229

33-
def test_set_index_drop_update_column(using_copy_on_write):
30+
def test_set_index_drop_update_column():
3431
df = DataFrame({"a": [1, 2], "b": 1.5})
3532
view = df[:]
3633
df = df.set_index("a", drop=True)
@@ -39,73 +36,58 @@ def test_set_index_drop_update_column(using_copy_on_write):
3936
tm.assert_index_equal(df.index, expected)
4037

4138

42-
def test_set_index_series(using_copy_on_write):
39+
def test_set_index_series():
4340
df = DataFrame({"a": [1, 2], "b": 1.5})
4441
ser = Series([10, 11])
4542
df = df.set_index(ser)
4643
expected = df.index.copy(deep=True)
4744
ser.iloc[0] = 100
48-
if using_copy_on_write:
49-
tm.assert_index_equal(df.index, expected)
50-
else:
51-
tm.assert_index_equal(df.index, Index([100, 11]))
45+
tm.assert_index_equal(df.index, expected)
5246

5347

54-
def test_assign_index_as_series(using_copy_on_write):
48+
def test_assign_index_as_series():
5549
df = DataFrame({"a": [1, 2], "b": 1.5})
5650
ser = Series([10, 11])
5751
df.index = ser
5852
expected = df.index.copy(deep=True)
5953
ser.iloc[0] = 100
60-
if using_copy_on_write:
61-
tm.assert_index_equal(df.index, expected)
62-
else:
63-
tm.assert_index_equal(df.index, Index([100, 11]))
54+
tm.assert_index_equal(df.index, expected)
6455

6556

66-
def test_assign_index_as_index(using_copy_on_write):
57+
def test_assign_index_as_index():
6758
df = DataFrame({"a": [1, 2], "b": 1.5})
6859
ser = Series([10, 11])
6960
rhs_index = Index(ser)
7061
df.index = rhs_index
7162
rhs_index = None # overwrite to clear reference
7263
expected = df.index.copy(deep=True)
7364
ser.iloc[0] = 100
74-
if using_copy_on_write:
75-
tm.assert_index_equal(df.index, expected)
76-
else:
77-
tm.assert_index_equal(df.index, Index([100, 11]))
65+
tm.assert_index_equal(df.index, expected)
7866

7967

80-
def test_index_from_series(using_copy_on_write):
68+
def test_index_from_series():
8169
ser = Series([1, 2])
8270
idx = Index(ser)
8371
expected = idx.copy(deep=True)
8472
ser.iloc[0] = 100
85-
if using_copy_on_write:
86-
tm.assert_index_equal(idx, expected)
87-
else:
88-
tm.assert_index_equal(idx, Index([100, 2]))
73+
tm.assert_index_equal(idx, expected)
8974

9075

91-
def test_index_from_series_copy(using_copy_on_write):
76+
def test_index_from_series_copy():
9277
ser = Series([1, 2])
9378
idx = Index(ser, copy=True) # noqa: F841
9479
arr = get_array(ser)
9580
ser.iloc[0] = 100
9681
assert np.shares_memory(get_array(ser), arr)
9782

9883

99-
def test_index_from_index(using_copy_on_write):
84+
def test_index_from_index():
10085
ser = Series([1, 2])
10186
idx = Index(ser)
10287
idx = Index(idx)
10388
expected = idx.copy(deep=True)
10489
ser.iloc[0] = 100
105-
if using_copy_on_write:
106-
tm.assert_index_equal(idx, expected)
107-
else:
108-
tm.assert_index_equal(idx, Index([100, 2]))
90+
tm.assert_index_equal(idx, expected)
10991

11092

11193
@pytest.mark.parametrize(
@@ -135,44 +117,36 @@ def test_index_from_index(using_copy_on_write):
135117
"astype",
136118
],
137119
)
138-
def test_index_ops(using_copy_on_write, func, request):
120+
def test_index_ops(func, request):
139121
idx, view_ = index_view([1, 2])
140122
expected = idx.copy(deep=True)
141123
if "astype" in request.node.callspec.id:
142124
expected = expected.astype("Int64")
143125
idx = func(idx)
144126
view_.iloc[0, 0] = 100
145-
if using_copy_on_write:
146-
tm.assert_index_equal(idx, expected, check_names=False)
127+
tm.assert_index_equal(idx, expected, check_names=False)
147128

148129

149-
def test_infer_objects(using_copy_on_write):
130+
def test_infer_objects():
150131
idx, view_ = index_view(["a", "b"])
151132
expected = idx.copy(deep=True)
152133
idx = idx.infer_objects(copy=False)
153134
view_.iloc[0, 0] = "aaaa"
154-
if using_copy_on_write:
155-
tm.assert_index_equal(idx, expected, check_names=False)
135+
tm.assert_index_equal(idx, expected, check_names=False)
156136

157137

158-
def test_index_to_frame(using_copy_on_write):
138+
def test_index_to_frame():
159139
idx = Index([1, 2, 3], name="a")
160140
expected = idx.copy(deep=True)
161141
df = idx.to_frame()
162-
if using_copy_on_write:
163-
assert np.shares_memory(get_array(df, "a"), idx._values)
164-
assert not df._mgr._has_no_reference(0)
165-
else:
166-
assert not np.shares_memory(get_array(df, "a"), idx._values)
142+
assert np.shares_memory(get_array(df, "a"), idx._values)
143+
assert not df._mgr._has_no_reference(0)
167144

168145
df.iloc[0, 0] = 100
169146
tm.assert_index_equal(idx, expected)
170147

171148

172-
def test_index_values(using_copy_on_write):
149+
def test_index_values():
173150
idx = Index([1, 2, 3])
174151
result = idx.values
175-
if using_copy_on_write:
176-
assert result.flags.writeable is False
177-
else:
178-
assert result.flags.writeable is True
152+
assert result.flags.writeable is False

pandas/tests/copy_view/index/test_periodindex.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515

1616
@pytest.mark.parametrize("box", [lambda x: x, PeriodIndex])
17-
def test_periodindex(using_copy_on_write, box):
17+
def test_periodindex(box):
1818
dt = period_range("2019-12-31", periods=3, freq="D")
1919
ser = Series(dt)
2020
idx = box(PeriodIndex(ser))
2121
expected = idx.copy(deep=True)
2222
ser.iloc[0] = Period("2020-12-31")
23-
if using_copy_on_write:
24-
tm.assert_index_equal(idx, expected)
23+
tm.assert_index_equal(idx, expected)

pandas/tests/copy_view/index/test_timedeltaindex.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
lambda x: TimedeltaIndex(TimedeltaIndex(x)),
2121
],
2222
)
23-
def test_timedeltaindex(using_copy_on_write, cons):
23+
def test_timedeltaindex(cons):
2424
dt = timedelta_range("1 day", periods=3)
2525
ser = Series(dt)
2626
idx = cons(ser)
2727
expected = idx.copy(deep=True)
2828
ser.iloc[0] = Timedelta("5 days")
29-
if using_copy_on_write:
30-
tm.assert_index_equal(idx, expected)
29+
tm.assert_index_equal(idx, expected)

0 commit comments

Comments
 (0)