8000 ENH: Allow rename_axis to specify index and columns arguments by Dr-Irv · Pull Request #20046 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Allow rename_axis to specify index and columns arguments #20046

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 19 commits into from
Oct 29, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some doc changes
  • Loading branch information
Dr-Irv committed Mar 7, 2018
commit 99011df0cc42d1649aaee3a44eb534dde2bc6288
41 changes: 31 additions & 10 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,16 @@ def rename(self, *args, **kwargs):
rename.__doc__ = _shared_docs['rename']

def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
"""Alter the name of the index or columns.
"""Alter the name of the index or name of index backing the
columns.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this to be one line.


Parameters
----------
mapper : scalar, list-like, optional
Value to set the axis name attribute.
s, index, columns : dict-like or function, optional
dict-like or functions transformations to apply to
that axis' values. Use either ``s`` and ``axis`` to
specify the axis to target with ``s``, or ``index`` and
``columns``.
axis : int or string, default 0
copy : boolean, default True
Also copy underlying data
Expand All @@ -934,6 +938,22 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
the axis *labels* by passing a mapping or scalar. This behavior is
deprecated and will be removed in a future version. Use ``rename``
instead.

``DataFrame.rename_axis`` supports two calling conventions

* ``(index=index_mapper, columns=columns_mapper, ...)``
* ``(s, axis={'index', 'columns'}, ...)``

The first calling convention will only modify the names of
the index or the names of the index backing the columns.

The second calling convention will modify the names of the
the corresponding index if s is a list or a scalar.
However, if s is dict-like or a function, it will use the
deprecated behavior of modifying the axis *labels*.

We *highly* recommend using keyword arguments to clarify your
intent.

See Also
--------
Expand Down Expand Up @@ -964,13 +984,14 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
if non_mapper:
return self._set_axis_name(mapper, axis=axis, inplace=inplace)
else:
# msg = ("Using 'rename_axis' to alter labels is deprecated. "
# "Use '.rename' instead")
# warnings.warn(msg, FutureWarning, stacklevel=2)
# axis = self._get_axis_name(axis)
# d = {'copy': copy, 'inplace': inplace}
# d[axis] = mapper
# return self.rename(**d)
msg = ("Using 'rename_axis' to alter labels is deprecated. "
"Use '.rename' instead")
warnings.warn(msg, FutureWarning, stacklevel=2)
axis = self._get_axis_name(axis)
d = {'copy': copy, 'inplace': inplace}
d[axis] = mapper
return self.rename(**d)
if (FALSE):
f = self._get_rename_function(mapper)
curnames = self._get_axis(axis).names
newnames = [f(name) for name in curnames]
Expand Down
0