Skip to content

Commit a14edfe

Browse files
committed
BUG: Enable plotting with PeriodIndex with arbitrary frequencies, resolves pandas-dev#14763
1 parent 9feb3ad commit a14edfe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/plotting/_timeseries.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def _get_index_freq(data):
262262
def _maybe_convert_index(ax, data):
263263
# tsplot converts automatically, but don't want to convert index
264264
# over and over for DataFrames
265-
if isinstance(data.index, ABCDatetimeIndex):
265+
if isinstance(data.index, (ABCDatetimeIndex, ABCPeriodIndex)):
266266
freq = getattr(data.index, 'freq', None)
267267

268268
if freq is None:
@@ -279,7 +279,10 @@ def _maybe_convert_index(ax, data):
279279
freq = get_base_alias(freq)
280280
freq = frequencies.get_period_alias(freq)
281281

282-
data = data.to_period(freq=freq)
282+
if isinstance(data.index, ABCDatetimeIndex):
283+
data = data.to_period(freq=freq)
284+
elif isinstance(data.index, ABCPeriodIndex):
285+
data.index = data.index.asfreq(freq)
283286
return data
284287

285288

0 commit comments

Comments
 (0)