Skip to content

TYP: all and any shape-typing#31170

Merged
charris merged 3 commits into
numpy:mainfrom
jorenham:typing/any-all
Apr 7, 2026
Merged

TYP: all and any shape-typing#31170
charris merged 3 commits into
numpy:mainfrom
jorenham:typing/any-all

Conversation

@jorenham
Copy link
Copy Markdown
Member

@jorenham jorenham commented Apr 6, 2026

np.any, np.all, and the corresponding ndarray methods will now return the same input shape when keepdims=True, and will no longer return Any in case axis is not None.

AI Disclosure

N/A

@github-actions

This comment has been minimized.

@jorenham
Copy link
Copy Markdown
Member Author

jorenham commented Apr 6, 2026

The new unused-ignore errors are good to see.

But there are also some other errors. I looked into them, and they don't seem to indicate a problem on our side.

  • pandas:
    • a call to np.all with axis: tuple[int, ...] is used as argument to __and__, but that __and__ does not accept NDArray[np.bool], even though that's what it could be at runtime
    • the other error correct, because np.bool and builtins.bool are indeed incompatible types, so that's a typing issue in pandas.
  • static-frame: all errors seem to be caused by incorrect callable annotations in static-frame itself.

@github-actions

This comment has been minimized.

@charris
Copy link
Copy Markdown
Member

charris commented Apr 7, 2026

Needs rebase.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/type_blocks.py:2454: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/join.py:101: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/index_hierarchy.py:2423: error: Argument "condition" to "dropna" of "IndexHierarchy" has incompatible type overloaded function; expected "Callable[[ndarray[Any, Any]], ndarray[Any, Any]]"  [arg-type]
+ static_frame/core/index_hierarchy.py:2796: error: Incompatible default for parameter "condition" (default has type overloaded function, parameter has type "Callable[[ndarray[Any, Any]], ndarray[Any, Any]]")  [assignment]
+ static_frame/core/index_hierarchy.py:2810: error: Incompatible default for parameter "condition" (default has type overloaded function, parameter has type "Callable[[ndarray[Any, Any]], ndarray[Any, Any]]")  [assignment]
+ static_frame/core/frame.py:4885: error: Incompatible default for parameter "condition" (default has type overloaded function, parameter has type "Callable[[ndarray[Any, Any]], ndarray[Any, Any]]")  [assignment]
+ static_frame/core/frame.py:4945: error: Incompatible default for parameter "condition" (default has type overloaded function, parameter has type "Callable[[ndarray[Any, Any]], ndarray[Any, Any]]")  [assignment]
+ static_frame/core/store_xlsx.py:487: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/store_xlsx.py:496: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/batch.py:1158: error: Incompatible default for parameter "condition" (default has type overloaded function, parameter has type "Callable[[ndarray[Any, Any]], builtins.bool]")  [assignment]
+ static_frame/core/batch.py:1187: error: Incompatible default for parameter "condition" (default has type overloaded function, parameter has type "Callable[[ndarray[Any, Any]], builtins.bool]")  [assignment]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/missing.py:262: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/io/formats/format.py:1249: error: No overload variant of "__rand__" of "ndarray" matches argument type "ExtensionArray"  [operator]
+ pandas/io/formats/format.py:1249: note: Possible overload variants:
+ pandas/io/formats/format.py:1249: note:     def __rand__(self, _SupportsArray[dtype[numpy.bool[builtins.bool]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]]]] | builtins.bool | _NestedSequence[builtins.bool], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
+ pandas/io/formats/format.py:1249: note:     def __rand__(self, _SupportsArray[dtype[numpy.bool[builtins.bool] | unsignedinteger[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | unsignedinteger[Any]]]] | builtins.bool | _NestedSequence[builtins.bool], /) -> ndarray[tuple[Any, ...], dtype[unsignedinteger[Any]]]
+ pandas/io/formats/format.py:1249: note:     def __rand__(self, _SupportsArray[dtype[numpy.bool[builtins.bool] | integer[Any]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | integer[Any]]]] | int | _NestedSequence[int], /) -> ndarray[tuple[Any, ...], dtype[signedinteger[Any]]]
+ pandas/io/formats/format.py:1249: note:     def __rand__(self, _SupportsArray[dtype[object_]] | _NestedSequence[_SupportsArray[dtype[object_]]], /) -> Any
+ pandas/io/formats/format.py:1249: note: Both left and right operands are unions
+ pandas/io/formats/format.py:1255: error: Incompatible types in assignment (expression has type "Any | numpy.bool[builtins.bool]", variable has type "builtins.bool | None")  [assignment]

@charris charris merged commit 1d6144c into numpy:main Apr 7, 2026
14 checks passed
@charris
Copy link
Copy Markdown
Member

charris commented Apr 7, 2026

Thanks Joren.

@jorenham jorenham deleted the typing/any-all branch April 7, 2026 15:46
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