Skip to content

Commit 263ee7a

Browse files
author
Marc Garcia
committed
Adding FutureWarning if Series.plot is called with positional arguments
1 parent 57c4937 commit 263ee7a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

pandas/plotting/_core.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib
22
from typing import List, Type # noqa
3+
import warnings
34

45
from pandas.util._decorators import Appender
56

@@ -518,11 +519,6 @@ def _get_call_args(data, args, kwargs):
518519
signatures, since `DataFramePlotMethods` accepted `x` and `y`
519520
parameters.
520521
"""
521-
if args and isinstance(data, ABCSeries):
522-
# TODO raise warning here, positional arguments shouldn't be
523-
# used anymore, so we can add x, y and kind to the signature
524-
pass
525-
526522
if isinstance(data, ABCSeries):
527523
arg_def = [
528524
('kind', 'line'), ('ax', None), ('figsize', None),
@@ -550,6 +546,18 @@ def _get_call_args(data, args, kwargs):
550546
'Series or DataFrame').format(
551547
type(data).__name__))
552548

549+
if args and isinstance(data, ABCSeries):
550+
msg = ('`Series.plot()` should not be called with positional '
551+
'arguments, only keyword arguments. The order of '
552+
'positional arguments will change in the future. '
553+
'Use `Series.plot({})` instead of `Series.plot({})`.')
554+
positional_args = str(args)[1:-1]
555+
keyword_args = ', '.join('{}={!r}'.format(name, value)
556+
for (name, default), value
557+
in zip(arg_def, args))
558+
warnings.warn(msg.format(keyword_args, positional_args),
559+
FutureWarning, stacklevel=3)
560+
553561
pos_args = {name: value for value, (name, _) in zip(args, arg_def)}
554562
kwargs = dict(arg_def, **pos_args, **kwargs)
555563

pandas/tests/plotting/test_misc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pandas.util._test_decorators as td
1111

12-
from pandas import DataFrame
12+
from pandas import DataFrame, Series
1313
from pandas.tests.plotting.common import TestPlotBase, _check_plot_works
1414
import pandas.util.testing as tm
1515

@@ -25,6 +25,12 @@ def test_import_error_message():
2525
df.plot()
2626

2727

28+
@td.skip_if_no_mpl
29+
def test_series_plot_with_positional_arguments_warns():
30+
with tm.assert_produces_warning(FutureWarning):
31+
Series([1, 2, 3]).plot('line', None)
32+
33+
2834
@td.skip_if_no_mpl
2935
class TestSeriesPlots(TestPlotBase):
3036

0 commit comments

Comments
 (0)