Skip to content

Commit 04243ef

Browse files
authored
Add type stubs for functions in matplotlib.dates (matplotlib#30385)
* Add type stubs for functions in matplotlib.dates * Make date typing tighter with overloads * Fix _dt64_to_ordinalf type * Remvoe old type alisas * Add argument defaults * Remove overload on datestr2num
1 parent f6f7d7a commit 04243ef

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

lib/matplotlib/dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def get_epoch():
309309

310310
def _dt64_to_ordinalf(d):
311311
"""
312-
Convert `numpy.datetime64` or an `numpy.ndarray` of those types to
312+
Convert a `numpy.ndarray` of np.datetime64 to
313313
Gregorian date as UTC float relative to the epoch (see `.get_epoch`).
314314
Roundoff is float64 precision. Practically: microseconds for dates
315315
between 290301 BC, 294241 AD, milliseconds for larger dates

lib/matplotlib/dates.pyi

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import datetime
2+
from collections.abc import Sequence
3+
from typing import overload
4+
5+
import numpy as np
6+
import numpy.typing as npt
7+
8+
TZ = str | datetime.tzinfo
9+
10+
def _get_tzinfo(tz: TZ | None=None) -> datetime.tzinfo: ...
11+
def _reset_epoch_test_example() -> None: ...
12+
def set_epoch(epoch: str) -> None: ...
13+
def get_epoch() -> str: ...
14+
def _dt64_to_ordinalf(d: npt.NDArray[np.datetime64]) -> npt.NDArray[np.floating]: ...
15+
def _from_ordinalf(x: float, tz: TZ | None=None) -> datetime.datetime: ...
16+
# Ideally str | Sequence[str] would get an override, but because a str is a valid Sequence[str],
17+
# it's not possible to distinguish between them in the type system
18+
# See https://github.com/python/typing/issues/256
19+
def datestr2num(d: str | Sequence[str], default: datetime.datetime | None=None) -> float | npt.NDArray[np.floating]: ...
20+
21+
@overload
22+
def date2num(d: datetime.datetime | np.datetime64) -> float: ...
23+
@overload
24+
def date2num(d: Sequence[datetime.datetime] | Sequence[np.datetime64]) -> npt.NDArray[np.floating]: ...
25+
26+
@overload
27+
def num2date(x: float, tz: TZ | None=None) -> datetime.datetime: ...
28+
@overload
29+
def num2date(x: Sequence[float], tz: TZ | None=None) -> list[datetime.datetime]: ...
30+
31+
@overload
32+
def num2timedelta(x: float) -> datetime.timedelta: ...
33+
@overload
34+
def num2timedelta(x: Sequence[float]) -> list[datetime.timedelta]: ...
35+
36+
def drange(dstart: datetime.datetime, dend: datetime.datetime, delta: datetime.timedelta) -> npt.NDArray[np.floating]: ...
37+
def _wrap_in_tex(text: str) -> str: ...

0 commit comments

Comments
 (0)