Skip to content

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

Merged
merged 2 commits into from
Mar 31, 2020

Conversation

topper-123
Copy link
Contributor

Closes #33131, a weakref was released too early.

@topper-123 topper-123 force-pushed the bug_MultiIndex_with_periods branch from 3fe0afa to 39cc530 Compare March 29, 2020 22:40
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
Copy link
Member

@ShaharNaveh ShaharNaveh Mar 29, 2020

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?

Copy link
Contributor Author

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.

@jreback jreback added Bug MultiIndex Period Period data type labels Mar 30, 2020
@jreback jreback added this to the 1.1 milestone Mar 30, 2020
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.

lgtm. if you'd add a whatsnew note. merge on green.

@jbrockmendel
Copy link
Member

If PeriodEngine.get_indexer is ever called it will raise AttributeError, ditto get_pad_indexer, get_backfill indexer.

@topper-123
Copy link
Contributor Author

@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

@jreback jreback merged commit f10ec59 into pandas-dev:master Mar 31, 2020
@jreback
Copy link
Contributor

jreback commented Mar 31, 2020

thanks @topper-123

@topper-123 topper-123 deleted the bug_MultiIndex_with_periods branch March 31, 2020 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Copying PeriodIndex levels on MultiIndex loses weakrefs
4 participants