Skip to content
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
23 changes: 17 additions & 6 deletions pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,24 @@ def f():
df2['y'] = ['g', 'h', 'i']

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

# warnings
with option_context('chained_assignment', 'warn'):
df = DataFrame({'A': ['aaa', 'bbb', 'ccc'], 'B': [1, 2, 3]})
with tm.assert_produces_warning(
expected_warning=com.SettingWithCopyWarning):
df.loc[0]['A'] = 111
with tm.assert_produces_warning(com.SettingWithCopyWarning):
df.loc[0]["A"] = 111

def test_detect_chained_assignment_warnings_filter_and_dupe_cols(self):
# xref gh-13017.
with option_context("chained_assignment", "warn"):
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, -9]],
columns=["a", "a", "c"])

with tm.assert_produces_warning(com.SettingWithCopyWarning):
df.c.loc[df.c > 0] = None

expected = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, -9]],
columns=["a", "a", "c"])
tm.assert_frame_equal(df, expected)

def test_chained_getitem_with_lists(self):

Expand Down