-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: Add tests for single level indexing with loc(axis=1) #29519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
60c3f9f
e8a27bb
184169e
ed9075b
bd31841
f47c322
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -492,6 +492,44 @@ def test_loc_axis_arguments(self): | |
with pytest.raises(ValueError): | ||
df.loc(axis="foo")[:, :, ["C1", "C3"]] | ||
|
||
def test_loc_axis_single_level_multi_col_indexing_multiindex_col_df(self): | ||
|
||
# GH29519 | ||
df = pd.DataFrame( | ||
np.arange(27).reshape(3, 9), | ||
columns=pd.MultiIndex.from_product( | ||
[["a1", "a2", "a3"], ["b1", "b2", "b3"]] | ||
), | ||
) | ||
result = df.loc(axis=1)["a1":"a2"] | ||
expected = df.iloc[:, :-3] | ||
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_loc_axis_single_level_single_col_indexing_multiindex_col_df(self): | ||
|
||
# GH29519 | ||
df = pd.DataFrame( | ||
np.arange(27).reshape(3, 9), | ||
columns=pd.MultiIndex.from_product( | ||
[["a1", "a2", "a3"], ["b1", "b2", "b3"]] | ||
), | ||
) | ||
result = df.loc(axis=1)["a1"] | ||
expected = df.iloc[:, :3] | ||
expected.columns = ["b1", "b2", "b3"] | ||
|
||
tm.assert_frame_equal(result, expected) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you make 3 different functions for these tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mroeschke Is it ok if I split it into 2 functions - one for Multindex column df and one for simple df --- and for the Multiindex bit I can comment on the two different tests - i.e one is slicing on multi columns on single level and other is slicing on single col. Otherwise, having concise names for the functions is tricky. Something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verbose function names are fine. Helps isolate the failing test as separate methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok just pushed with changes as you originally suggested |
||
|
||
def test_loc_ax_single_level_indexer_simple_df(self): | ||
|
||
# GH29519 | ||
# test single level indexing on single index column data frame | ||
df = pd.DataFrame(np.arange(9).reshape(3, 3), columns=["a", "b", "c"]) | ||
result = df.loc(axis=1)["a"] | ||
expected = pd.Series(np.array([0, 3, 6]), name="a") | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_per_axis_per_level_setitem(self): | ||
|
||
# test index maker | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the issue number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure