summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-08-06 17:22:20 -0500
committerGitHub <noreply@github.com>2017-08-06 17:22:20 -0500
commit91b06c021319faccb008a8ee485d26ae227bf079 (patch)
tree7195085d6bcaec87b5f2f0629c14456fcfa53d11 /numpy/core
parentf307cec3962926558b6387ebb4ab8d3f4ea3aa34 (diff)
parent351fe979580ab842cc5c04e1b616d3a64936a695 (diff)
downloadnumpy-91b06c021319faccb008a8ee485d26ae227bf079.tar.gz
Merge pull request #9522 from eric-wieser/stop-using-obj2sctype
BUG: Fix problems with obj2sctype
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/numerictypes.py38
1 files changed, 7 insertions, 31 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index 2cb66aab4..b61f5e7bc 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -529,27 +529,6 @@ def maximum_sctype(t):
else:
return sctypes[base][-1]
-try:
- buffer_type = _types.BufferType
-except AttributeError:
- # Py3K
- buffer_type = memoryview
-
-_python_types = {int: 'int_',
- float: 'float_',
- complex: 'complex_',
- bool: 'bool_',
- bytes: 'bytes_',
- unicode: 'unicode_',
- buffer_type: 'void',
- }
-
-def _python_type(t):
- """ Get a numpy scalar type corresponding to a Python type or value """
- if not isinstance(t, type):
- t = type(t)
- return allTypes[_python_types.get(t, 'object_')]
-
def issctype(rep):
"""
@@ -634,22 +613,19 @@ def obj2sctype(rep, default=None):
<type 'list'>
"""
- try:
- if issubclass(rep, generic):
- return rep
- except TypeError:
- pass
- if isinstance(rep, dtype):
- return rep.type
- if isinstance(rep, type):
- return _python_type(rep)
+ # prevent abtract classes being upcast
+ if isinstance(rep, type) and issubclass(rep, generic):
+ return rep
+ # extract dtype from arrays
if isinstance(rep, ndarray):
return rep.dtype.type
+ # fall back on dtype to convert
try:
res = dtype(rep)
except Exception:
return default
- return res.type
+ else:
+ return res.type
def issubclass_(arg1, arg2):