Skip to content

Commit

Permalink
TST: clean-up various tests avoiding CoW issues (#55861)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Nov 7, 2023
1 parent 4377dd1 commit 1307608
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,11 @@ def test_getitem_setitem_float_labels(self, using_array_manager):
expected = df.iloc[0:2]
tm.assert_frame_equal(result, expected)

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

# #2727
index = Index([1.0, 2.5, 3.5, 4.5, 5.0])
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ def test_with_datetimelikes(self):

def test_deepcopy(self, float_frame):
cp = deepcopy(float_frame)
series = cp["A"]
series[:] = 10
for idx, value in series.items():
assert float_frame["A"][idx] != value
cp.loc[0, "A"] = 10
assert not float_frame.equals(cp)

def test_inplace_return_self(self):
# GH 1893
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_nonunique_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,15 @@ def test_set_value_by_index(self):

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

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

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

with tm.assert_produces_warning(warn, match=msg):
df.iloc[:, 0] = 3
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_frame_at_with_duplicate_axes(self):
df = DataFrame(arr, columns=["A", "A"])

result = df.at[0, "A"]
expected = df.iloc[0]
expected = df.iloc[0].copy()

tm.assert_series_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ def test_setitem_with_bool_indexer():
# GH#42530

df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
result = df.pop("b")
result = df.pop("b").copy()
result[[True, False, False]] = 9
expected = Series(data=[9, 5, 6], name="b")
tm.assert_series_equal(result, expected)
Expand Down

0 comments on commit 1307608

Please sign in to comment.