Skip to content

Commit

Permalink
🐛 no longer raise user warning when plotting tz aware time series
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Gorelli committed Jan 23, 2020
1 parent b529857 commit 66adf3b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ I/O
Plotting
^^^^^^^^

-
- Plotting tz-aware timeseries no longer gives UserWarning (:issue:`31205`)
-

Groupby/resample/rolling
Expand Down
5 changes: 4 additions & 1 deletion pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO: Use the fact that axis can have units to simplify the process

import functools
import warnings

import numpy as np

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

if isinstance(data.index, ABCDatetimeIndex):
data = data.to_period(freq=freq)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
data = data.to_period(freq=freq)
elif isinstance(data.index, ABCPeriodIndex):
data.index = data.index.asfreq(freq=freq)
return data
Expand Down
11 changes: 3 additions & 8 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,14 @@ def setup_method(self, method):
def teardown_method(self, method):
tm.close()

# Ignore warning
# ```
# Converting to PeriodArray/Index representation will drop timezone information.
# ```
# which occurs for UTC-like timezones.
@pytest.mark.slow
@pytest.mark.filterwarnings("ignore:msg:UserWarning")
def test_ts_plot_with_tz(self, tz_aware_fixture):
# GH2877, GH17173
def test_ts_plot_with_tz(self, tz_aware_fixture, recwarn):
# GH2877, GH17173, GH31205
tz = tz_aware_fixture
index = date_range("1/1/2011", periods=2, freq="H", tz=tz)
ts = Series([188.5, 328.25], index=index)
_check_plot_works(ts.plot)
assert not any(isinstance(i.message, UserWarning) for i in recwarn)

def test_fontsize_set_correctly(self):
# For issue #8765
Expand Down

0 comments on commit 66adf3b

Please sign in to comment.