Add overloads for DataArray.argmin and DataArray.argmax on dim parameter#11233
Add overloads for DataArray.argmin and DataArray.argmax on dim parameter#11233SurfyPenguin wants to merge 4 commits intopydata:mainfrom
Conversation
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
8c91f37 to
471352b
Compare
- Move `# type: ignore[overload-overlap]` to the @overload decorator - Add whats-new entry
471352b to
f950225
Compare
|
Closing this PR for now. |
headtr1ck
left a comment
There was a problem hiding this comment.
This approach is actually correct. The ignore is important and it will work exactly as intended.
|
@headtr1ck , thanks for the clarification. I was not sure if |
|
Yes it's correct. Mypy correctly complains because technically it is overlapping because str is an IT table of hashable. But if you ignore this, it will correctly infer that str will return Self while e.g. a list returns something else (it will start looking through the overloads by their order and pick the first match). |
What this does
Adds
@overloaddecorators toDataArray.argminandDataArray.argmaxso type checkers can narrow the return type based on thedimargument.dim: str->Selfdim: Collection[Hashable] | EllipsisType | None = None->dict[Hashable, Self]Additional info
While testing, I noticed this
FutureWarning:The overload reflects the intended behavior i.e.
dim=Noneis typed to returndict[Hashable, Self]rather thanSelf.whats-new.rstapi.rst