Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: sort_columns in plot (#47563) #48073

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ Other Deprecations
- Deprecated unused arguments ``encoding`` and ``verbose`` in :meth:`Series.to_excel` and :meth:`DataFrame.to_excel` (:issue:`47912`)
- 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`)
- 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`)
- Deprecated the ``sort_columns`` argument in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`).

.. ---------------------------------------------------------------------------
.. _whatsnew_150.performance:
Expand Down
17 changes: 17 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations

import importlib
import inspect
import itertools
import types
from typing import (
TYPE_CHECKING,
Sequence,
)
import warnings

from pandas._config import get_option

Expand All @@ -14,6 +17,7 @@
Appender,
Substitution,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_integer,
Expand Down Expand Up @@ -755,6 +759,11 @@ class PlotAccessor(PandasObject):
If True, create stacked plot.
sort_columns : bool, default False
Sort column names to determine plot ordering.

.. deprecated:: 1.5.0
The `sort_columns` arguments is deprecated and will be removed in a
future version.

secondary_y : bool or sequence, default False
Whether to plot on the secondary y-axis if a list/tuple, which
columns to plot on secondary y-axis.
Expand Down Expand Up @@ -875,6 +884,14 @@ def _get_call_args(backend_name, data, args, kwargs):
"expected Series or DataFrame"
)

if "sort_columns" in itertools.chain(args, kwargs.keys()):
warnings.warn(
"`sort_columns` is deprecated and will be removed in a future "
"version.",
FutureWarning,
stacklevel=find_stack_level(inspect.currentframe()),
)

if args and isinstance(data, ABCSeries):
positional_args = str(args)[1:-1]
keyword_args = ", ".join(
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,19 @@ def test_secondary_y(self, secondary_y):
assert ax.get_ylim() == (0, 100)
assert ax.get_yticks()[0] == 99

def test_sort_columns_deprecated(self):
# GH 47563
df = DataFrame({"a": [1, 2], "b": [3, 4]})

with tm.assert_produces_warning(FutureWarning):
df.plot.box("a", sort_columns=True)

with tm.assert_produces_warning(FutureWarning):
df.plot.box(sort_columns=False)
YagoGG marked this conversation as resolved.
Show resolved Hide resolved

with tm.assert_produces_warning(False):
df.plot.box("a")


def _generate_4_axes_via_gridspec():
import matplotlib as mpl
Expand Down