Skip to content

TYP: Type MaskedArray.repeat, improve overloads for NDArray.repeat, generic.repeat, and np.repeat#28849

Merged
jorenham merged 4 commits into
numpy:mainfrom
MarcoGorelli:ma-repeat
Apr 29, 2025
Merged

TYP: Type MaskedArray.repeat, improve overloads for NDArray.repeat, generic.repeat, and np.repeat#28849
jorenham merged 4 commits into
numpy:mainfrom
MarcoGorelli:ma-repeat

Conversation

@MarcoGorelli

Copy link
Copy Markdown
Member

No description provided.

@MarcoGorelli MarcoGorelli marked this pull request as ready for review April 28, 2025 15:40
@jorenham jorenham added the component: numpy.ma masked arrays label Apr 28, 2025
@jorenham jorenham self-requested a review April 28, 2025 16:38
Comment thread numpy/ma/core.pyi Outdated
Comment thread numpy/ma/core.pyi Outdated
@MarcoGorelli MarcoGorelli marked this pull request as draft April 28, 2025 20:02
@MarcoGorelli MarcoGorelli changed the title TYP: Type np.ma.repeat and MaskedArray.repeat TYP: Type np.ma.repeat, improve overloads for NDArray.repeat, generic.repeat, and np.repeat Apr 29, 2025
@MarcoGorelli MarcoGorelli marked this pull request as ready for review April 29, 2025 10:00
@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/reshape/concat.py:936: error: Generator has incompatible item type "ndarray[tuple[int, ...], dtype[Any]]"; expected "ndarray[tuple[int], dtype[Any]]"  [misc]
+ pandas/core/reshape/concat.py:940: error: Argument 1 to "append" of "list" has incompatible type "ndarray[tuple[int, ...], dtype[Any]]"; expected "ndarray[tuple[int], dtype[Any]]"  [arg-type]

@MarcoGorelli MarcoGorelli changed the title TYP: Type np.ma.repeat, improve overloads for NDArray.repeat, generic.repeat, and np.repeat TYP: Type MaskedArray.repeat, improve overloads for NDArray.repeat, generic.repeat, and np.repeat Apr 29, 2025
@jorenham

Copy link
Copy Markdown
Member

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/reshape/concat.py:936: error: Generator has incompatible item type "ndarray[tuple[int, ...], dtype[Any]]"; expected "ndarray[tuple[int], dtype[Any]]"  [misc]
+ pandas/core/reshape/concat.py:940: error: Argument 1 to "append" of "list" has incompatible type "ndarray[tuple[int, ...], dtype[Any]]"; expected "ndarray[tuple[int], dtype[Any]]"  [arg-type]

relevant pandas code:
https://github.com/pandas-dev/pandas/blob/cf6de581e1c27f06107b5be9e7f2923d7bbc98a6/pandas/core/reshape/concat.py#L918-L940

@jorenham

Copy link
Copy Markdown
Member

The change to np.repeat will apparently cause new typing errors in pandas.

@mroeschke since you worked on pandas-dev/pandas#61265, perhaps you are willing to share your thoughts on this change?

@mroeschke

Copy link
Copy Markdown
Contributor

I'm fine to adapt to these typing changes in pandas (mostly by adding ignores or simple annotations until someone from the pandas community would like to improve the annotations internally)

@jorenham

Copy link
Copy Markdown
Member

I'm fine to adapt to these typing changes in pandas (mostly by adding ignores or simple annotations until someone from the pandas community would like to improve the annotations internally)

Good to hear, thanks!

@jorenham jorenham merged commit 9af251c into numpy:main Apr 29, 2025
@jorenham

Copy link
Copy Markdown
Member

Thanks Marco

MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request May 8, 2025
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.

3 participants