Skip to content

Commit 15b1f7c

Browse files
committed
TYP: axis, freq in plotting code
1 parent 0b66b92 commit 15b1f7c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pandas/plotting/_matplotlib/converter.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,28 @@ def __call__(self, x, pos: int | None = 0) -> str:
224224

225225
class PeriodConverter(mdates.DateConverter):
226226
@staticmethod
227-
def convert(values, units, axis):
227+
def convert(values, unit, axis: Axis):
228+
# Reached via e.g. `ax.set_xlim`
229+
230+
# In tests as of 2025-09-24, unit is always None except for 3 tests
231+
# that directly call this with unit="";
232+
# axis is always specifically a matplotlib.axis.XAxis
233+
228234
if not hasattr(axis, "freq"):
229235
raise TypeError("Axis must have `freq` set to convert to Periods")
230-
return PeriodConverter.convert_from_freq(values, axis.freq)
236+
freq = to_offset(axis.freq, is_period=True)
237+
return PeriodConverter.convert_from_freq(values, freq)
231238

232239
@staticmethod
233-
def convert_from_freq(values, freq):
240+
def convert_from_freq(values, freq: BaseOffset):
234241
if is_nested_list_like(values):
235242
values = [PeriodConverter._convert_1d(v, freq) for v in values]
236243
else:
237244
values = PeriodConverter._convert_1d(values, freq)
238245
return values
239246

240247
@staticmethod
241-
def _convert_1d(values, freq):
248+
def _convert_1d(values, freq: BaseOffset):
242249
valid_types = (str, datetime, Period, pydt.date, np.datetime64)
243250
with warnings.catch_warnings():
244251
warnings.filterwarnings(
@@ -266,7 +273,7 @@ def _convert_1d(values, freq):
266273
return values
267274

268275

269-
def _get_datevalue(date, freq):
276+
def _get_datevalue(date, freq: BaseOffset):
270277
if isinstance(date, Period):
271278
return date.asfreq(freq).ordinal
272279
elif isinstance(date, (str, datetime, pydt.date, np.datetime64)):
@@ -281,7 +288,13 @@ def _get_datevalue(date, freq):
281288
# Datetime Conversion
282289
class DatetimeConverter(mdates.DateConverter):
283290
@staticmethod
284-
def convert(values, unit, axis):
291+
def convert(values, unit, axis: Axis):
292+
# Reached via e.g. `ax.set_xlim`
293+
294+
# In tests as of 2025-09-24, unit is always None except for 3 tests
295+
# that directly call this with unit="";
296+
# axis is always specifically a matplotlib.axis.XAxis
297+
285298
# values might be a 1-d array, or a list-like of arrays.
286299
if is_nested_list_like(values):
287300
values = [DatetimeConverter._convert_1d(v, unit, axis) for v in values]

0 commit comments

Comments
 (0)