diff options
author | Stephan Hoyer <shoyer@gmail.com> | 2017-02-11 18:07:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-11 18:07:53 -0800 |
commit | bcae38abb15ef27fea0c581f122ff5a79574277f (patch) | |
tree | 2714c4ef7b86e717f777a18295ba7e728669e35b /numpy/lib | |
parent | 1b483c2398ce2de49f72b9005dfb92859e389914 (diff) | |
parent | bb1c471a299c0118d890988f4bfb7df8eca6595d (diff) | |
download | numpy-bcae38abb15ef27fea0c581f122ff5a79574277f.tar.gz |
Merge pull request #8602 from behrmann/fix-iscomplexobj
BUG: Make iscomplexobj compatible with custom dtypes again
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/tests/test_type_check.py | 9 | ||||
-rw-r--r-- | numpy/lib/type_check.py | 8 |
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): |