Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pandas._libs.tslibs.frequencies import FreqGroup, base_and_stride, get_freq_code
from pandas._libs.tslibs.period import Period
from pandas._typing import FrameOrSeriesUnion

from pandas.core.dtypes.generic import (
ABCDatetimeIndex,
Expand Down Expand Up @@ -197,7 +198,7 @@ def _get_freq(ax, series: "Series"):
return freq, ax_freq


def _use_dynamic_x(ax, data):
def _use_dynamic_x(ax, data: "FrameOrSeriesUnion") -> bool:
freq = _get_index_freq(data.index)
ax_freq = _get_ax_freq(ax)

Expand Down
13 changes: 12 additions & 1 deletion pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pandas.core.resample import DatetimeIndex
from pandas.tests.plotting.common import TestPlotBase

from pandas.tseries.offsets import DateOffset
from pandas.tseries.offsets import DateOffset, WeekOfMonth


@td.skip_if_no_mpl
Expand Down Expand Up @@ -325,6 +325,17 @@ def test_business_freq_convert(self):
idx = ax.get_lines()[0].get_xdata()
assert PeriodIndex(data=idx).freqstr == "M"

def test_freq_with_no_period_alias(self):
freq = WeekOfMonth()
bts = tm.makeTimeSeries(5).asfreq(freq)
_, ax = self.plt.subplots()
bts.plot(ax=ax)
assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].toordinal()
idx = ax.get_lines()[0].get_xdata()
msg = "freq not specified and cannot be inferred"
with pytest.raises(ValueError, match=msg):
PeriodIndex(data=idx)

def test_nonzero_base(self):
# GH2571
idx = date_range("2012-12-20", periods=24, freq="H") + timedelta(minutes=30)
Expand Down