diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c4c1b02cdc5abc..60f5efc021df82 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -497,23 +497,23 @@ def _expand_axes(self, key): 1 2 2 3 dtype: int64 - >>> s.set_axis(0, ['a', 'b', 'c'], inplace=False) + >>> s.set_axis(['a', 'b', 'c'], axis=0, inplace=False) a 1 b 2 c 3 dtype: int64 >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) - >>> df.set_axis(0, ['a', 'b', 'c'], inplace=False) + >>> df.set_axis(['a', 'b', 'c'], axis=0, inplace=False) A B a 1 4 b 2 5 c 3 6 - >>> df.set_axis(1, ['I', 'II'], inplace=False) + >>> df.set_axis(['I', 'II'], axis=1, inplace=False) I II 0 1 4 1 2 5 2 3 6 - >>> df.set_axis(1, ['i', 'ii'], inplace=True) + >>> df.set_axis(['i', 'ii'], axis=1, inplace=True) >>> df i ii 0 1 4 @@ -952,7 +952,7 @@ def _set_axis_name(self, name, axis=0, inplace=False): inplace = validate_bool_kwarg(inplace, 'inplace') renamed = self if inplace else self.copy() - renamed.set_axis(axis, idx) + renamed.set_axis(idx, axis=axis, inplace=True) if not inplace: return renamed @@ -5840,7 +5840,7 @@ def slice_shift(self, periods=1, axis=0): new_obj = self._slice(vslicer, axis=axis) shifted_axis = self._get_axis(axis)[islicer] - new_obj.set_axis(axis, shifted_axis) + new_obj.set_axis(shifted_axis, axis=axis, inplace=True) return new_obj.__finalize__(self) @@ -6000,7 +6000,7 @@ def _tz_convert(ax, tz): ax = _tz_convert(ax, tz) result = self._constructor(self._data, copy=copy) - result.set_axis(axis, ax) + result.set_axis(ax, axis=axis, inplace=True) return result.__finalize__(self) @deprecate_kwarg(old_arg_name='infer_dst', new_arg_name='ambiguous', @@ -6068,7 +6068,7 @@ def _tz_localize(ax, tz, ambiguous): ax = _tz_localize(ax, tz, ambiguous) result = self._constructor(self._data, copy=copy) - result.set_axis(axis, ax) + result.set_axis(ax, axis=axis, inplace=True) return result.__finalize__(self) # ---------------------------------------------------------------------- diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index daf3381ae4e890..c8a7ee752d243f 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -530,10 +530,11 @@ def _set_result_index_ordered(self, result): if not self.grouper.is_monotonic: index = Index(np.concatenate( self._get_indices(self.grouper.result_index))) - result.set_axis(self.axis, index) + result.set_axis(index, axis=self.axis, inplace=True) result = result.sort_index(axis=self.axis) - result.set_axis(self.axis, self.obj._get_axis(self.axis)) + result.set_axis(self.obj._get_axis(self.axis), axis=self.axis, + inplace=True) return result def _dir_additions(self): diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 0581ec7484c491..0e351c9df62854 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -311,8 +311,9 @@ def _all_key(key): except TypeError: # we cannot reshape, so coerce the axis - piece.set_axis(cat_axis, piece._get_axis( - cat_axis)._to_safe_for_reshape()) + piece.set_axis(piece._get_axis( + cat_axis)._to_safe_for_reshape(), + axis=cat_axis, inplace=True) piece[all_key] = margin[key] table_pieces.append(piece)