Skip to content

Commit 7b27b19

Browse files
committed
TST: Add test of assignment chaining and dupe cols
xref pandas-devgh-13017.
1 parent d78bd7a commit 7b27b19

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pandas/tests/indexing/test_chaining_and_caching.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,20 @@ def f():
337337
df2['y'] = ['g', 'h', 'i']
338338

339339
def test_detect_chained_assignment_warnings(self):
340+
with option_context("chained_assignment", "warn"):
341+
df = DataFrame({"A": ["aaa", "bbb", "ccc"], "B": [1, 2, 3]})
340342

341-
# warnings
342-
with option_context('chained_assignment', 'warn'):
343-
df = DataFrame({'A': ['aaa', 'bbb', 'ccc'], 'B': [1, 2, 3]})
344-
with tm.assert_produces_warning(
345-
expected_warning=com.SettingWithCopyWarning):
346-
df.loc[0]['A'] = 111
343+
with tm.assert_produces_warning(com.SettingWithCopyWarning):
344+
df.loc[0]["A"] = 111
345+
346+
def test_detect_chained_assignment_warnings_filter_and_dupe_cols(self):
347+
# xref gh-13017.
348+
with option_context("chained_assignment", "warn"):
349+
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, -9]],
350+
columns=["a", "a", "c"])
351+
352+
with tm.assert_produces_warning(com.SettingWithCopyWarning):
353+
df.c.loc[df.c > 0] = None
347354

348355
def test_chained_getitem_with_lists(self):
349356

0 commit comments

Comments
 (0)