Skip to content

Commit 44782c0

Browse files
authored
BUG: no longer raise user warning when plotting tz aware time series (#31207)
1 parent 64336ff commit 44782c0

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

doc/source/whatsnew/v1.0.1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ I/O
105105
Plotting
106106
^^^^^^^^
107107

108-
-
108+
- Plotting tz-aware timeseries no longer gives UserWarning (:issue:`31205`)
109109
-
110110

111111
Groupby/resample/rolling

pandas/plotting/_matplotlib/timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _maybe_convert_index(ax, data):
251251
freq = frequencies.get_period_alias(freq)
252252

253253
if isinstance(data.index, ABCDatetimeIndex):
254-
data = data.to_period(freq=freq)
254+
data = data.tz_localize(None).to_period(freq=freq)
255255
elif isinstance(data.index, ABCPeriodIndex):
256256
data.index = data.index.asfreq(freq=freq)
257257
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")
5347
def test_ts_plot_with_tz(self, tz_aware_fixture):
54-
# GH2877, GH17173
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)
58-
_check_plot_works(ts.plot)
52+
with tm.assert_produces_warning(None):
53+
_check_plot_works(ts.plot)
5954

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

0 commit comments

Comments
 (0)