Skip to content

Commit

Permalink
tests fixed, float32 restored
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Rybakov committed Dec 4, 2023
1 parent f3ca631 commit 33d4870
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions deker/ABC/base_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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))
2 changes: 2 additions & 0 deletions deker/types/private/typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
np.ushort,
np.ulonglong,
np.float16,
np.float32,
np.float64,
np.float128,
np.longfloat,
Expand Down Expand Up @@ -97,6 +98,7 @@
np.ushort,
np.ulonglong,
np.float16,
np.float32,
np.float64,
np.float128,
np.longfloat,
Expand Down

0 comments on commit 33d4870

Please sign in to comment.