Skip to content

Commit 0ac99ae

Browse files
author
Marco Gorelli
committed
🐛 no longer raise user warning when plotting tz aware time series
1 parent 6dea557 commit 0ac99ae

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ I/O
160160
Plotting
161161
^^^^^^^^
162162

163-
-
163+
- Plotting tz-aware timeseries no longer gives UserWarning (:issue:`31205`)
164164
-
165165

166166
Groupby/resample/rolling

pandas/plotting/_matplotlib/timeseries.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# TODO: Use the fact that axis can have units to simplify the process
22

33
import functools
4+
import warnings
45

56
import numpy as np
67

@@ -251,7 +252,9 @@ def _maybe_convert_index(ax, data):
251252
freq = frequencies.get_period_alias(freq)
252253

253254
if isinstance(data.index, ABCDatetimeIndex):
254-
data = data.to_period(freq=freq)
255+
with warnings.catch_warnings():
256+
warnings.filterwarnings("ignore", category=UserWarning)
257+
data = data.to_period(freq=freq)
255258
elif isinstance(data.index, ABCPeriodIndex):
256259
data.index = data.index.asfreq(freq=freq)
257260
return data

pandas/tests/plotting/test_datetimelike.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ def teardown_method(self, method):
4949
# ```
5050
# which occurs for UTC-like timezones.
5151
@pytest.mark.slow
52-
@pytest.mark.filterwarnings("ignore:msg:UserWarning")
5352
def test_ts_plot_with_tz(self, tz_aware_fixture):
5453
# GH2877, GH17173
5554
tz = tz_aware_fixture
5655
index = date_range("1/1/2011", periods=2, freq="H", tz=tz)
5756
ts = Series([188.5, 328.25], index=index)
58-
_check_plot_works(ts.plot)
57+
with pytest.warns(None) as all_warnings:
58+
_check_plot_works(ts.plot)
59+
assert len(all_warnings) == 0
5960

6061
def test_fontsize_set_correctly(self):
6162
# For issue #8765

0 commit comments

Comments
 (0)