diff options
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/defmatrix.py | 2 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py index 1707e49fd..97602918d 100644 --- a/numpy/core/defmatrix.py +++ b/numpy/core/defmatrix.py @@ -3,7 +3,7 @@ __all__ = ['matrix', 'bmat', 'mat', 'asmatrix'] import sys import numeric as N from numeric import concatenate, isscalar, binary_repr, identity -from numpy.lib.utils import issubdtype +from numerictypes import issubdtype # make translation table _table = [None]*256 diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 548740eb1..ad555f2e0 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -484,6 +484,49 @@ def obj2sctype(rep, default=None): return res.type +def issubclass_(arg1, arg2): + try: + return issubclass(arg1, arg2) + except TypeError: + return False + +def issubsctype(arg1, arg2): + return issubclass(obj2sctype(arg1), obj2sctype(arg2)) + +def issubdtype(arg1, arg2): + """ + Returns True if first argument is a typecode lower/equal in type hierarchy. + + Parameters + ---------- + arg1 : dtype_like + dtype or string representing a typecode. + arg2 : dtype_like + dtype or string representing a typecode. + + + See Also + -------- + numpy.core.numerictypes : Overview of numpy type hierarchy. + + Examples + -------- + >>> np.issubdtype('S1', str) + True + >>> np.issubdtype(np.float64, np.float32) + False + + """ + 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) + + # This dictionary allows look up based on any alias for an array data-type class _typedict(dict): def __getitem__(self, obj): |