Skip to content

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

Merged
merged 1 commit into from
Feb 12, 2017

Conversation

behrmann
Copy link
Contributor

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

Copy link
Member

@shoyer shoyer left a 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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@@ -268,6 +268,7 @@ def iscomplexobj(x):
"""
try:
dtype = x.dtype
getattr(dtype, "type")
Copy link
Member

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

@behrmann
Copy link
Contributor Author

I have just force pushed a version reusing type_ and adding a test.

Copy link
Member

@shoyer shoyer left a 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

@behrmann
Copy link
Contributor Author

Thanks!

try:
return issubclass(dtype.type, _nx.complexfloating)
return issubclass(type_, _nx.complexfloating)
Copy link
Contributor

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

Copy link
Member

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
@behrmann
Copy link
Contributor Author

behrmann commented Feb 10, 2017 via email

@shoyer shoyer merged commit bcae38a into numpy:master Feb 12, 2017
@shoyer
Copy link
Member

shoyer commented Feb 12, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants