Skip to content

Add type stubs for functions in matplotlib.dates #30385

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def get_epoch():

def _dt64_to_ordinalf(d):
"""
Convert `numpy.datetime64` or an `numpy.ndarray` of those types to
Convert a `numpy.ndarray` of np.datetime64 to
Gregorian date as UTC float relative to the epoch (see `.get_epoch`).
Roundoff is float64 precision. Practically: microseconds for dates
between 290301 BC, 294241 AD, milliseconds for larger dates
Expand Down
37 changes: 37 additions & 0 deletions lib/matplotlib/dates.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import datetime
from collections.abc import Sequence
from typing import overload

import numpy as np
import numpy.typing as npt

TZ = str | datetime.tzinfo

def _get_tzinfo(tz: TZ | None=None) -> datetime.tzinfo: ...
def _reset_epoch_test_example() -> None: ...
def set_epoch(epoch: str) -> None: ...
def get_epoch() -> str: ...
def _dt64_to_ordinalf(d: npt.NDArray[np.datetime64]) -> npt.NDArray[np.floating]: ...
def _from_ordinalf(x: float, tz: TZ | None=None) -> datetime.datetime: ...
# Ideally str | Sequence[str] would get an override, but because a str is a valid Sequence[str],
# it's not possible to distinguish between them in the type system
# See https://github.com/python/typing/issues/256
def datestr2num(d: str | Sequence[str], default: datetime.datetime | None=None) -> float | npt.NDArray[np.floating]: ...

@overload
def date2num(d: datetime.datetime | np.datetime64) -> float: ...
@overload
def date2num(d: Sequence[datetime.datetime] | Sequence[np.datetime64]) -> npt.NDArray[np.floating]: ...

@overload
def num2date(x: float, tz: TZ | None=None) -> datetime.datetime: ...
@overload
def num2date(x: Sequence[float], tz: TZ | None=None) -> list[datetime.datetime]: ...

@overload
def num2timedelta(x: float) -> datetime.timedelta: ...
@overload
def num2timedelta(x: Sequence[float]) -> list[datetime.timedelta]: ...

def drange(dstart: datetime.datetime, dend: datetime.datetime, delta: datetime.timedelta) -> npt.NDArray[np.floating]: ...
def _wrap_in_tex(text: str) -> str: ...
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy