Skip to content

TST, TYP: _use_dynamic_x #34487

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
Show file tree
Hide file tree
Changes from all 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 import Period, to_offset
from pandas._libs.tslibs.frequencies import FreqGroup, base_and_stride, get_freq_code
from pandas._typing import FrameOrSeriesUnion

from pandas.core.dtypes.generic import (
ABCDatetimeIndex,
Expand Down Expand Up @@ -192,7 +193,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
14 changes: 13 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,18 @@ 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):
# GH34487
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