Numpy: int is a basestring?

How are numpynumeric types subtypes basestring?

for nptype in [np.int32, np.int64, np.integer, np.float]:
    for stype in [str, basestring, unicode]:
        print nptype, stype, np.issubdtype(nptype,stype)
<type 'numpy.int32'> <type 'str'> False
<type 'numpy.int32'> <type 'basestring'> True
<type 'numpy.int32'> <type 'unicode'> False
<type 'numpy.int64'> <type 'str'> False
<type 'numpy.int64'> <type 'basestring'> True
<type 'numpy.int64'> <type 'unicode'> False
<type 'numpy.integer'> <type 'str'> False
<type 'numpy.integer'> <type 'basestring'> True
<type 'numpy.integer'> <type 'unicode'> False
<type 'float'> <type 'str'> False
<type 'float'> <type 'basestring'> True
<type 'float'> <type 'unicode'> False
+4
source share
1 answer

basestringis not dtype or secure convertible to dtype, but issubdtypedoes not have error handling to recognize this. It callsnumpy.dtype on basestringto get a dtype, and since it numpy.dtypesees that the input is an object of type Python, it doesn’t. I don’t understand, the resulting dtype is a dtype object. The rest of the logic considers each dtype subtype of a dtype object.

+3
source

Source: https://habr.com/ru/post/1671308/


All Articles