Skip to content

Commit 8b72297

Browse files
authored
DEPR: sort_columns in plot (#47563) (#48073)
1 parent 50c2af1 commit 8b72297

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ Other Deprecations
847847
- Deprecated unused arguments ``encoding`` and ``verbose`` in :meth:`Series.to_excel` and :meth:`DataFrame.to_excel` (:issue:`47912`)
848848
- 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`)
849849
- 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`)
850+
- Deprecated the ``sort_columns`` argument in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`).
850851

851852
.. ---------------------------------------------------------------------------
852853
.. _whatsnew_150.performance:

pandas/plotting/_core.py

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

33
import importlib
4+
import inspect
5+
import itertools
46
import types
57
from typing import (
68
TYPE_CHECKING,
79
Sequence,
810
)
11+
import warnings
912

1013
from pandas._config import get_option
1114

@@ -14,6 +17,7 @@
1417
Appender,
1518
Substitution,
1619
)
20+
from pandas.util._exceptions import find_stack_level
1721

1822
from pandas.core.dtypes.common import (
1923
is_integer,
@@ -755,6 +759,11 @@ class PlotAccessor(PandasObject):
755759
If True, create stacked plot.
756760
sort_columns : bool, default False
757761
Sort column names to determine plot ordering.
762+
763+
.. deprecated:: 1.5.0
764+
The `sort_columns` arguments is deprecated and will be removed in a
765+
future version.
766+
758767
secondary_y : bool or sequence, default False
759768
Whether to plot on the secondary y-axis if a list/tuple, which
760769
columns to plot on secondary y-axis.
@@ -875,6 +884,14 @@ def _get_call_args(backend_name, data, args, kwargs):
875884
"expected Series or DataFrame"
876885
)
877886

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

pandas/tests/plotting/frame/test_frame.py

+13
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,19 @@ 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+
# GH 47563
2220+
df = DataFrame({"a": [1, 2], "b": [3, 4]})
2221+
2222+
with tm.assert_produces_warning(FutureWarning):
2223+
df.plot.box("a", sort_columns=True)
2224+
2225+
with tm.assert_produces_warning(FutureWarning):
2226+
df.plot.box(sort_columns=False)
2227+
2228+
with tm.assert_produces_warning(False):
2229+
df.plot.box("a")
2230+
22182231

22192232
def _generate_4_axes_via_gridspec():
22202233
import matplotlib as mpl

0 commit comments

Comments
 (0)