Skip to content

BUG: Should not raises errors in .set_names and comparison methods for MultiIndex with nlevels == 1 (GH21149) #21182

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

Closed
wants to merge 8 commits into from

Conversation

KalyanGokhale
Copy link
Contributor

@KalyanGokhale KalyanGokhale commented May 23, 2018

@KalyanGokhale
Copy link
Contributor Author

KalyanGokhale commented May 23, 2018

@toobaz have made necessary updates for #21149

original issue with set_names is fixed

Also, with the previous code snippet in def cmp_method it raised ValueError for equality / inequality comparisons of MultiIndex with nlevels == 1, which was inconsistent with behaviour for MultiIndex with nlevels > 1 - this has now been fixed

@KalyanGokhale
Copy link
Contributor Author

Resolved the earlier conflict with whatsnew file

@KalyanGokhale KalyanGokhale changed the title BUG: Should not raises errors in .set_names and comparison methods for MultiIndex with nlevels == 1 BUG: Should not raises errors in .set_names and comparison methods for MultiIndex with nlevels == 1 (GH21149) May 24, 2018
@KalyanGokhale
Copy link
Contributor Author

Will check the test failure and resubmit after necessary edits

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

you are doing 2 different changes here which are unreleated, break this in to 2 PRs

@@ -3291,3 +3291,37 @@ 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)

testdata = [
(pd.MultiIndex.from_product([[0, 1], [1, 0]]), pd.Series(range(4)), 4),
Copy link
Contributor

Choose a reason for hiding this comment

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

don't create a variable here, just put it directly in the parametrize (see how to format it from other tests)


@pytest.mark.parametrize("midx,idx,count", testdata)
def test_multiindex_compare(self, midx, idx, count):
# GH 21149 - change in 'def cmp_method()'
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a non-sensical comment, be more descriptive.

with tm.assert_raises_regex(TypeError, 'not supported'):
midx > idx

def test_multiindex_set_names(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

put this near the other tests for set_names

# GH 21149 - change in 'def cmp_method()'
expected = pd.Series([True]).repeat(count)
expected.reset_index(drop=True, inplace=True)
result = pd.Series(midx == midx)
Copy link
Contributor

Choose a reason for hiding this comment

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

not really clear what you are testing, this is way too dense. put blank lines and a comment in between cases.

@KalyanGokhale
Copy link
Contributor Author

KalyanGokhale commented May 24, 2018

@jreback Thanks for the review - have split this into two PRs as suggested (#21195 and #21196). Have also made the requested edits. Closing this PR.

@KalyanGokhale KalyanGokhale deleted the multi-nlevel branch May 24, 2018 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Assuming we don't want to disallow 1-level MultiIndexes), stop identifying MultiIndex by nlevels == 1
2 participants