Skip to content
Next Next commit
add a test for loc method; check if a warning raise when replacing a …
…subframe
  • Loading branch information
samilAyoub committed Sep 19, 2020
commit bc745d53b238e6abaf88ed635a225265e3c4072e
13 changes: 13 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,3 +1130,16 @@ def test_loc_with_period_index_indexer():
tm.assert_frame_equal(df, df.loc[list(idx)])
tm.assert_frame_equal(df.iloc[0:5], df.loc[idx[0:5]])
tm.assert_frame_equal(df, df.loc[list(idx)])

def test_loc_replace_subset_with_another():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call it test_loc_replace_subset_with_subset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# GH#36424 Should raise a warning
df1 = pd.DataFrame(
data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
columns = ['A', 'B', 'C'],
index = [0, 0, 1]
)
df2 = df1.copy()
df2[:] = np.nan
# it fail if a warning is not raised
with pytest.warns(Warning):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use tm.assert_produces_warning instead of pytest.warns

def assert_produces_warning(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

df2.loc['0']['A'] = df1.loc['0']['A']