Skip to content

Commit 77698c8

Browse files
jbrockmendelproost
authored andcommitted
DEPR: enforce deprecation of old set_axis signature (pandas-dev#30089)
1 parent b275e0d commit 77698c8

File tree

4 files changed

+1
-40
lines changed

4 files changed

+1
-40
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
614614
- 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`)
615615
- Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`)
616616
- Removed previously deprecated ``errors`` argument in :meth:`Timestamp.tz_localize`, :meth:`DatetimeIndex.tz_localize`, and :meth:`Series.tz_localize` (:issue:`22644`)
617+
- :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`)
617618
-
618619

619620
.. _whatsnew_1000.performance:

pandas/core/generic.py

-11
Original file line numberDiff line numberDiff line change
@@ -633,17 +633,6 @@ def set_axis(self, labels, axis=0, inplace=False):
633633
1 2 5
634634
2 3 6
635635
"""
636-
if is_scalar(labels):
637-
warnings.warn(
638-
'set_axis now takes "labels" as first argument, and '
639-
'"axis" as named parameter. The old form, with "axis" as '
640-
'first parameter and "labels" as second, is still supported '
641-
"but will be deprecated in a future version of pandas.",
642-
FutureWarning,
643-
stacklevel=2,
644-
)
645-
labels, axis = axis, labels
646-
647636
if inplace:
648637
setattr(self, self._get_axis_name(axis), labels)
649638
else:

pandas/tests/frame/test_alter_axes.py

-18
Original file line numberDiff line numberDiff line change
@@ -1548,21 +1548,3 @@ def test_set_axis_inplace(self):
15481548
for axis in 3, "foo":
15491549
with pytest.raises(ValueError, match="No axis named"):
15501550
df.set_axis(list("abc"), axis=axis)
1551-
1552-
def test_set_axis_prior_to_deprecation_signature(self):
1553-
df = DataFrame(
1554-
{"A": [1.1, 2.2, 3.3], "B": [5.0, 6.1, 7.2], "C": [4.4, 5.5, 6.6]},
1555-
index=[2010, 2011, 2012],
1556-
)
1557-
1558-
expected = {0: df.copy(), 1: df.copy()}
1559-
expected[0].index = list("abc")
1560-
expected[1].columns = list("abc")
1561-
expected["index"] = expected[0]
1562-
expected["columns"] = expected[1]
1563-
1564-
# old signature
1565-
for axis in expected:
1566-
with tm.assert_produces_warning(FutureWarning):
1567-
result = df.set_axis(axis, list("abc"), inplace=False)
1568-
tm.assert_frame_equal(result, expected[axis])

pandas/tests/series/test_alter_axes.py

-11
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,6 @@ def test_set_axis_inplace(self):
322322
with pytest.raises(ValueError, match="No axis named"):
323323
s.set_axis(list("abcd"), axis=axis, inplace=False)
324324

325-
def test_set_axis_prior_to_deprecation_signature(self):
326-
s = Series(np.arange(4), index=[1, 3, 5, 7], dtype="int64")
327-
328-
expected = s.copy()
329-
expected.index = list("abcd")
330-
331-
for axis in [0, "index"]:
332-
with tm.assert_produces_warning(FutureWarning):
333-
result = s.set_axis(0, list("abcd"), inplace=False)
334-
tm.assert_series_equal(result, expected)
335-
336325
def test_reset_index_drop_errors(self):
337326
# GH 20925
338327

0 commit comments

Comments
 (0)