-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
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 | ||
|
||
behave consistently with those for MultiIndex with nlevels > 1 | ||
''' | ||
expected = pd.Series([True]).repeat(count) | ||
expected.reset_index(drop=True, inplace=True) | ||
|
||
# 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) | ||
|
||
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