Skip to content

Commit 7ac2e3b

Browse files
committed
Cleanup messages, generic
1 parent 2478296 commit 7ac2e3b

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

pandas/core/frame.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
by : str or list of str
114114
Name or list of names which refer to the axis items.""",
115115
versionadded_to_excel='',
116-
mapper = """mapper : dict-like or function
116+
mapper="""mapper : dict-like or function
117117
Applied to the axis specified by `axis`""",
118118
)
119119

@@ -2911,11 +2911,12 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
29112911
def rename(self, mapper=None, index=None, columns=None, axis=None,
29122912
**kwargs):
29132913
if axis is not None:
2914+
# Using "axis" style, along with a positional mapper
2915+
# Both index and columns should be None then
29142916
axis = self._get_axis_name(axis)
2915-
# interpreting 'mapper' as a positional argument
29162917
if index is not None or columns is not None:
2917-
raise TypeError("Can't specify 'index' or 'columns' and 'axis'"
2918-
" at the same time. Specify either\n"
2918+
raise TypeError("Can't specify both 'axis' and 'index' or "
2919+
"'columns' Specify either\n"
29192920
"\t.rename(mapper, axis=axis), or\n"
29202921
"\t.rename(index=index, columns=columns)")
29212922
if axis == 'index':
@@ -2929,8 +2930,10 @@ def rename(self, mapper=None, index=None, columns=None, axis=None,
29292930
elif axis is None and (mapper is not None and index is not None):
29302931
# Determine if they meant df.rename(idx_map, col_map)
29312932
if callable(index) or is_dict_like(index):
2932-
warnings.warn("Interpreting renaming index and columns. "
2933-
"Use keyword arguments.", UserWarning)
2933+
warnings.warn("Interpreting call to '.rename(a, b)' as "
2934+
"'.rename(index=a, columns=b)'. "
2935+
"Use keyword arguments to remove ambiguity.",
2936+
UserWarning)
29342937
index, columns = mapper, index
29352938
elif index is None and columns is None:
29362939
index = mapper

pandas/core/generic.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -828,16 +828,6 @@ def rename(self, *args, **kwargs):
828828
copy = kwargs.pop('copy', True)
829829
inplace = kwargs.pop('inplace', False)
830830
level = kwargs.pop('level', None)
831-
axis = kwargs.pop("axis", None)
832-
833-
if axis:
834-
# At this point, we know the call was
835-
# rename(fn, axis=axis), so axes is always
836-
# {index: op, columns: None}
837-
axis = self._get_axis_name(axis)
838-
op = axes['index']
839-
axes['index'] = None
840-
axes[axis] = op
841831

842832
if kwargs:
843833
raise TypeError('rename() got an unexpected keyword '

0 commit comments

Comments
 (0)