Skip to content

Commit

Permalink
DEPR: enforce deprecation of old set_axis signature (pandas-dev#30089)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and proost committed Dec 19, 2019
1 parent 50e35d3 commit d516ea1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 40 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Changed :meth:`Timedelta.resolution` to match the behavior of the standard library ``datetime.timedelta.resolution``, for the old behavior, use :meth:`Timedelta.resolution_string` (:issue:`26839`)
- Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`)
- Removed previously deprecated ``errors`` argument in :meth:`Timestamp.tz_localize`, :meth:`DatetimeIndex.tz_localize`, and :meth:`Series.tz_localize` (:issue:`22644`)
- :meth:`Series.set_axis` and :meth:`DataFrame.set_axis` now require "labels" as the first argument and "axis" as an optional named parameter (:issue:`30089`)
-

.. _whatsnew_1000.performance:
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,6 @@ def set_axis(self, labels, axis=0, inplace=False):
1 2 5
2 3 6
"""
if is_scalar(labels):
warnings.warn(
'set_axis now takes "labels" as first argument, and '
'"axis" as named parameter. The old form, with "axis" as '
'first parameter and "labels" as second, is still supported '
"but will be deprecated in a future version of pandas.",
FutureWarning,
stacklevel=2,
)
labels, axis = axis, labels

if inplace:
setattr(self, self._get_axis_name(axis), labels)
else:
Expand Down
18 changes: 0 additions & 18 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,21 +1548,3 @@ def test_set_axis_inplace(self):
for axis in 3, "foo":
with pytest.raises(ValueError, match="No axis named"):
df.set_axis(list("abc"), axis=axis)

def test_set_axis_prior_to_deprecation_signature(self):
df = DataFrame(
{"A": [1.1, 2.2, 3.3], "B": [5.0, 6.1, 7.2], "C": [4.4, 5.5, 6.6]},
index=[2010, 2011, 2012],
)

expected = {0: df.copy(), 1: df.copy()}
expected[0].index = list("abc")
expected[1].columns = list("abc")
expected["index"] = expected[0]
expected["columns"] = expected[1]

# old signature
for axis in expected:
with tm.assert_produces_warning(FutureWarning):
result = df.set_axis(axis, list("abc"), inplace=False)
tm.assert_frame_equal(result, expected[axis])
11 changes: 0 additions & 11 deletions pandas/tests/series/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,6 @@ def test_set_axis_inplace(self):
with pytest.raises(ValueError, match="No axis named"):
s.set_axis(list("abcd"), axis=axis, inplace=False)

def test_set_axis_prior_to_deprecation_signature(self):
s = Series(np.arange(4), index=[1, 3, 5, 7], dtype="int64")

expected = s.copy()
expected.index = list("abcd")

for axis in [0, "index"]:
with tm.assert_produces_warning(FutureWarning):
result = s.set_axis(0, list("abcd"), inplace=False)
tm.assert_series_equal(result, expected)

def test_reset_index_drop_errors(self):
# GH 20925

Expand Down

0 comments on commit d516ea1

Please sign in to comment.