Skip to content

Commit 6ba5b6b

Browse files
committed
add test case which hits uncovered line
1 parent 3d190aa commit 6ba5b6b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/plotting/_matplotlib/timeseries.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ def _use_dynamic_x(ax, data: "FrameOrSeriesUnion") -> bool:
205205

206206
freq = get_period_alias(freq)
207207

208+
if freq is None:
209+
return False
210+
208211
# FIXME: hack this for 0.10.1, creating more technical debt...sigh
209212
if isinstance(data.index, ABCDatetimeIndex):
210213
base = get_freq_code(freq)[0]

pandas/tests/plotting/test_datetimelike.py

Lines changed: 12 additions & 1 deletion
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,17 @@ 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+
freq = WeekOfMonth()
330+
bts = tm.makeTimeSeries(5).asfreq(freq)
331+
_, ax = self.plt.subplots()
332+
bts.plot(ax=ax)
333+
assert ax.get_lines()[0].get_xydata()[0, 0] == bts.index[0].toordinal()
334+
idx = ax.get_lines()[0].get_xdata()
335+
msg = "freq not specified and cannot be inferred"
336+
with pytest.raises(ValueError, match=msg):
337+
PeriodIndex(data=idx)
338+
328339
def test_nonzero_base(self):
329340
# GH2571
330341
idx = date_range("2012-12-20", periods=24, freq="H") + timedelta(minutes=30)

0 commit comments

Comments
 (0)