Thanks to visit codestin.com
Credit goes to github.com

Skip to content

issubdtype(double, bool) #5711

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

Closed
ahojnnes opened this issue Mar 23, 2015 · 8 comments
Closed

issubdtype(double, bool) #5711

ahojnnes opened this issue Mar 23, 2015 · 8 comments

Comments

@ahojnnes
Copy link
Contributor

Maybe I am missing something, but is this correct?

np.issubdtype(np.double, np.bool) => True

At the very least, this is confusing.

@argriffing
Copy link
Contributor

This isn't an answer, but:

>>> np.issubdtype(np.double, np.bool_)
False

also related

>>> np.issubclass_(np.bool, np.generic)
False
>>> np.issubclass_(np.bool_, np.generic)
True

>>> inspect.getmro(np.bool)
(<type 'bool'>, <type 'int'>, <type 'object'>)
>>> inspect.getmro(np.bool_)
(<type 'numpy.bool_'>, <type 'numpy.generic'>, <type 'object'>)

@ahojnnes
Copy link
Contributor Author

Thanks for the clarification!

Feel free to close the issue, if you think this is the intended behavior.

@charris
Copy link
Member

charris commented Mar 24, 2015

In [39]: issubdtype(np.bool_, np.int8)
Out[39]: False

In [40]: issubdtype(np.int8, np.bool_)
Out[40]: False

np.bool_ seems to be a type all by itself in the type hierarchy.

@njsmith
Copy link
Member

njsmith commented Mar 24, 2015

Yes, it is. For some reason the picture is hidden on this page:
http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html

I don't know what's going on with the original report, though: dtype(bool)
and dtype(bool_) certainly ought to return the same things...
On Mar 23, 2015 7:49 PM, "Charles Harris" [email protected] wrote:

In [39]: issubdtype(np.bool_, np.int8)
Out[39]: False

In [40]: issubdtype(np.int8, np.bool_)
Out[40]: False

np.bool_ seems to be a type all by itself in the type hierarchy.


Reply to this email directly or view it on GitHub
#5711 (comment).

@charris
Copy link
Member

charris commented Mar 24, 2015

There is this

n [14]: issubdtype(np.object, np.bool)
Out[14]: True

In [15]: issubdtype(np.bool, np.object)
Out[15]: True

Python bool was new in python version 2.2.1. It may be that the current behavior is an accident.

@pv
Copy link
Member

pv commented Mar 24, 2015

Note that the code in np.issubdtype contains some weird stuff:

    if issubclass_(arg2, generic):
        return issubclass(dtype(arg1).type, arg2)
    mro = dtype(arg2).type.mro()
    if len(mro) > 1:
        val = mro[1]
    else:
        val = mro[0]
    return issubclass(dtype(arg1).type, val)

For example

>>> np.issubdtype(np.float32, np.dtype(float))
True

The commit message in 325aad6 is not very helpful on why this was made so.
One possible motivation could be to make issubdtype(foo, int) and issubdtype(foo, float) do the same thing as if comparing to np.integer_ and np.floating_.

@maniteja123
Copy link
Contributor

I think #3218 is relevant to this issue.

sethaxen added a commit to keiserlab/e3fp-paper that referenced this issue Feb 11, 2017
This is due to odd behavior in NumPy where
floating point numbers are considered
subtypes of bool. Now explicitly check
if number is floating point.

See numpy/numpy#5711
@eric-wieser
Copy link
Member

eric-wieser commented Sep 27, 2017

Duplicate of #2334

Deprecated in #9505

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

No branches or pull requests

7 participants