From 104d1ef0c9748daf37cb141be984945e0cb0fb60 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 3 Feb 2020 07:36:35 +0000 Subject: [PATCH] Backport PR #31207: BUG: no longer raise user warning when plotting tz aware time series --- doc/source/whatsnew/v1.0.1.rst | 2 +- pandas/plotting/_matplotlib/timeseries.py | 2 +- pandas/tests/plotting/test_datetimelike.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.0.1.rst b/doc/source/whatsnew/v1.0.1.rst index 71a67e10ca38c..684dcb1cbf002 100644 --- a/doc/source/whatsnew/v1.0.1.rst +++ b/doc/source/whatsnew/v1.0.1.rst @@ -95,7 +95,7 @@ I/O Plotting ^^^^^^^^ -- +- Plotting tz-aware timeseries no longer gives UserWarning (:issue:`31205`) - Groupby/resample/rolling diff --git a/pandas/plotting/_matplotlib/timeseries.py b/pandas/plotting/_matplotlib/timeseries.py index dd048114142f3..3abce690cbe6b 100644 --- a/pandas/plotting/_matplotlib/timeseries.py +++ b/pandas/plotting/_matplotlib/timeseries.py @@ -251,7 +251,7 @@ def _maybe_convert_index(ax, data): freq = frequencies.get_period_alias(freq) if isinstance(data.index, ABCDatetimeIndex): - data = data.to_period(freq=freq) + data = data.tz_localize(None).to_period(freq=freq) elif isinstance(data.index, ABCPeriodIndex): data.index = data.index.asfreq(freq=freq) return data diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 8f855fd0c6cff..10d7efd22971b 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -45,11 +45,12 @@ def teardown_method(self, method): @pytest.mark.slow def test_ts_plot_with_tz(self, tz_aware_fixture): - # GH2877, GH17173 + # GH2877, GH17173, GH31205 tz = tz_aware_fixture index = date_range("1/1/2011", periods=2, freq="H", tz=tz) ts = Series([188.5, 328.25], index=index) - _check_plot_works(ts.plot) + with tm.assert_produces_warning(None): + _check_plot_works(ts.plot) def test_fontsize_set_correctly(self): # For issue #8765