Skip to content

Commit 157cb20

Browse files
authored
TST, TYP: _use_dynamic_x (#34487)
1 parent 4a6ba1a commit 157cb20

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pandas/plotting/_matplotlib/timeseries.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from pandas._libs.tslibs import Period, to_offset
99
from pandas._libs.tslibs.frequencies import FreqGroup, base_and_stride, get_freq_code
10+
from pandas._typing import FrameOrSeriesUnion
1011

1112
from pandas.core.dtypes.generic import (
1213
ABCDatetimeIndex,
@@ -192,7 +193,7 @@ def _get_freq(ax, series: "Series"):
192193
return freq, ax_freq
193194

194195

195-
def _use_dynamic_x(ax, data):
196+
def _use_dynamic_x(ax, data: "FrameOrSeriesUnion") -> bool:
196197
freq = _get_index_freq(data.index)
197198
ax_freq = _get_ax_freq(ax)
198199

pandas/tests/plotting/test_datetimelike.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from pandas.core.resample import DatetimeIndex
1717
from pandas.tests.plotting.common import TestPlotBase
1818

19-
from pandas.tseries.offsets import DateOffset
19+
from pandas.tseries.offsets import DateOffset, WeekOfMonth
2020

2121

2222
@td.skip_if_no_mpl
@@ -325,6 +325,18 @@ def test_business_freq_convert(self):
325325
idx = ax.get_lines()[0].get_xdata()
326326
assert PeriodIndex(data=idx).freqstr == "M"
327327

328+
def test_freq_with_no_period_alias(self):
329+
# GH34487
330+
freq = WeekOfMonth()
331+
bts = tm.makeTimeSeries(5).asfreq(freq)
332+
_, ax = self.plt.subplots()
333+
bts.plot(ax=ax)
334+
assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].toordinal()
335+
idx = ax.get_lines()[0].get_xdata()
336+
msg = "freq not specified and cannot be inferred"
337+
with pytest.raises(ValueError, match=msg):
338+
PeriodIndex(data=idx)
339+
328340
def test_nonzero_base(self):
329341
# GH2571
330342
idx = date_range("2012-12-20", periods=24, freq="H") + timedelta(minutes=30)

0 commit comments

Comments
 (0)