Skip to content

TYP: r_/c_ shape-typing and improved dtypes - #32734

Merged
charris merged 2 commits into
numpy:mainfrom
jorenham:typing/r_/shape-typing
Sep 22, 2026
Merged

charris merged 2 commits into
numpy:mainfrom
jorenham:typing/r_/shape-typing

Conversation

@jorenham

Copy link
Copy Markdown
Member

The __getitem__ methods of np.r_ and np.c_ now support shape-typing and have overloads for builtin sequence array-likes. Before these were effectively fully untyped.


Pair programmed with AI.

@jorenham jorenham added this to the 2.6.0 Release milestone Sep 21, 2026
@jorenham
jorenham force-pushed the typing/r_/shape-typing branch from 629c72c to c33c316 Compare September 21, 2026 15:34
@github-actions

Copy link
Copy Markdown

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

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/groupby/groupby.py:1747: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[float64]]", variable has type "ndarray[tuple[int], dtype[signedinteger[_32Bit | _64Bit]]]")  [assignment]
+ pandas/core/groupby/generic.py:1225: error: Incompatible types in assignment (expression has type "ndarray[tuple[Any, ...], dtype[signedinteger[_32Bit | _64Bit]]] | None", variable has type "ndarray[Any, Any]")  [assignment]

@jorenham

Copy link
Copy Markdown
Member Author

RE: the new pandas mypy errors reported by mypy_primer:

  • groupby.py (src): a classic re-assignment with different type mypy error. Can be resolved by configuring mypy appropriately in Pandas. This is only now showing up because before this, the returned Any caused the error to be hidden.
  • generic.py (src): same story as above (also note the deliberately ignored other mypy error that's actually a problem).

@charris
charris merged commit a02c5a3 into numpy:main Sep 22, 2026
15 checks passed
@charris

charris commented Sep 22, 2026

Copy link
Copy Markdown
Member

Thanks Joren.

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