summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>2017-02-10 19:20:33 +0100
committerCharles Harris <charlesr.harris@gmail.com>2017-02-12 11:39:15 -0700
commitc42ed284ea690c876499e89667f0bd75f4bfe3b4 (patch)
treeb454334a41760b1e6526fd1d68383cc4af814a79
parent0a458acbc3ada2e24a4d5080d71a79680239013b (diff)
downloadnumpy-c42ed284ea690c876499e89667f0bd75f4bfe3b4.tar.gz
BUG: Make iscomplexobj compatible with custom dtypes again
This change makes iscomplexobj compatible with custom array types using custom dtypes, that are not fully compatible to Numpys dtypes, which can nevertheless be coerced to a numpy array with asarray again, as has been the behaviour before PR #7936. Fixes #8601
-rw-r--r--numpy/lib/tests/test_type_check.py9
-rw-r--r--numpy/lib/type_check.py8
2 files changed, 12 insertions, 5 deletions
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index 93a4da97a..4523e3f24 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -183,6 +183,15 @@ class TestIscomplexobj(TestCase):
dummy = DummyPd()
assert_(iscomplexobj(dummy))
+ def test_custom_dtype_duck(self):
+ class MyArray(list):
+ @property
+ def dtype(self):
+ return complex
+
+ a = MyArray([1+0j, 2+0j, 3+0j])
+ assert_(iscomplexobj(a))
+
class TestIsrealobj(TestCase):
def test_basic(self):
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 1658f160c..3bbee0258 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -268,12 +268,10 @@ def iscomplexobj(x):
"""
try:
dtype = x.dtype
+ type_ = dtype.type
except AttributeError:
- dtype = asarray(x).dtype
- try:
- return issubclass(dtype.type, _nx.complexfloating)
- except AttributeError:
- return False
+ type_ = asarray(x).dtype.type
+ return issubclass(type_, _nx.complexfloating)
def isrealobj(x):