Skip to content

BUG: Enable plotting with PeriodIndex with arbitrary frequencies, resolves #14763 #26241

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 16 commits into from
May 28, 2019
Merged
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions pandas/plotting/_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _get_index_freq(data):
def _maybe_convert_index(ax, data):
# tsplot converts automatically, but don't want to convert index
# over and over for DataFrames
if isinstance(data.index, ABCDatetimeIndex):
if isinstance(data.index, (ABCDatetimeIndex, ABCPeriodIndex)):
freq = getattr(data.index, 'freq', None)

if freq is None:
Expand All @@ -279,7 +279,10 @@ def _maybe_convert_index(ax, data):
freq = get_base_alias(freq)
freq = frequencies.get_period_alias(freq)

data = data.to_period(freq=freq)
if isinstance(data.index, ABCDatetimeIndex):
data = data.to_period(freq=freq)
elif isinstance(data.index, ABCPeriodIndex):
data.index = data.index.asfreq(freq)
return data


Expand Down