Skip to content

Commit f2f4745

Browse files
Backport PR #31207: BUG: no longer raise user warning when plotting tz aware time series (#31601)
Co-authored-by: Marco Gorelli <[email protected]>
1 parent 78e6ec0 commit f2f4745

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

doc/source/whatsnew/v1.0.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ I/O
103103
Plotting
104104
^^^^^^^^
105105

106-
-
106+
- Plotting tz-aware timeseries no longer gives UserWarning (:issue:`31205`)
107107
-
108108

109109
Groupby/resample/rolling

pandas/plotting/_matplotlib/timeseries.py

+1-1
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ def teardown_method(self, method):
4545

4646
@pytest.mark.slow
4747
def test_ts_plot_with_tz(self, tz_aware_fixture):
48-
# GH2877, GH17173
48+
# GH2877, GH17173, GH31205
4949
tz = tz_aware_fixture
5050
index = date_range("1/1/2011", periods=2, freq="H", tz=tz)
5151
ts = Series([188.5, 328.25], index=index)
52-
_check_plot_works(ts.plot)
52+
with tm.assert_produces_warning(None):
53+
_check_plot_works(ts.plot)
5354

5455
def test_fontsize_set_correctly(self):
5556
# For issue #8765

0 commit comments

Comments
 (0)