| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| True | ||
|
|
||
| """ | ||
| x = asarray(x) |
There was a problem hiding this comment.
This isn't really right:
I am actually not sure if astype should coerce from to an array at all? If this does a forced cast, then astype becomes asarray().
Sorry, something went wrong.
There was a problem hiding this comment.
I also wonder if any coercion should be allowed here and I would agree if it shouldn't.
Then e.g. np.astype([1,2,3], np.float64) just wouldn't be supported.
Sorry, something went wrong.
There was a problem hiding this comment.
I think I agree about no coercion here. Instead, it seems to me like this should verify that the input is already an array.
That would leave the question of how exactly to do that. The dispatcher for __array_function__ was already added, so I think it should work to check with isinstance(x, np.ndarray) (allows subclasses, but not duck arrays - those should be using __array_function__).
And, if we do that, what's the right exception type? I'd think TypeError?
Sorry, something went wrong.
There was a problem hiding this comment.
I second TypeError. Its documentation says:
Raised when an operation or function is applied to an object of inappropriate type.
Sorry, something went wrong.
|
|
||
| Parameters | ||
| ---------- | ||
| x : array_like |
There was a problem hiding this comment.
| x : array_like | |
| x : `ndarray` |
Maybe also a note that array-likes are explicitly not supported here?
Sorry, something went wrong.
There was a problem hiding this comment.
Right, I updated it to x : ndarray to follow existing docs in other functions.
I also added the note.
Sorry, something went wrong.
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
There was a problem hiding this comment.
Uh, I noticed I misspelled PR number - fix is in #25054.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Hi @rgommers @ngoldbaum,
This PR adds np.astype for Array API compatibility (https://data-apis.org/array-api/latest/API_specification/generated/array_api.astype.html).
It adheres to Array API and uses default values for ndarray.astype arguments outside of the standard.
Tracking issue: #25076