Skip to content

BUG: no longer raise user warning when plotting tz aware time series #31207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ I/O
Plotting
^^^^^^^^

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

Groupby/resample/rolling
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _maybe_convert_index(ax, data):
freq = frequencies.get_period_alias(freq)

if isinstance(data.index, ABCDatetimeIndex):
data = data.to_period(freq=freq)
data = data.tz_localize(None).to_period(freq=freq)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To preserve the existing behaviour, this might need to be tz_convert instead of tz_localize ? (the first will give the underlying UTC data, the other converts to naive local time)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe check with a small actual example and see what plotting it gives (on 0.25.3 and on this PR).

Because intuitively, converting to local time zone sounds more useful, though. But not fully sure what the current behaviour is

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the output of

df = pd.DataFrame(np.random.randn(100, 3), index=pd.date_range("2012", freq='H', periods=100, tz='UTC'), columns=['a', 'b', 'c']) 
df.head().plot() 

on 0.25.3:
image

On this branch:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoGorelli can you try with something else as UTC? (as UTC is the one timezone where UTC and local is the same :-))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorisvandenbossche sure :)

df = pd.DataFrame(
    np.random.randn(100, 3),
    index=pd.date_range(
        "2012", freq="H", periods=100, tz=pytz.timezone("Africa/Gaborone")
    ),
    columns=["a", "b", "c"],
)
df.head().plot()

0.25.3
image

This branch:
image

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
# 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)
with tm.assert_produces_warning(None):
_check_plot_works(ts.plot)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add something to check that the points are actually in the correct date-time, e.g. we removed the timezone (checking first/last prob enough)


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