diff --git a/deker/ABC/base_schemas.py b/deker/ABC/base_schemas.py index 9f04704..95f0310 100644 --- a/deker/ABC/base_schemas.py +++ b/deker/ABC/base_schemas.py @@ -27,7 +27,7 @@ from deker.errors import DekerInvalidSchemaError, DekerValidationError from deker.tools.schema import get_default_fill_value from deker.types.private.enums import DTypeEnum -from deker.types.private.typings import Numeric +from deker.types.private.typings import Numeric, NumericDtypes @dataclass(repr=True) @@ -121,6 +121,9 @@ def __attrs_post_init__(self) -> None: if len({d.name for d in self.dimensions}) < len(self.dimensions): raise DekerValidationError("Dimensions shall have unique names") + if self.dtype not in NumericDtypes: + raise DekerValidationError(f"Invalid dtype {self.dtype}") + try: if self.dtype == int: self.dtype = np.int64 @@ -163,10 +166,10 @@ def named_shape(self) -> Tuple[Tuple[str, int], ...]: @property def as_dict(self) -> dict: """Serialize as dict.""" - if not issubclass(self.dtype, Numeric): # type: ignore[arg-type] - raise DekerInvalidSchemaError( - f'Schema "{self.__class__.__name__}" is invalid/corrupted: wrong dtype {self.dtype}' - ) + error = f'Schema "{self.__class__.__name__}" is invalid/corrupted: ' + + if self.dtype not in NumericDtypes: + raise DekerInvalidSchemaError(error + f"wrong dtype {self.dtype}") try: dtype = DTypeEnum.get_name(DTypeEnum(self.dtype)) fill_value = None if np.isnan(self.fill_value) else str(self.fill_value) # type: ignore[arg-type] @@ -180,6 +183,4 @@ def as_dict(self) -> dict: "fill_value": fill_value, } except (KeyError, ValueError) as e: - raise DekerInvalidSchemaError( - f'Schema "{self.__class__.__name__}" is invalid/corrupted: {e}' - ) + raise DekerInvalidSchemaError(error + str(e)) diff --git a/deker/types/private/typings.py b/deker/types/private/typings.py index c5372ef..0ab14a0 100644 --- a/deker/types/private/typings.py +++ b/deker/types/private/typings.py @@ -65,6 +65,7 @@ np.ushort, np.ulonglong, np.float16, + np.float32, np.float64, np.float128, np.longfloat, @@ -97,6 +98,7 @@ np.ushort, np.ulonglong, np.float16, + np.float32, np.float64, np.float128, np.longfloat,