Skip to content

Commit 332bd6e

Browse files
committed
DEPR: sort_columns in plot (#47563)
1 parent 96fe059 commit 332bd6e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ Other Deprecations
845845
- Deprecated unused arguments ``encoding`` and ``verbose`` in :meth:`Series.to_excel` and :meth:`DataFrame.to_excel` (:issue:`47912`)
846846
- Deprecated producing a single element when iterating over a :class:`DataFrameGroupBy` or a :class:`SeriesGroupBy` that has been grouped by a list of length 1; A tuple of length one will be returned instead (:issue:`42795`)
847847
- Fixed up warning message of deprecation of :meth:`MultiIndex.lesort_depth` as public method, as the message previously referred to :meth:`MultiIndex.is_lexsorted` instead (:issue:`38701`)
848+
- Deprecated the ``sort_columns`` argument in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`).
848849

849850
.. ---------------------------------------------------------------------------
850851
.. _whatsnew_150.performance:

pandas/plotting/_core.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import annotations
22

33
import importlib
4+
import inspect
45
import types
56
from typing import (
67
TYPE_CHECKING,
78
Sequence,
89
)
10+
import warnings
911

1012
from pandas._config import get_option
1113

@@ -14,6 +16,7 @@
1416
Appender,
1517
Substitution,
1618
)
19+
from pandas.util._exceptions import find_stack_level
1720

1821
from pandas.core.dtypes.common import (
1922
is_integer,
@@ -755,6 +758,11 @@ class PlotAccessor(PandasObject):
755758
If True, create stacked plot.
756759
sort_columns : bool, default False
757760
Sort column names to determine plot ordering.
761+
762+
.. deprecated:: 1.5.0
763+
The `sort_columns` arguments is deprecated and will be removed in a
764+
future version.
765+
758766
secondary_y : bool or sequence, default False
759767
Whether to plot on the secondary y-axis if a list/tuple, which
760768
columns to plot on secondary y-axis.
@@ -875,6 +883,14 @@ def _get_call_args(backend_name, data, args, kwargs):
875883
"expected Series or DataFrame"
876884
)
877885

886+
if "sort_columns" in args + tuple(kwargs.keys()):
887+
warnings.warn(
888+
"`sort_columns` is deprecated and will be removed in a future "
889+
"version.",
890+
FutureWarning,
891+
stacklevel=find_stack_level(inspect.currentframe()),
892+
)
893+
878894
if args and isinstance(data, ABCSeries):
879895
positional_args = str(args)[1:-1]
880896
keyword_args = ", ".join(

pandas/tests/plotting/frame/test_frame.py

+12
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,18 @@ def test_secondary_y(self, secondary_y):
22152215
assert ax.get_ylim() == (0, 100)
22162216
assert ax.get_yticks()[0] == 99
22172217

2218+
def test_sort_columns_deprecated(self):
2219+
df = DataFrame({"a": [1, 2], "b": [3, 4]})
2220+
2221+
with tm.assert_produces_warning(FutureWarning):
2222+
df.plot.box("a", sort_columns=True)
2223+
2224+
with tm.assert_produces_warning(FutureWarning):
2225+
df.plot.box(sort_columns=False)
2226+
2227+
with tm.assert_produces_warning(False):
2228+
df.plot.box("a")
2229+
22182230

22192231
def _generate_4_axes_via_gridspec():
22202232
import matplotlib as mpl

0 commit comments

Comments
 (0)