From 66adf3bf2cd49f50b419e84a96e023b6a92012d3 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Wed, 22 Jan 2020 14:37:41 +0000 Subject: [PATCH] :bug: no longer raise user warning when plotting tz aware time series --- doc/source/whatsnew/v1.1.0.rst | 2 +- pandas/plotting/_matplotlib/timeseries.py | 5 ++++- pandas/tests/plotting/test_datetimelike.py | 11 +++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index c8e811ce82b1f2..6c130cbe243cd0 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -162,7 +162,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 dd048114142f32..a6b0b91f99fa85 100644 --- a/pandas/plotting/_matplotlib/timeseries.py +++ b/pandas/plotting/_matplotlib/timeseries.py @@ -1,6 +1,7 @@ # TODO: Use the fact that axis can have units to simplify the process import functools +import warnings import numpy as np @@ -251,7 +252,9 @@ def _maybe_convert_index(ax, data): freq = frequencies.get_period_alias(freq) if isinstance(data.index, ABCDatetimeIndex): - data = data.to_period(freq=freq) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=UserWarning) + data = data.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 84d298cd7c6fe1..500fb69b028c48 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -43,19 +43,14 @@ def setup_method(self, method): def teardown_method(self, method): tm.close() - # Ignore warning - # ``` - # Converting to PeriodArray/Index representation will drop timezone information. - # ``` - # which occurs for UTC-like timezones. @pytest.mark.slow - @pytest.mark.filterwarnings("ignore:msg:UserWarning") - def test_ts_plot_with_tz(self, tz_aware_fixture): - # GH2877, GH17173 + def test_ts_plot_with_tz(self, tz_aware_fixture, recwarn): + # 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) + assert not any(isinstance(i.message, UserWarning) for i in recwarn) def test_fontsize_set_correctly(self): # For issue #8765