Skip to content

Commit ead2624

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

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,15 @@ def setup_method(self, method):
4343
def teardown_method(self, method):
4444
tm.close()
4545

46-
# Ignore warning
47-
# ```
48-
# Converting to PeriodArray/Index representation will drop timezone information.
49-
# ```
50-
# which occurs for UTC-like timezones.
5146
@pytest.mark.slow
52-
@pytest.mark.filterwarnings("ignore:msg:UserWarning")
5347
def test_ts_plot_with_tz(self, tz_aware_fixture):
5448
# GH2877, GH17173
5549
tz = tz_aware_fixture
5650
index = date_range("1/1/2011", periods=2, freq="H", tz=tz)
5751
ts = Series([188.5, 328.25], index=index)
58-
_check_plot_works(ts.plot)
52+
with pytest.warns(UserWarning) as user_warnings:
53+
_check_plot_works(ts.plot)
54+
assert len(user_warnings) == 0
5955

6056
def test_fontsize_set_correctly(self):
6157
# For issue #8765

0 commit comments

Comments
 (0)