Skip to content
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

DOC: docs for issubdtype doesn't explain why complex64 is not a subdtype of complex or complex_ #20259

Open
david-cortes opened this issue Oct 31, 2021 · 6 comments

Comments

@david-cortes
Copy link
Contributor

david-cortes commented Oct 31, 2021

Describe the issue:

Calling issubdtype on a complex64 does not produce the correct output.

Reproduce the code example:

import numpy as np
np.issubdtype(np.array([], dtype="F").dtype, complex)
np.issubdtype(np.array([], dtype="F").dtype, np.complex_)
False
False

Error message:

No response

NumPy/Python version information:

1.21 and current master (1046087)

@eric-wieser
Copy link
Member

Are you looking for np.issubdtype(np.array([], dtype="F").dtype, np.complexfloating)?

@eric-wieser
Copy link
Member

eric-wieser commented Oct 31, 2021

If you pass a non-numpy type into np.issubtype, it will just call np.dtype on it, and np.dtype(complex) == np.complex_ == np.complex128.

Until #15773, this would give a DeprecationWarning, but then do what you expect.

@david-cortes
Copy link
Contributor Author

david-cortes commented Oct 31, 2021

Yes, that would do it, although it would be nice to have that kind of thing as a warning in the docs for dtypes under the part where it says "Built-in Python types" (https://numpy.org/doc/stable/reference/arrays.dtypes.html).

@eric-wieser
Copy link
Member

eric-wieser commented Oct 31, 2021

I think this probably belongs as a warning in the docs for issubdtype. I've rephrased the issue as missing documentation, but feel free to contribute a fix yourself.

@eric-wieser eric-wieser changed the title BUG: complex64 is not a subdtype of complex or complex_ DOC: docs for issubdtype doesn't explain why complex64 is not a subdtype of complex or complex_ Oct 31, 2021
@eric-wieser eric-wieser reopened this Oct 31, 2021
@tensionhead
Copy link

I also stumbled upon this, it is very irritating:

np.issubdtype(np.dtype('complex64'), np.complex)
>>>DeprecationWarning: `np.complex` is a deprecated alias for the builtin `complex`. To silence this warning, use `complex` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.complex128` here.
>>> False

If I then follow the deprecation warning I still get:

np.issubdtype(np.dtype('complex64'), complex)
>>> False

Same for floats:

np.issubdtype(np.dtype('float32'), float)
>>> False

However:

np.issubdtype(np.dtype('float64'), float)
>>> True

But if I just want to know if I have a complex dtype, the answer by @eric-wieser with np.complexfloating got me what I need.

@eric-wieser
Copy link
Member

For completeness, I think:

np.issubdtype(np.dtype('complex128'), complex)
>>> True

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

No branches or pull requests

3 participants