Skip to content

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

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

jorisvandenbossche
Copy link
Member

A few smaller and independent test changes broken off from #55838

@jorisvandenbossche jorisvandenbossche added the Testing pandas testing functions or related to the test suite label Nov 7, 2023
Comment on lines -750 to +754
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)
Copy link
Member Author

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.

Comment on lines -220 to +221
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)
Copy link
Member Author

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()
Copy link
Member Author

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

@mroeschke mroeschke added this to the 2.2 milestone Nov 7, 2023
@mroeschke mroeschke merged commit 1307608 into pandas-dev:main Nov 7, 2023
@mroeschke
Copy link
Member

Nice thanks @jorisvandenbossche

@jorisvandenbossche jorisvandenbossche deleted the cow-tst-updates branch November 7, 2023 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants