Skip to content

TYP: fix output dtype of bincount with weights - #31911

Merged
charris merged 1 commit into
numpy:mainfrom
jorenham:typing/bincount-weights
Jul 8, 2026
Merged

charris merged 1 commit into
numpy:mainfrom
jorenham:typing/bincount-weights

Conversation

@jorenham

@jorenham jorenham commented Jul 8, 2026

Copy link
Copy Markdown
Member

If weights are passed to bincount, the returned dtype is float64, not intp:

>>> np.bincount(np.array([0, 1, 1, 2]), weights=np.array([.5, 1, 1.5, 2])).dtype
dtype('float64')
>>> np.bincount(np.array([0, 1, 1, 2]), weights=np.array([1, 2, 3, 4])).dtype
dtype('float64')

This fixes the stubs to match this runtime behavior


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

(more stub fixes incoming, btw)

@jorenham jorenham added 09 - Backport-Candidate PRs tagged should be backported 41 - Static typing labels Jul 8, 2026
@jorenham
jorenham force-pushed the typing/bincount-weights branch from 85ffa51 to fb8803d Compare July 8, 2026 09:57
@charris
charris merged commit b1aea2d into numpy:main Jul 8, 2026
13 checks passed
@charris

charris commented Jul 8, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

@jorenham
jorenham deleted the typing/bincount-weights branch July 8, 2026 12:38
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 8, 2026
jorenham added a commit that referenced this pull request Jul 8, 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