Skip to content

Commit ed46d6d

Browse files
gfyoungJustinZhengBC
authored andcommitted
TST: Add test of assignment chaining and dupe cols (pandas-dev#23487)
xref pandas-devgh-13017.
1 parent 5e09698 commit ed46d6d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pandas/tests/indexing/test_chaining_and_caching.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,24 @@ 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
354+
355+
expected = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, -9]],
356+
columns=["a", "a", "c"])
357+
tm.assert_frame_equal(df, expected)
347358

348359
def test_chained_getitem_with_lists(self):
349360

0 commit comments

Comments
 (0)