Handle Python scalars consistently in np.astype#31365
Conversation
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
|
Not sure we should do this, since this function really exists only for the Array API, I would say, so I am not sure there is a reason to broaden it up beyond such use. |
but still, it may be an issue? |
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
|
To me it isn't an issue until someone asks from it from a usability perspective outside of the original context. But if other maintainers prefer to do coerction to array here because NumPy usually does, sure... |
That makes sense, and i also don't think anyone would often use this outside of what it is intended for. (raise TypeError( |
I agree. In the stubs it's even stricter currently, because it only accepts Lines 1349 to 1366 in 5cba3b4
Sounds good to me |
So, should I create a new branch/PR, where the code will return attribute error for python-native numbers, or should I make changes on this one? |
Whatever you prefer |
|
ok, i will create a new branch with PR |
PR summary
First time committer introduction
I use numpy as a machine learner, and data-analytic. I also use it for a lot of other tasks, but primarily for ML.
I was interested in reviewing the code of numpy, and how it works, and i saw a bug in astype.
So, the issue i found was in the astype function. This PR update 'np.astype':, so python scalar inputs are also handled, instead of ending with error 'AttributeError'
So, as python integers do not have a .astype attribute, in my edits, if the integer is scalar, it is converted by the np.asarray , which does not raise an issue, and makes the python-native scalars work fine
AI Disclosure
No AI tools used