Skip to content

Commit 1c28cd9

Browse files
Marco GorelliMarcoGorelli
Marco Gorelli
authored andcommitted
🐛 no longer raise user warning when plotting tz aware time series
1 parent fc813e7 commit 1c28cd9

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

doc/source/whatsnew/v1.0.1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ I/O
9797
Plotting
9898
^^^^^^^^
9999

100-
-
100+
- Plotting tz-aware timeseries no longer gives UserWarning (:issue:`31205`)
101101
-
102102

103103
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,14 @@ 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")
53-
def test_ts_plot_with_tz(self, tz_aware_fixture):
54-
# GH2877, GH17173
47+
def test_ts_plot_with_tz(self, tz_aware_fixture, recwarn):
48+
# GH2877, GH17173, GH31205
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)
5852
_check_plot_works(ts.plot)
53+
assert not any(isinstance(i.message, UserWarning) for i in recwarn)
5954

6055
def test_fontsize_set_correctly(self):
6156
# For issue #8765

0 commit comments

Comments
 (0)