-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: np.<ufunc>(np.ndarray) should raise TypeError #8877
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The fix for the last case at least is the thing where we need to stop auto-coercing unrecognized objects into |
Second half of this issue is fixed in #12700. First half isn't really a ufunc problem at all, and comes from: >>> np.array(np.ndarray)
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
np.array(np.ndarray)
ValueError: invalid __array_struct__ This happens because This would be fixed by having Do we think we can get away with changing that? |
Seems sensible to be consistent with how python does it. |
This was previously allowed for nested cases, i.e.: np.array([np.int64]) but not for the scalar case: np.array(np.int64) The solution is to align these two cases by always interpreting these as not being array-likes (instead of invalid array-likes) if the passed in object is a `type` object and the special attribute has a `__get__` attribute (and is thus probable a property or method). The (arguably better) alterative to this is to move the special attribute lookup to be on the type instead of the instance (which is what python does). This will definitely require some adjustments in our tests to use properties, but is probably fine with respect to most actual code. (The tests more commonly use this to quickly set up an array-like, while it is a fairly strange pattern for typical code.) Address parts of numpygh-16939 Closes numpygh-8877
Nice to see this resolved, thanks all! |
As noted by @charris in charris#5 (comment)
Should really both be TypeError.
Similarly, the following is arguably less than useful:
The text was updated successfully, but these errors were encountered: