-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: clean-up various tests avoiding CoW issues #55861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea why we are setting values to 0 to then check that the indexing result
also has values of 0. Can also use a plain assert_frame_equal, which seems simpler.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a tedious way to check that cp
is an actual copy (getting a column, mutating that column, and then iterating through column values), while we can also use a simpler direct mutation and single assert
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying those "expected" frames avoids any potential issues where expected
might be modified(or not) through what is actually being tested
Nice thanks @jorisvandenbossche |
A few smaller and independent test changes broken off from #55838