Uh oh!
There was an error while loading. Please reload this page.
TYP: sum and prod shape-typing and improved dtypes - #31160
Conversation
This comment has been minimized.
This comment has been minimized.
RE: mypy_primer
So to summarize, there are two action points for me:
|
Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code: jax (https://github.com/google/jax)
- jax/_src/pallas/pipelining/schedulers.py:412: error: Argument 3 to "check_async_done" has incompatible type "signedinteger[_64Bit]"; expected "int | Array" [arg-type]+ jax/_src/pallas/pipelining/schedulers.py:412: error: Argument 3 to "check_async_done" has incompatible type "signedinteger[_32Bit | _64Bit]"; expected "int | Array" [arg-type]
colour (https://github.com/colour-science/colour)
+ colour/phenomena/sky/wilkie2021.py:927: error: Argument "theta" to "SkyParameters_Wilkie2021" has incompatible type "ndarray[tuple[Any, ...], dtype[Any]]"; expected "float" [arg-type]+ colour/phenomena/sky/wilkie2021.py:928: error: Argument "gamma" to "SkyParameters_Wilkie2021" has incompatible type "ndarray[tuple[Any, ...], dtype[Any]]"; expected "float" [arg-type]+ colour/phenomena/sky/wilkie2021.py:929: error: Argument "shadow" to "SkyParameters_Wilkie2021" has incompatible type "ndarray[tuple[Any, ...], dtype[Any]]"; expected "float" [arg-type]+ colour/phenomena/sky/wilkie2021.py:930: error: Argument "zero" to "SkyParameters_Wilkie2021" has incompatible type "ndarray[tuple[Any, ...], dtype[Any]]"; expected "float" [arg-type]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/io/parsers/base_parser.py:516: error: Incompatible types in assignment (expression has type "signedinteger[_32Bit | _64Bit]", variable has type "int") [assignment]+ pandas/io/parsers/base_parser.py:518: error: Incompatible types in assignment (expression has type "signedinteger[_32Bit | _64Bit]", variable has type "int") [assignment]+ pandas/core/internals/blocks.py:1279: error: Argument 2 to "setitem_datetimelike_compat" has incompatible type "signedinteger[_32Bit | _64Bit]"; expected "int" [arg-type]+ pandas/core/indexes/base.py:5773: error: Argument 2 to "setitem_datetimelike_compat" has incompatible type "signedinteger[_32Bit | _64Bit]"; expected "int" [arg-type]+ pandas/core/resample.py:2623: error: Incompatible types in assignment (expression has type "signedinteger[_32Bit | _64Bit]", variable has type "int") [assignment]
optuna (https://github.com/optuna/optuna)
+ optuna/importance/_fanova/_tree.py:311: error: Incompatible return value type (got "ndarray[Any, Any]", expected "float") [return-value]
numpy-stl (https://github.com/WoLpH/numpy-stl)
+ stl/base.py:448: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, int], dtype[float64]]", variable has type "ndarray[tuple[int, int], dtype[floating[_32Bit]]]") [assignment] |
jorenham
commented
Apr 5, 2026
The remaining primer errors are, except for the The |
Uh oh!
There was an error while loading. Please reload this page.
charris
commented
Apr 6, 2026
Thanks Joren. |
This follows #31154, and uses a similar overload pattern as for
np[.ndarray].{mean,std,var}, butsumandproddiffer in that they don't upcastintegertofloat64, and instead upcastbool_toint_, so they require additional overloads.The
sumandprodcontracts are almost identical except fortimedelta64; which is acceptedsumbut not byprod.This also adds specialized overrides for the
sumandprodmethods of thenumber,bool, andtimedelta64(only forsum) scalar types, which might help in case you e.g..sum()onfloat64 | NDArray[float64]input, i.e. when you're not sure if you're summing a scalar or an array.AI Disclosure
N/A