@@ -224,22 +224,29 @@ def __call__(self, x, pos: int | None = 0) -> str:
224224
225225class 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 ):
242- valid_types = (str , datetime , Period , pydt .date , pydt . time , np .datetime64 )
248+ def _convert_1d (values , freq : BaseOffset ):
249+ valid_types = (str , datetime , Period , pydt .date , np .datetime64 )
243250 with warnings .catch_warnings ():
244251 warnings .filterwarnings (
245252 "ignore" , "Period with BDay freq is deprecated" , category = FutureWarning
@@ -252,30 +259,26 @@ def _convert_1d(values, freq):
252259 or is_integer (values )
253260 or is_float (values )
254261 ):
255- return get_datevalue (values , freq )
262+ return _get_datevalue (values , freq )
256263 elif isinstance (values , PeriodIndex ):
257264 return values .asfreq (freq ).asi8
258265 elif isinstance (values , Index ):
259- return values .map (lambda x : get_datevalue (x , freq ))
266+ return values .map (lambda x : _get_datevalue (x , freq ))
260267 elif lib .infer_dtype (values , skipna = False ) == "period" :
261268 # https://github.com/pandas-dev/pandas/issues/24304
262269 # convert ndarray[period] -> PeriodIndex
263270 return PeriodIndex (values , freq = freq ).asi8
264- elif isinstance (values , (list , tuple , np .ndarray , Index )):
265- return [get_datevalue (x , freq ) for x in values ]
271+ elif isinstance (values , (list , tuple , np .ndarray )):
272+ return [_get_datevalue (x , freq ) for x in values ]
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
272- elif isinstance (date , (str , datetime , pydt .date , pydt . time , np .datetime64 )):
279+ elif isinstance (date , (str , datetime , pydt .date , np .datetime64 )):
273280 return Period (date , freq ).ordinal
274- elif (
275- is_integer (date )
276- or is_float (date )
277- or (isinstance (date , (np .ndarray , Index )) and (date .size == 1 ))
278- ):
281+ elif is_integer (date ) or is_float (date ):
279282 return date
280283 elif date is None :
281284 return None
@@ -285,7 +288,13 @@ def get_datevalue(date, freq):
285288# Datetime Conversion
286289class DatetimeConverter (mdates .DateConverter ):
287290 @staticmethod
288- 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+
289298 # values might be a 1-d array, or a list-like of arrays.
290299 if is_nested_list_like (values ):
291300 values = [DatetimeConverter ._convert_1d (v , unit , axis ) for v in values ]
0 commit comments