コード例 #1
0
    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))
コード例 #2
0
    def test_duck(self):
        class DummyComplexArray:
            @property
            def dtype(self):
                return np.dtype(complex)

        dummy = DummyComplexArray()
        assert_(iscomplexobj(dummy))
コード例 #3
0
 def test_basic(self):
     a = np.random.rand(10)
     b = real_if_close(a + 1e-15j)
     assert_all(isrealobj(b))
     assert_array_equal(a, b)
     b = real_if_close(a + 1e-7j)
     assert_all(iscomplexobj(b))
     b = real_if_close(a + 1e-7j, tol=1e-6)
     assert_all(isrealobj(b))
コード例 #4
0
    def test_pandas_duck(self):
        # This tests a custom np.dtype duck-typed class, such as used by pandas
        # (pandas.core.dtypes)
        class PdComplex(np.complex128):
            pass

        class PdDtype(object):
            name = 'category'
            names = None
            type = PdComplex
            kind = 'c'
            str = '<c16'
            base = np.dtype('complex128')

        class DummyPd:
            @property
            def dtype(self):
                return PdDtype

        dummy = DummyPd()
        assert_(iscomplexobj(dummy))
コード例 #5
0
 def test_list(self):
     assert_(iscomplexobj([3, 1 + 0j, True]))
     assert_(not iscomplexobj([3, 1, True]))
コード例 #6
0
 def test_scalar(self):
     assert_(not iscomplexobj(1.0))
     assert_(iscomplexobj(1 + 0j))
コード例 #7
0
 def test_basic(self):
     z = np.array([-1, 0, 1])
     assert_(not iscomplexobj(z))
     z = np.array([-1j, 0, -1])
     assert_(iscomplexobj(z))