Skip to content

ENH: Support rename on MultiIndex #4628

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
jtratner opened this issue Aug 21, 2013 · 3 comments · Fixed by #4718
Closed

ENH: Support rename on MultiIndex #4628

jtratner opened this issue Aug 21, 2013 · 3 comments · Fixed by #4718
Milestone

Comments

@jtratner
Copy link
Contributor

Change up MultiIndex.rename to be an alias for MultiIndex.set_names.

  • Index.rename : takes single object
  • MultiIndex.set_names, Index.set_names - same type signature: take list of names [Index.set_names can only take iterable of length 1)
  • MultiIndex.rename - synonym for set_names

So if you want to do something generically, you should use set_names (just like you would with other attributes). If you expect a non-MI index, then you could use rename with a string, etc.

cc @jreback

I personally think that this behavior is how it should work for Index. Everyone okay with this? I'd prefer not to do type sniffing if at all possible.

ind = Index(range(10))
ind.rename(["apple"], inplace=True)
print(ind.name) # ['apple']
print(ind.names) # [['apple']]
ind.set_names('apple') # Fails with error that it's too long
@jreback
Copy link
Contributor

jreback commented Aug 21, 2013

ind.set_name('a') would work (but is wrong), maybe just disallow its not com.is_list_like

@jtratner
Copy link
Contributor Author

@jreback there's no set_name defined, so that's okay. Have to leave in this behavior, because levels are converted to indices and are given tuples as names in some parts of the library/tests - so on rename, I don't think it's worth it to check (and it's not very important either)

@jreback
Copy link
Contributor

jreback commented Aug 31, 2013

I think I meant set_names which works fine with a list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants