Skip to content

TYP: fix std/var output type for complex input - #31880

Merged
charris merged 2 commits into
numpy:mainfrom
jorenham:typing/complex-var-std
Jul 6, 2026
Merged

charris merged 2 commits into
numpy:mainfrom
jorenham:typing/complex-var-std

Conversation

@jorenham

@jorenham jorenham commented Jul 6, 2026

Copy link
Copy Markdown
Member

The np.std/np.var functions and ndarray.std/ndarray.var methods incorrectly returned complex dtypes for complex input. Because at runtime that would result in real output:

In [1]: c = np.array([1j, 1])

In [2]: np.std(c)
Out[2]: np.float64(0.7071067811865476)

In [3]: c.std()
Out[3]: np.float64(0.7071067811865476)

Miraculously, the fix didn't require adding new overloads this time. It even got rid of two!


Fully written by me (a human, I think); bug found by Claude Fable 5 (high) (here's the full audit for those interested).

@jorenham jorenham added 09 - Backport-Candidate PRs tagged should be backported 41 - Static typing labels Jul 6, 2026
@charris
charris merged commit ccd61c9 into numpy:main Jul 6, 2026
14 checks passed
@charris

charris commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

@jorenham
jorenham deleted the typing/complex-var-std branch July 6, 2026 21:28
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 6, 2026
MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request Jul 7, 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.

2 participants