summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-08-01 18:14:06 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-08-05 21:50:05 -0500
commit44a4b719e49b7106560b46d373b8627ab19e7c2d (patch)
treeaf1513aaf5e9ee4a7eb8d4aa88513dfceb197433 /numpy
parentdda20349d172ed09b949a3b819eb16a384cd29a8 (diff)
downloadnumpy-44a4b719e49b7106560b46d373b8627ab19e7c2d.tar.gz
BUG: dtypes are ignored and downcast in issubdtype
Fixes #9480
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/numerictypes.py19
-rw-r--r--numpy/core/tests/test_numerictypes.py25
2 files changed, 36 insertions, 8 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index e7e7e5509..941642d91 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -753,14 +753,17 @@ def issubdtype(arg1, arg2):
"""
if not issubclass_(arg1, generic):
arg1 = dtype(arg1).type
- if issubclass_(arg2, generic):
- return issubclass(arg1, arg2)
- mro = dtype(arg2).type.mro()
- if len(mro) > 1:
- val = mro[1]
- else:
- val = mro[0]
- return issubclass(arg1, val)
+ if not issubclass_(arg2, generic):
+ arg2_orig = arg2
+ arg2 = dtype(arg2).type
+ if not isinstance(arg2_orig, dtype):
+ # weird deprecated behaviour, that tried to infer np.floating from
+ # float, and similar less obvious things, such as np.generic from
+ # basestring
+ mro = arg2.mro()
+ arg2 = mro[1] if len(mro) > 1 else mro[0]
+
+ return issubclass(arg1, arg2)
# This dictionary allows look up based on any alias for an array data-type
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index 977e4ce40..8831cd1bb 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -1,6 +1,7 @@
from __future__ import division, absolute_import, print_function
import sys
+import itertools
import numpy as np
from numpy.testing import (
@@ -379,10 +380,34 @@ class TestMultipleFields(object):
class TestIsSubDType(object):
+ # scalar types can be promoted into dtypes
+ wrappers = [np.dtype, lambda x: x]
+
def test_both_abstract(self):
assert_(np.issubdtype(np.floating, np.inexact))
assert_(not np.issubdtype(np.inexact, np.floating))
+ def test_same(self):
+ for cls in (np.float32, np.int32):
+ for w1, w2 in itertools.product(self.wrappers, repeat=2):
+ assert_(np.issubdtype(w1(cls), w2(cls)))
+
+ def test_subclass(self):
+ # note we cannot promote floating to a dtype, as it would turn into a
+ # concrete type
+ for w in self.wrappers:
+ assert_(np.issubdtype(w(np.float32), np.floating))
+ assert_(np.issubdtype(w(np.float64), np.floating))
+
+ def test_subclass_backwards(self):
+ for w in self.wrappers:
+ assert_(not np.issubdtype(np.floating, w(np.float32)))
+ assert_(not np.issubdtype(np.floating, w(np.float64)))
+
+ def test_sibling_class(self):
+ for w1, w2 in itertools.product(self.wrappers, repeat=2):
+ assert_(not np.issubdtype(w1(np.float32), w2(np.float64)))
+ assert_(not np.issubdtype(w1(np.float64), w2(np.float32)))
if __name__ == "__main__":
run_module_suite()