🌐 AI搜索 & 代理 主页
Skip to content

TYP: np.argmin overloads could be more precise #28641

@MarcoGorelli

Description

@MarcoGorelli

Describe the issue:

np.argmin preserves the type of out (if passed), but it could be more precise than that and be narrowed down to integer or boolean arrays

Same for np.ma.argmin. Opening this as a follow-up to #28638 (comment)

Reproduce the code example:

from typing import Any
import numpy as np
import numpy.typing as npt

arr = np.array([1,2,3])
out = np.empty(())
reveal_type(np.argmin(arr, out=out))

Error message:

/home/marcogorelli/numpy-dev/t.py:7:13 - information: Type of "np.argmin(arr, out=out)" is "ndarray[tuple[()], dtype[float64]]"

Python and NumPy Versions:

2.3.0.dev0+git20250403.ec1cfa6
3.12.9 | packaged by conda-forge | (main, Mar 4 2025, 22:48:41) [GCC 13.3.0]

Type-checker version and settings:

pyright 1.1.398
spin run pyright t.py

Additional typing packages.

No response

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