Skip to content

TYP: arange: accept datetime strings#30631

Merged
charris merged 1 commit intonumpy:mainfrom
jorenham:typing/fix-30628
Jan 10, 2026
Merged

TYP: arange: accept datetime strings#30631
charris merged 1 commit intonumpy:mainfrom
jorenham:typing/fix-30628

Conversation

@jorenham
Copy link
Copy Markdown
Member

fixes #30628

@jorenham jorenham added 09 - Backport-Candidate PRs tagged should be backported 41 - Static typing labels Jan 10, 2026
@jorenham jorenham added this to the 2.4.2 release milestone Jan 10, 2026
@github-actions
Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_plot.py:1167: note:     def arange(str, /, stop: str, step: int | timedelta64[Any] | integer[Any] | numpy.bool[builtins.bool] | None = ..., *, dtype: type[datetime64[Any]] | dtype[datetime64[Any]] | _HasDType[dtype[datetime64[Any]]] | _HasNumPyDType[dtype[datetime64[Any]]] | Literal['datetime64', 'M', 'M8', '|M8', '=M8', '<M8', '>M8', 'datetime64[Y]', 'M8[Y]', '|M8[Y]', '=M8[Y]', '<M8[Y]', '>M8[Y]', 'datetime64[M]', 'M8[M]', '|M8[M]', '=M8[M]', '<M8[M]', '>M8[M]', 'datetime64[W]', 'M8[W]', '|M8[W]', '=M8[W]', '<M8[W]', '>M8[W]', 'datetime64[D]', 'M8[D]', '|M8[D]', '=M8[D]', '<M8[D]', '>M8[D]', 'datetime64[h]', 'M8[h]', '|M8[h]', '=M8[h]', '<M8[h]', '>M8[h]', 'datetime64[m]', 'M8[m]', '|M8[m]', '=M8[m]', '<M8[m]', '>M8[m]', 'datetime64[s]', 'M8[s]', '|M8[s]', '=M8[s]', '<M8[s]', '>M8[s]', 'datetime64[ms]', 'M8[ms]', '|M8[ms]', '=M8[ms]', '<M8[ms]', '>M8[ms]', 'datetime64[us]', 'M8[us]', '|M8[us]', '=M8[us]', '<M8[us]', '>M8[us]', 'datetime64[μs]', 'M8[μs]', '|M8[μs]', '=M8[μs]', '<M8[μs]', '>M8[μs]', 'datetime64[ns]', 'M8[ns]', '|M8[ns]', '=M8[ns]', '<M8[ns]', '>M8[ns]', 'datetime64[ps]', 'M8[ps]', '|M8[ps]', '=M8[ps]', '<M8[ps]', '>M8[ps]', 'datetime64[fs]', 'M8[fs]', '|M8[fs]', '=M8[fs]', '<M8[fs]', '>M8[fs]', 'datetime64[as]', 'M8[as]', '|M8[as]', '=M8[as]', '<M8[as]', '>M8[as]'], device: Literal['cpu'] | None = ..., like: _SupportsArrayFunc | None = ...) -> ndarray[tuple[int], dtype[datetime64[Any]]]
- xarray/tests/test_plot.py:1167: note:     def arange(integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float, /, stop: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | None = ..., step: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | None = ..., *, dtype: type | str | dtype[Any] | _HasDType[dtype[Any]] | _HasNumPyDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | None = ..., device: Literal['cpu'] | None = ..., like: _SupportsArrayFunc | None = ...) -> ndarray[tuple[int], dtype[Any]]
+ xarray/tests/test_plot.py:1167: note:     def arange(integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | str, /, stop: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | str | None = ..., step: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | None = ..., *, dtype: type | str | dtype[Any] | _HasDType[dtype[Any]] | _HasNumPyDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | None = ..., device: Literal['cpu'] | None = ..., like: _SupportsArrayFunc | None = ...) -> ndarray[tuple[int], dtype[Any]]
+ xarray/tests/test_plot.py:1168: note:     def arange(str, /, stop: str, step: int | timedelta64[Any] | integer[Any] | numpy.bool[builtins.bool] | None = ..., *, dtype: type[datetime64[Any]] | dtype[datetime64[Any]] | _HasDType[dtype[datetime64[Any]]] | _HasNumPyDType[dtype[datetime64[Any]]] | Literal['datetime64', 'M', 'M8', '|M8', '=M8', '<M8', '>M8', 'datetime64[Y]', 'M8[Y]', '|M8[Y]', '=M8[Y]', '<M8[Y]', '>M8[Y]', 'datetime64[M]', 'M8[M]', '|M8[M]', '=M8[M]', '<M8[M]', '>M8[M]', 'datetime64[W]', 'M8[W]', '|M8[W]', '=M8[W]', '<M8[W]', '>M8[W]', 'datetime64[D]', 'M8[D]', '|M8[D]', '=M8[D]', '<M8[D]', '>M8[D]', 'datetime64[h]', 'M8[h]', '|M8[h]', '=M8[h]', '<M8[h]', '>M8[h]', 'datetime64[m]', 'M8[m]', '|M8[m]', '=M8[m]', '<M8[m]', '>M8[m]', 'datetime64[s]', 'M8[s]', '|M8[s]', '=M8[s]', '<M8[s]', '>M8[s]', 'datetime64[ms]', 'M8[ms]', '|M8[ms]', '=M8[ms]', '<M8[ms]', '>M8[ms]', 'datetime64[us]', 'M8[us]', '|M8[us]', '=M8[us]', '<M8[us]', '>M8[us]', 'datetime64[μs]', 'M8[μs]', '|M8[μs]', '=M8[μs]', '<M8[μs]', '>M8[μs]', 'datetime64[ns]', 'M8[ns]', '|M8[ns]', '=M8[ns]', '<M8[ns]', '>M8[ns]', 'datetime64[ps]', 'M8[ps]', '|M8[ps]', '=M8[ps]', '<M8[ps]', '>M8[ps]', 'datetime64[fs]', 'M8[fs]', '|M8[fs]', '=M8[fs]', '<M8[fs]', '>M8[fs]', 'datetime64[as]', 'M8[as]', '|M8[as]', '=M8[as]', '<M8[as]', '>M8[as]'], device: Literal['cpu'] | None = ..., like: _SupportsArrayFunc | None = ...) -> ndarray[tuple[int], dtype[datetime64[Any]]]
- xarray/tests/test_plot.py:1168: note:     def arange(integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float, /, stop: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | None = ..., step: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | None = ..., *, dtype: type | str | dtype[Any] | _HasDType[dtype[Any]] | _HasNumPyDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | None = ..., device: Literal['cpu'] | None = ..., like: _SupportsArrayFunc | None = ...) -> ndarray[tuple[int], dtype[Any]]
+ xarray/tests/test_plot.py:1168: note:     def arange(integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | str, /, stop: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | str | None = ..., step: integer[Any] | floating[Any] | datetime64[Any] | timedelta64[Any] | float | None = ..., *, dtype: type | str | dtype[Any] | _HasDType[dtype[Any]] | _HasNumPyDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | None = ..., device: Literal['cpu'] | None = ..., like: _SupportsArrayFunc | None = ...) -> ndarray[tuple[int], dtype[Any]]

@charris charris merged commit c9c0e2a into numpy:main Jan 10, 2026
14 checks passed
@charris
Copy link
Copy Markdown
Member

charris commented Jan 10, 2026

Thanks Joren.

@jorenham jorenham deleted the typing/fix-30628 branch January 11, 2026 00:11
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TYP: np.arrange with datetime str

2 participants