Skip to content

Commit 1307608

Browse files
TST: clean-up various tests avoiding CoW issues (#55861)
1 parent 4377dd1 commit 1307608

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

pandas/tests/frame/indexing/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,11 @@ def test_getitem_setitem_float_labels(self, using_array_manager):
747747
expected = df.iloc[0:2]
748748
tm.assert_frame_equal(result, expected)
749749

750-
df.loc[1:2] = 0
750+
expected = df.iloc[0:2]
751751
msg = r"The behavior of obj\[i:j\] with a float-dtype index"
752752
with tm.assert_produces_warning(FutureWarning, match=msg):
753753
result = df[1:2]
754-
assert (result == 0).all().all()
754+
tm.assert_frame_equal(result, expected)
755755

756756
# #2727
757757
index = Index([1.0, 2.5, 3.5, 4.5, 5.0])

pandas/tests/frame/test_api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ def test_with_datetimelikes(self):
217217

218218
def test_deepcopy(self, float_frame):
219219
cp = deepcopy(float_frame)
220-
series = cp["A"]
221-
series[:] = 10
222-
for idx, value in series.items():
223-
assert float_frame["A"][idx] != value
220+
cp.loc[0, "A"] = 10
221+
assert not float_frame.equals(cp)
224222

225223
def test_inplace_return_self(self):
226224
# GH 1893

pandas/tests/frame/test_nonunique_indexes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,15 @@ def test_set_value_by_index(self):
322322

323323
df = DataFrame(np.arange(9).reshape(3, 3).T)
324324
df.columns = list("AAA")
325-
expected = df.iloc[:, 2]
325+
expected = df.iloc[:, 2].copy()
326326

327327
with tm.assert_produces_warning(warn, match=msg):
328328
df.iloc[:, 0] = 3
329329
tm.assert_series_equal(df.iloc[:, 2], expected)
330330

331331
df = DataFrame(np.arange(9).reshape(3, 3).T)
332332
df.columns = [2, float(2), str(2)]
333-
expected = df.iloc[:, 1]
333+
expected = df.iloc[:, 1].copy()
334334

335335
with tm.assert_produces_warning(warn, match=msg):
336336
df.iloc[:, 0] = 3

pandas/tests/indexing/test_scalar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_frame_at_with_duplicate_axes(self):
140140
df = DataFrame(arr, columns=["A", "A"])
141141

142142
result = df.at[0, "A"]
143-
expected = df.iloc[0]
143+
expected = df.iloc[0].copy()
144144

145145
tm.assert_series_equal(result, expected)
146146

pandas/tests/series/indexing/test_setitem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ def test_setitem_with_bool_indexer():
17461746
# GH#42530
17471747

17481748
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
1749-
result = df.pop("b")
1749+
result = df.pop("b").copy()
17501750
result[[True, False, False]] = 9
17511751
expected = Series(data=[9, 5, 6], name="b")
17521752
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)