-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: create new MI from MultiIndex._get_level_values #33134
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: create new MI from MultiIndex._get_level_values #33134
Conversation
3fe0afa
to
39cc530
Compare
idx2 = MultiIndex.from_arrays( | ||
[idx._get_level_values(level) for level in range(idx.nlevels)] | ||
) | ||
assert all(x.is_monotonic for x in idx2.levels) is True |
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.
Question, not a blocker.
Is the is True
necessary?
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.
Yeah, in this case it's not needed. I'm in the habit of testing properties with a strict is
test, where possible. I'll remove it, but will wait to see if other comments need addressing.
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.
lgtm. if you'd add a whatsnew note. merge on green.
If PeriodEngine.get_indexer is ever called it will raise AttributeError, ditto get_pad_indexer, get_backfill indexer. |
@jreback , this is a regression since v1.0, causes by #32669, so a whatsnew isn't needed here. @jbrockmendel , it looks like it also did that in v1.0?: >>> idx = pd.MultiIndex.from_arrays([pd.PeriodIndex([pd.Period("2019Q1"), pd.Period("2019Q2")], name='b')])
>>> idx2 = pd.MultiIndex.from_arrays([idx._get_level_values(level) for level in range(idx.nlevels)])
>>> idx2.levels[0]._engine.get_indexer(idx.levels[0])
AttributeError: 'super' object has no attribute '_ensure_mapping_populated' # both 1.0 and master |
thanks @topper-123 |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Closes #33131, a weakref was released too early.