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

df.rename works with 'mapper' and 'axis' params #1057

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,11 +1364,13 @@ def rename(
# inplace should always be true because this is just a copy, and we will use the
# results after.
kwargs["inplace"] = False
if index is not None:
if axis is not None:
axis = self._get_axis_number(axis)
if index is not None or (mapper is not None and axis == 0):
new_index = pandas.DataFrame(index=self.index).rename(**kwargs).index
else:
new_index = self.index
if columns is not None:
if columns is not None or (mapper is not None and axis == 1):
new_columns = (
pandas.DataFrame(columns=self.columns).rename(**kwargs).columns
)
Expand Down
10 changes: 10 additions & 0 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4639,6 +4639,16 @@ def test_rename_sanity(self):
tm.assert_index_equal(
modin_df.rename(index=str.upper).index, df.rename(index=str.upper).index
)

# Using the `mapper` functionality with `axis`
tm.assert_index_equal(
modin_df.rename(str.upper, axis=0).index, df.rename(str.upper, axis=0).index
)
tm.assert_index_equal(
modin_df.rename(str.upper, axis=1).columns,
df.rename(str.upper, axis=1).columns,
)

# have to pass something
with pytest.raises(TypeError):
modin_df.rename()
Expand Down