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

Add a .relabel method; deprecate .rename and .rename_axis for relabeling #16990

Closed
toobaz opened this issue Jul 17, 2017 · 2 comments
Closed
Labels
API Design Deprecate Functionality to remove in pandas Duplicate Report Duplicate issue or pull request

Comments

@toobaz
Copy link
Member

toobaz commented Jul 17, 2017

This was suggested by @MaximilianR here, but @jorisvandenbossche (rightly) proposed to discuss separately.

This is related to the discussion on .rename and .rename_axis's signatures (see above), but touches a different issue. Currently, these two functions are confusing not just because they do the same thing, but also because they (each) do two different things (renaming axis/object name, and relabeling), and because they do not do the most obvious thing (relabeling by passing a list-like - since a list-like is assumed to refer to multiple names for a MultiIndex' levels).

My proposal is the following:

  • add a new method .relabel, which changes the content of the axis, as in
df.relabel(['l1', 'l2', 'l3']) # changes df.index labels - assuming df.index is flat
df.relabel([['l1a', 'l1b', 'l1c'], [...], [...]]) # changes df.index labels - assuming df.index has 3 levels
df.relabel(a_dict) # again, changes the index labels, analogously to what df.rename(a_dict) currently does
  • deprecate the use of .rename and .rename_index for doing the same operation, that is when the index or mapper argument (respectively) is a callable or dict-like; keep them (or, even better, keep one and deprecate the other) for changing only index names

Whether the signature of .relabel should follow the axis= or index=, column= standard will depend from the outcome of the discussion about rename and rename_index (#12392).

@gfyoung
Copy link
Member

gfyoung commented Jul 17, 2017

Not quite an enhancement but totally onboard with making a cleaner, simpler API.

@jreback
Copy link
Contributor

jreback commented Jul 17, 2017

this issue is duplicated by much discussion already, pls comment on the existing issues: #14829

xref issues:
#12392
#14636
#15104

@jreback jreback closed this as completed Jul 17, 2017
@gfyoung gfyoung added the Duplicate Report Duplicate issue or pull request label Jul 17, 2017
@gfyoung gfyoung added this to the No action milestone Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Deprecate Functionality to remove in pandas Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants