ENH: Add dtype-support to 3 generic/ndarray methods #19140
Merged
charris merged 2 commits intonumpy:mainfrom Jun 6, 2021
Merged
ENH: Add dtype-support to 3 generic/ndarray methods #19140charris merged 2 commits intonumpy:mainfrom
generic/ndarray methods #19140charris merged 2 commits intonumpy:mainfrom
Conversation
* `astype` * `getfield` * `view`
BvB93
commented
May 31, 2021
Comment on lines
+1864
to
+1881
| @overload | ||
| def astype( | ||
| self, | ||
| dtype: _DTypeLike[_ScalarType], | ||
| order: _OrderKACF = ..., | ||
| casting: _Casting = ..., | ||
| subok: bool = ..., | ||
| copy: bool = ..., | ||
| ) -> NDArray[_ScalarType]: ... | ||
| @overload | ||
| def astype( | ||
| self, | ||
| dtype: DTypeLike, | ||
| order: _OrderKACF = ..., | ||
| casting: _Casting = ..., | ||
| subok: bool = ..., | ||
| copy: bool = ..., | ||
| ) -> NDArray[Any]: ... |
Member
Author
There was a problem hiding this comment.
dtype-support is, for now, limited to dtype-likes that can be parametrized w.r.t. np.generic.
For all others the dtype will be set to Any.
Comment on lines
+1891
to
+1896
| @overload | ||
| def view( | ||
| self, | ||
| dtype: DTypeLike, | ||
| type: Type[_NdArraySubClass], | ||
| ) -> _NdArraySubClass: ... |
Member
Author
There was a problem hiding this comment.
Unfortunately we can't express the return of an ndarray-subclass with a specific dtype
(e.g. ndarray[float64] -> matrix[int64]). This would require higher-kinded TypeVars, which we don't have.
Member
|
Thanks Bas. |
This was referenced Aug 24, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds dtype-support to the annotations of the following 3
generic/ndarraymethods:astypeviewgetfield