Repository: ramonhagenaars/nptyping

Issue:
Support complex type
Numpy can have complex numbers. I use it a lot in my code, it would be nice to have it

For example so far I get

```python
>>> NDArray.type_of(np.array([1j, 2j]))
KeyError: 'c'
```


Discussion:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index e590ee1..6796073 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,11 @@
 History
 -------
 
+1.3.0 (2020-07-21)
+++++++++++++++++++
+
+- Added ``Complex128``
+
 1.2.0 (2020-06-20)
 ++++++++++++++++++
 
diff --git a/README.md b/README.md
index d018f67..ca6cb15 100644
--- a/README.md
+++ b/README.md
@@ -231,6 +231,17 @@ Bool
 
 ```
 
+### (❒) Complex128
+An nptyping equivalent of numpy complex128.
+
+```python
+>>> from nptyping import Complex128
+
+>>> Complex128
+Complex128
+
+```
+
 ### (❒) Datetime64
 An nptyping equivalent of numpy datetime64.
 
diff --git a/nptyping/__init__.py b/nptyping/__init__.py
index 9dc9c20..e15aaac 100644
--- a/nptyping/__init__.py
+++ b/nptyping/__init__.py
@@ -2,8 +2,8 @@ from nptyping._meta import __version__
 from nptyping.functions._get_type import get_type
 from nptyping.functions._py_type import py_type
 from nptyping.types._bool import Bool
+from nptyping.types._complex import Complex128
 from nptyping.types._datetime64 import Datetime64
-from nptyping.types._timedelta64 import Timedelta64
 from nptyping.types._ndarray import NDArray
 from nptyping.types._nptype import NPType
 from nptyping.types._number import (
@@ -26,4 +26,5 @@ from nptyping.types._number import (
     Float64,
 )
 from nptyping.types._object import Object
+from nptyping.types._timedelta64 import Timedelta64
 from nptyping.types._unicode import Unicode
diff --git a/nptyping/_meta.py b/nptyping/_meta.py
index 4884844..22d55e0 100644
--- a/nptyping/_meta.py
+++ b/nptyping/_meta.py
@@ -1,5 +1,5 @@
 __title__ = 'nptyping'
-__version__ = '1.2.0'
+__version__ = '1.3.0'
 __author__ = 'Ramon Hagenaars'
 __author_email__ = 'ramon.hagenaars@gmail.com'
 __description__ = 'Type hints for Numpy.'
diff --git a/nptyping/functions/_get_type.py b/nptyping/functions/_get_type.py
index 13ed1b3..a1286a4 100644
--- a/nptyping/functions/_get_type.py
+++ b/nptyping/functions/_get_type.py
@@ -6,6 +6,7 @@ from typish import ClsFunction
 
 from nptyping.functions._py_type import py_type
 from nptyping.types._bool import Bool
+from nptyping.types._complex import Complex128
 from nptyping.types._datetime64 import Datetime64
 from nptyping.types._ndarray import NDArray
 from nptyping.types._nptype import NPType
@@ -15,7 +16,7 @@ from nptyping.types._number import (
     UInt,
     Number,
     DEFAULT_INT_BITS,
-    DEFAULT_FLOAT_BITS
+    DEFAULT_FLOAT_BITS,
 )
 from nptyping.types._object import Object
 from nptyping.types._timedelta64 import Timedelta64
@@ -49,6 +50,7 @@ def _get_type_dtype(dtype: numpy.dtype) -> Type['NPType']:
         int: get_type_int,
         float: get_type_float,
         str: get_type_str,
+        complex: get_type_complex,
         datetime: get_type_datetime64,
         timedelta: get_type_timedelta64,
         object: lambda _: Object,
@@ -172,6 +174,16 @@ def get_type_timedelta64(_: Any) -> Type[Timedelta64]:
     return Timedelta64
 
 
+# Library private.
+def get_type_complex(_: Any) -> Type[Complex128]:
+    """
+    Return the NPType that corresponds to obj.
+    :param _: a complex128 compatible object.
+    :return: a Complex128 type.
+    """
+    return Complex128
+
+
 _delegates = [
     (NPType, lambda x: x),
     (type, _get_type_type),
@@ -179,6 +191,7 @@ _delegates = [
     (int, get_type_int),
     (float, get_type_float),
     (str, get_type_str),
+    (complex, get_type_complex),
     (datetime, get_type_datetime64),
     (timedelta, get_type_timedelta64),
     (numpy.datetime64, get_type_datetime64),
diff --git a/nptyping/functions/_py_type.py b/nptyping/functions/_py_type.py
index 5dd2109..ebbc800 100644
--- a/nptyping/functions/_py_type.py
+++ b/nptyping/functions/_py_type.py
@@ -37,4 +37,5 @@ _TYPE_PER_KIND = {
     'b': bool,
     'M': datetime,
     'm': timedelta,
+    'c': complex,
 }
diff --git a/nptyping/types/_complex.py b/nptyping/types/_complex.py
new file mode 100644
index 0000000..bf05e37
--- /dev/null
+++ b/nptyping/types/_complex.py
@@ -0,0 +1,16 @@
+import numpy
+
+from nptyping.types._nptype import NPType
+
+
+class _Complex128Meta(type):
+    def __repr__(cls):
+        return 'Complex128'
+
+    __str__ = __repr__
+
+
+class Complex128(NPType, numpy.generic, metaclass=_Complex128Meta):
+    """
+    Corresponds to numpy.complex128.
+    """
diff --git a/setup.cfg b/setup.cfg
index 4b5f3fa..39f9ffb 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,11 +1,5 @@
 [pylint]
-disable = broad-except,too-many-instance-attributes,too-many-arguments
+disable = too-many-instance-attributes,too-many-arguments
           ,missing-module-docstring,too-few-public-methods,fixme
           ,invalid-name,import-outside-toplevel,unidiomatic-typecheck
-          ,cyclic-import
-
-[mypy-typish.*]
-ignore_missing_imports = True
-
-[mypy-numpy.*]
-ignore_missing_imports = True
+          ,cyclic-import,duplicate-code


Test patch:
diff --git a/tests/test_functions/test_get_type.py b/tests/test_functions/test_get_type.py
index 3f7e4ca..f040e70 100644
--- a/tests/test_functions/test_get_type.py
+++ b/tests/test_functions/test_get_type.py
@@ -22,7 +22,9 @@ from nptyping import (
     DEFAULT_FLOAT_BITS,
     Float,
     Bool,
-    Datetime64)
+    Datetime64,
+    Complex128,
+)
 from nptyping.types._object import Object
 from nptyping.types._timedelta64 import Timedelta64
 from nptyping.types._unicode import Unicode
@@ -69,6 +71,13 @@ class TestGetType(TestCase):
         self.assertEqual(Bool, get_type(np.bool_(True)))
         self.assertEqual(Bool, get_type(np.bool_(False)))
 
+    def test_get_type_complex(self):
+        self.assertEqual(Complex128, get_type(1 + 1j))
+        self.assertEqual(Complex128, get_type(np.complex128(1 + 1j)))
+
+        self.assertEqual(Complex128, get_type(complex))
+        self.assertEqual(Complex128, get_type(np.complex128))
+
     def test_get_type_datatime(self):
         self.assertEqual(Datetime64, get_type(datetime.now()))
         self.assertEqual(Datetime64, get_type(datetime))
diff --git a/tests/test_types/test_complex.py b/tests/test_types/test_complex.py
new file mode 100644
index 0000000..7f05b35
--- /dev/null
+++ b/tests/test_types/test_complex.py
@@ -0,0 +1,9 @@
+from unittest import TestCase
+
+from nptyping import Complex128
+
+
+class TestComplex(TestCase):
+
+    def test_repr(self):
+        self.assertEqual('Complex128', repr(Complex128))