113
113
by : str or list of str
114
114
Name or list of names which refer to the axis items.""" ,
115
115
versionadded_to_excel = '' ,
116
- mapper = """mapper : dict-like or function
116
+ mapper = """mapper : dict-like or function
117
117
Applied to the axis specified by `axis`""" ,
118
118
)
119
119
@@ -2911,11 +2911,12 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
2911
2911
def rename (self , mapper = None , index = None , columns = None , axis = None ,
2912
2912
** kwargs ):
2913
2913
if axis is not None :
2914
+ # Using "axis" style, along with a positional mapper
2915
+ # Both index and columns should be None then
2914
2916
axis = self ._get_axis_name (axis )
2915
- # interpreting 'mapper' as a positional argument
2916
2917
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 "
2919
2920
"\t .rename(mapper, axis=axis), or\n "
2920
2921
"\t .rename(index=index, columns=columns)" )
2921
2922
if axis == 'index' :
@@ -2929,8 +2930,10 @@ def rename(self, mapper=None, index=None, columns=None, axis=None,
2929
2930
elif axis is None and (mapper is not None and index is not None ):
2930
2931
# Determine if they meant df.rename(idx_map, col_map)
2931
2932
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 )
2934
2937
index , columns = mapper , index
2935
2938
elif index is None and columns is None :
2936
2939
index = mapper
0 commit comments