From 0d5e4cf555b95f9a3093cd67a3964b665cd099e0 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Wed, 31 Jul 2024 02:03:30 -0700 Subject: [PATCH] add datetime to maps --- src/numpydantic/maps.py | 1 + src/numpydantic/ndarray.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/numpydantic/maps.py b/src/numpydantic/maps.py index 4db4b2d..38e4925 100644 --- a/src/numpydantic/maps.py +++ b/src/numpydantic/maps.py @@ -64,5 +64,6 @@ python_to_nptyping = { int: dt.Int, bool: dt.Bool, complex: dt.Complex, + datetime: np.datetime64, } """Map from python types to nptyping types""" diff --git a/src/numpydantic/ndarray.py b/src/numpydantic/ndarray.py index e62df59..5ad42ba 100644 --- a/src/numpydantic/ndarray.py +++ b/src/numpydantic/ndarray.py @@ -135,6 +135,15 @@ class NDArrayMeta(_NDArrayMeta, implementation="NDArray"): ) return dtype + def _dtype_to_str(cls, dtype: Any) -> str: + if dtype is Any: + result = "Any" + elif issubclass(dtype, Structure): + result = str(dtype) + elif isinstance(dtype, tuple): + result = ", ".join([str(dt) for dt in dtype]) + return result + class NDArray(NPTypingType, metaclass=NDArrayMeta): """