Skip to content

TST: insert 'match' to bare pytest raises in pandas/tests/indexing/te… #36762

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
Oct 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ def test_detect_chained_assignment(self):
)
assert df._is_copy is None

with pytest.raises(com.SettingWithCopyError):
msg = "A value is trying to be set on a copy of a slice from a DataFrame"
with pytest.raises(com.SettingWithCopyError, match=msg):
df["A"][0] = -5

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df["A"][1] = np.nan

assert df["A"]._is_copy is None
Expand All @@ -171,7 +172,7 @@ def test_detect_chained_assignment(self):
}
)

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df.loc[0]["A"] = -5

# Doc example
Expand All @@ -183,17 +184,17 @@ def test_detect_chained_assignment(self):
)
assert df._is_copy is None

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
indexer = df.a.str.startswith("o")
df[indexer]["c"] = 42

expected = DataFrame({"A": [111, "bbb", "ccc"], "B": [1, 2, 3]})
df = DataFrame({"A": ["aaa", "bbb", "ccc"], "B": [1, 2, 3]})

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df["A"][0] = 111

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df.loc[0]["A"] = 111

df.loc[0, "A"] = 111
Expand Down Expand Up @@ -293,7 +294,7 @@ def random_text(nobs=100):
df = DataFrame(np.arange(0, 9), columns=["count"])
df["group"] = "b"

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df.iloc[0:5]["group"] = "a"

# Mixed type setting but same dtype & changing dtype
Expand All @@ -306,13 +307,13 @@ def random_text(nobs=100):
)
)

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df.loc[2]["D"] = "foo"

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df.loc[2]["C"] = "foo"

with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df["C"][2] = "foo"

def test_setting_with_copy_bug(self):
Expand Down Expand Up @@ -340,8 +341,10 @@ def test_detect_chained_assignment_warnings_errors(self):
with option_context("chained_assignment", "warn"):
with tm.assert_produces_warning(com.SettingWithCopyWarning):
df.loc[0]["A"] = 111

msg = "A value is trying to be set on a copy of a slice from a DataFrame"
with option_context("chained_assignment", "raise"):
with pytest.raises(com.SettingWithCopyError):
with pytest.raises(com.SettingWithCopyError, match=msg):
df.loc[0]["A"] = 111

def test_detect_chained_assignment_warnings_filter_and_dupe_cols(self):
Expand Down