Skip to content

Commit

Permalink
REF: adapt NDFrame.set_axis() calls to new signature
Browse files Browse the repository at this point in the history
  • Loading branch information
toobaz committed Jul 18, 2017
1 parent 94c58ed commit bfa7466
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)

# ----------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bfa7466

Please sign in to comment.