Skip to content

Commit 6ce4726

Browse files
committed
Add whatsnew note and additional tests for rename_axis(inplace=True)
1 parent 2c51767 commit 6ce4726

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Other Enhancements
3333
- The ``validate`` argument for :func:`merge` function now checks whether a merge is one-to-one, one-to-many, many-to-one, or many-to-many. If a merge is found to not be an example of specified merge type, an exception of type ``MergeError`` will be raised. For more, see :ref:`here <merging.validation>` (:issue:`16270`)
3434
- ``Series.to_dict()`` and ``DataFrame.to_dict()`` now support an ``into`` keyword which allows you to specify the ``collections.Mapping`` subclass that you would like returned. The default is ``dict``, which is backwards compatible. (:issue:`16122`)
3535
- ``RangeIndex.append`` now returns a ``RangeIndex`` object when possible (:issue:`16212`)
36+
- ``Series.rename_axis()`` and ``DataFrame.rename_axis()`` with ``inplace=True`` now return None while renaming the axis inplace. (:issue:`15704`)
3637
- :func:`to_pickle` has gained a protocol parameter (:issue:`16252`). By default, this parameter is set to `HIGHEST_PROTOCOL <https://docs.python.org/3/library/pickle.html#data-stream-format>`__
3738
- :func:`api.types.infer_dtype` now infers decimals. (:issue: `15690`)
3839
- :func:`read_feather` has gained the ``nthreads`` parameter for multi-threaded operations (:issue:`16359`)

pandas/tests/frame/test_alter_axes.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,19 @@ def test_rename(self):
420420

421421
def test_rename_axis_inplace(self):
422422
# GH 15704
423-
expected = self.frame.rename_axis('foo')
424-
no_return = self.frame.rename_axis('foo', inplace=True)
423+
frame = self.frame.copy()
424+
expected = frame.rename_axis('foo')
425+
result = frame.copy()
426+
no_return = result.rename_axis('foo', inplace=True)
427+
428+
assert no_return is None
429+
assert_frame_equal(result, expected)
430+
431+
expected = frame.rename_axis('bar', axis=1)
432+
result = frame.copy()
433+
no_return = result.rename_axis('bar', axis=1, inplace=True)
434+
425435
assert no_return is None
426-
result = self.frame
427436
assert_frame_equal(result, expected)
428437

429438
def test_rename_multiindex(self):

pandas/tests/series/test_alter_axes.py

+10
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,13 @@ def test_reorder_levels(self):
224224

225225
result = s.reorder_levels(['L0', 'L0', 'L0'])
226226
assert_series_equal(result, expected)
227+
228+
def test_rename_axis_inplace(self):
229+
# GH 15704
230+
series = self.ts.copy()
231+
expected = series.rename_axis('foo')
232+
result = series.copy()
233+
no_return = result.rename_axis('foo', inplace=True)
234+
235+
assert no_return is None
236+
assert_series_equal(result, expected)

0 commit comments

Comments
 (0)