-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
BUG: Make iscomplexobj compatible with custom dtypes again #8602
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix also needs a test.
@@ -268,6 +268,7 @@ def iscomplexobj(x): | |||
""" | |||
try: | |||
dtype = x.dtype |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about instead making this type_ = x.dtype.type
and reusing type_
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
numpy/lib/type_check.py
Outdated
@@ -268,6 +268,7 @@ def iscomplexobj(x): | |||
""" | |||
try: | |||
dtype = x.dtype | |||
getattr(dtype, "type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no different from writing dtype.type
df41641
to
e3a9417
Compare
I have just force pushed a version reusing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, will merge after tests pass
Thanks! |
numpy/lib/type_check.py
Outdated
try: | ||
return issubclass(dtype.type, _nx.complexfloating) | ||
return issubclass(type_, _nx.complexfloating) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer needs to be inside a try/except
to catch AttributeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, good catch!
This change makes iscomplexobj compatible with custom array types using custom dtypes, that are not fully compatible to Numpys dtypes, which can nevertheless be coerced to a numpy array with asarray again, as has been the behaviour before PR numpy#7936. Fixes numpy#8601
e3a9417
to
bb1c471
Compare
Yes, of course. I just pushed a fixed version.
|
Thanks! |
This change makes iscomplexobj compatible with custom array types
using custom dtypes, that are not fully compatible to Numpys dtypes,
which can nevertheless be coerced to a numpy array with asarray
again, as has been the behaviour before PR #7936.
Fixes #8601