-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Comparison methods for MultiIndex should have consistent behaviour for all nlevels (GH21149) #21195
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
CLN: Comparison methods for MultiIndex should have consistent behaviour for all nlevels (GH21149) #21195
Changes from 8 commits
d0c7ebc
143566a
dd60b4e
d4d2db3
370d509
b661ca1
cd6e752
d27736d
f90cf94
6ad6e7e
a2cd674
bf4494f
6925732
a27cc98
b504276
f0723e7
73cac75
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 |
---|---|---|
|
@@ -3291,3 +3291,29 @@ def test_duplicate_multiindex_labels(self): | |
with pytest.raises(ValueError): | ||
ind.set_levels([['A', 'B', 'A', 'A', 'B'], [2, 1, 3, -2, 5]], | ||
inplace=True) | ||
|
||
@pytest.mark.parametrize("midx,idx,count", [ | ||
(pd.MultiIndex.from_product([[0, 1], [1, 0]]), pd.Series(range(4)), 4), | ||
(pd.MultiIndex.from_product([[0, 1]]), pd.Series(range(2)), 2)]) | ||
def test_multiindex_compare(self, midx, idx, count): | ||
# GH 21149 | ||
'''Ensure comparison operations for MultiIndex with nlevels == 1 | ||
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. use triple-double quotes 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. done |
||
behave consistently with those for MultiIndex with nlevels > 1 | ||
''' | ||
expected = pd.Series([True]).repeat(count) | ||
expected.reset_index(drop=True, inplace=True) | ||
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. don't use inplace in 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. @jreback Thanks - here 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. done - I have simplified the tests. |
||
# Equality self-test: MultiIndex object vs self | ||
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. blank line between cases 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. done |
||
result = pd.Series(midx == midx) | ||
tm.assert_series_equal(result, expected) | ||
# Equality self-test: non-MultiIndex Index object vs self | ||
result = (idx == idx) | ||
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. where did the idea for these test come from? what exactly are you trying to test here? 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. These tests are trying to ensure the behaviour on comparison between Currently (as of 0.23.0), comparing [In] midx=pd.MultiIndex.from_product([[0, 1]])
[In] midx
[Out] MultiIndex(levels=[[0, 1]],
labels=[[0, 1]])
[In] midx == midx
[Out] ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() whereas the behaviour should be consistent with that for [In] midx == midx
[Out] array([ True, True]) 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. in this test, probably should be OK to only keep the |
||
tm.assert_series_equal(result, expected) | ||
|
||
expected = pd.Series([False]).repeat(count) | ||
expected.reset_index(drop=True, inplace=True) | ||
# Greater than comparison: MultiIndex object vs self | ||
result = pd.Series(midx > midx) | ||
tm.assert_series_equal(result, expected) | ||
# Equality test: non-MultiIndex Index object vs MultiIndex object | ||
result = pd.Series(midx == idx) | ||
tm.assert_series_equal(result, expected) |
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.
double backticks on MultiIndex