Skip to content
Prev Previous commit
Series.rename now handles values by Series constructor
  • Loading branch information
prajvalgupta committed Aug 17, 2019
commit b929efd65964c2bf51b6132af6aac07c8833daa0
8 changes: 3 additions & 5 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4165,12 +4165,10 @@ def rename(self, index=None, **kwargs):
"""
kwargs["inplace"] = validate_bool_kwarg(kwargs.get("inplace", False), "inplace")

non_mapping = is_scalar(index) or (
is_list_like(index) and not is_dict_like(index)
)
if non_mapping:
if callable(index) or is_dict_like(index):
return super().rename(index=index, **kwargs)
else:
return self._set_name(index, inplace=kwargs.get("inplace"))
return super().rename(index=index, **kwargs)

@Substitution(**_shared_doc_kwargs)
@Appender(generic.NDFrame.reindex.__doc__)
Expand Down