Skip to content

TYP: numpy allows a datetime array to be divided by another array #30173

@Dr-Irv

Description

@Dr-Irv

Describe the issue:

If a numpy array has a datetime type, and is divided by another array, typecheckers are not picking that up as wrong.

Reproduce the code example:

from typing import reveal_type
import numpy as np

s = np.array([np.datetime64(f"2025-10-{d:02d}") for d in (23, 24, 25)], np.datetime64)
t = np.array([1, 2, 3])
reveal_type(s)
reveal_type(t)
reveal_type(s.__truediv__(t))

s / t

Error message:

The type revealed of the division operation is `Any`

Python and NumPy Versions:

python 3.12
numpy 2.3.4

Type-checker version and settings:

pyright 1.1.407
mypy 1.18.2

Additional typing packages.

Note: This came up with pandas-stubs.

We think the solution is to add an overload that returns Never .

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions