Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TYP: Adjust type hint of Norm.__call__ to return masked array#26434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 2 commits intomatplotlib:mainfromksunden:norm_masked_array
Aug 3, 2023

Conversation

ksunden
Copy link
Member

PR summary

xrefpydata/xarray#8030

We were perhaps overly permissive in the return type, I'm pretty sure we always return Masked Array, so may as well say so, so that downstream can rely on that (which they already are, to be clear...)

PR checklist

xrefpydata/xarray#8030We were perhaps overly permissive in the return type, I'm pretty sure we always return Masked Array, so may as well say so, so that downstream can rely on that (which they already are, to be clear...)
@QuLogic
Copy link
Member

You can also pass a scalar in and get a scalar out; should weoverload that?

@ksunden
Copy link
MemberAuthor

Hmmmm... right you are... that ... complicates things as "scalar" is not a very easy thing to type hint even those from "ArrayLike" are actually insufficient... (and we do want to accept the non-scalar array likes (not just arrays...)

perhaps

@overloaddef__call__(self,value:np.ndarray,clip:bool|None= ...)->np.ma.MaskedArray: ...@overloaddef__call__(self,value:ArrayLike,clip:bool|None= ...)->ArrayLike: ...

It's a little funky because the signatures are overlapping (whichcan be a problem to mypy... at least xarray is having a problem along those lines, but I think we may be saved by the return types being compatible, just one is more restricted...)

This seems to help with xarray without causing us problems.

Lists and other non-ndarray array likes (including scalars, to the extent that scalars are supported by type hints at all) will just not get the type narrowing that the output is a masked array, but those that care can easily donp.asarray or similar to get that type specifically.

@tacaswelltacaswell added this to thev3.8.0 milestoneAug 2, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

3 participants
@ksunden@QuLogic@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp