Skip to content
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

BUG: MultiIndex needs to validate length of levels on setting. #4794

Closed
jtratner opened this issue Sep 10, 2013 · 6 comments · Fixed by #5209

Comments

@jtratner
Copy link
Contributor

commented Sep 10, 2013

related #4687

Bad errors and/or not checking:

>>> ind = tm.makeCustomIndex(5, 5)
>>> ind.set_levels([[1, 2]]) # Wrong Error
Traceback
    ...
ValueError: Length of names (5) must be same as level (1)
>>> ind = tm.makeCustomIndex(5, 5)
>>> ind.set_levels([[1, 2]], inplace=True) # Wrong Error
Traceback
    ...
ValueError: Length of names (5) must be same as level (1)
>>> ind = tm.makeCustomIndex(5, 5)
>>> ind.levels = [[1, 2]] # Wrong Error
Traceback
    ...
ValueError: Length of names (5) must be same as level (1)
@jreback

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2013

What's wrong with these errors? they are informative

@jtratner

This comment has been minimized.

Copy link
Contributor Author

commented Oct 3, 2013

Well, it's more just that it's not validating levels, so you can end up
with the wrong level length accidentally. These examples might be wrong,
but the overall point that labels but not levels are checked is valid (and,
in particular, needs to check that, for each level/label pair, level.max()
<= len(label)). One upside of refactoring Index to not be ndarray (and use
a _data attribute) is that we can skip these checks on slicing or with
fastpath=True.

@jreback

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2013

ok.....leaving open in 0.13 then

@jtratner

This comment has been minimized.

Copy link
Contributor Author

commented Oct 3, 2013

I looked at this again and the reason its wrong is because names are (generally) irrelevant. Instead it's the fact that there is a level/label mismatch.

@jreback

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2013

@jtratner in 0.13?

@jtratner

This comment has been minimized.

Copy link
Contributor Author

commented Oct 11, 2013

Yes, I'm adding to my near-term todo list now. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.