Skip to content

BUG: MultiIndex.set_names loses name #11979

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

Open
TomAugspurger opened this issue Jan 7, 2016 · 7 comments
Open

BUG: MultiIndex.set_names loses name #11979

TomAugspurger opened this issue Jan 7, 2016 · 7 comments

Comments

@TomAugspurger
Copy link
Contributor

Seems surprising, I thought .name would come along.

In [31]: idx = pd.MultiIndex.from_product([['A'], ['a', 'b', 'c']])

In [32]: idx.name = 'foo'

In [33]: idx2 = idx.set_names(['l1', 'l2'])

In [34]: idx2.name

Bug, or user error since MultiIndex.name isn't all that useful?

@jreback
Copy link
Contributor

jreback commented Jan 7, 2016

I think the fix is similar to what I am doing in RangeIndex for copy, see here: https://github.com/pydata/pandas/pull/11892/files#diff-dc96e62847cdfe77b570cf9c6b0e8086R495

name and names are accepted and aliased to each other for both Index and MultiIndex. mainly for compat I think (e.g. for an Index people tend to use name and for a MultiIndex names). You can't have both, but either should set correctly. (of course a MultiIndex index requires a list equal in len to the levels; .set_names enforces this). I think the setter needs to be updated though.

@jreback jreback modified the milestones: Next Major Release, 0.18.0 Jan 7, 2016
@jreback jreback modified the milestones: 0.18.1, 0.18.0 Feb 10, 2016
@jreback
Copy link
Contributor

jreback commented Feb 10, 2016

does #11980 close this?

@TomAugspurger
Copy link
Contributor Author

No, I think I had an old test would have failed, but I removed the ability to set both self.index.name and self.index.names on a MultiIndex

@jreback
Copy link
Contributor

jreback commented Feb 10, 2016

thanks @TomAugspurger

@SeeminSyed
Copy link

Does #30335 close this ticket and if not, would I be possible for me to work on it?

@SeeminSyed
Copy link

@TomAugspurger @jreback @jbrockmendel ^^^

Sorry to disturb but I'm not sure notifications are sent if people are not mentioned by name.

@TomAugspurger
Copy link
Contributor Author

No, this isn't fixed by #30335.

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants