Skip to content

Commit d9722ef

Browse files
authored
add a test for loc method; check if a warning raise when replacing a … (#36486)
1 parent 3295270 commit d9722ef

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/tests/indexing/test_chaining_and_caching.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,14 @@ def test_setting_with_copy_bug(self):
335335
# this should not raise
336336
df2["y"] = ["g", "h", "i"]
337337

338-
def test_detect_chained_assignment_warnings(self):
338+
def test_detect_chained_assignment_warnings_errors(self):
339+
df = DataFrame({"A": ["aaa", "bbb", "ccc"], "B": [1, 2, 3]})
339340
with option_context("chained_assignment", "warn"):
340-
df = DataFrame({"A": ["aaa", "bbb", "ccc"], "B": [1, 2, 3]})
341-
342341
with tm.assert_produces_warning(com.SettingWithCopyWarning):
343342
df.loc[0]["A"] = 111
343+
with option_context("chained_assignment", "raise"):
344+
with pytest.raises(com.SettingWithCopyError):
345+
df.loc[0]["A"] = 111
344346

345347
def test_detect_chained_assignment_warnings_filter_and_dupe_cols(self):
346348
# xref gh-13017.

0 commit comments

Comments
 (0)