mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-14 18:54:28 +00:00
unbreak numpydantic
This commit is contained in:
parent
5b59e9fc07
commit
4ad3dc0696
1 changed files with 26 additions and 26 deletions
|
@ -5,7 +5,9 @@ For literal dtypes intended for use by end-users, see :mod:`numpydantic.dtype`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Union, get_origin
|
from typing import Any, Union, get_args, get_origin
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from numpydantic.types import DtypeType
|
from numpydantic.types import DtypeType
|
||||||
|
|
||||||
|
@ -26,31 +28,29 @@ def validate_dtype(dtype: Any, target: DtypeType) -> bool:
|
||||||
Returns:
|
Returns:
|
||||||
bool: ``True`` if valid, ``False`` otherwise
|
bool: ``True`` if valid, ``False`` otherwise
|
||||||
"""
|
"""
|
||||||
return False
|
if target is Any:
|
||||||
#
|
return True
|
||||||
# if target is Any:
|
|
||||||
# return True
|
if isinstance(target, tuple):
|
||||||
#
|
valid = dtype in target
|
||||||
# if isinstance(target, tuple):
|
elif is_union(target):
|
||||||
# valid = dtype in target
|
valid = any(
|
||||||
# elif is_union(target):
|
[validate_dtype(dtype, target_dt) for target_dt in get_args(target)]
|
||||||
# valid = any(
|
)
|
||||||
# [validate_dtype(dtype, target_dt) for target_dt in get_args(target)]
|
elif target is np.str_:
|
||||||
# )
|
valid = getattr(dtype, "type", None) in (np.str_, str) or dtype in (
|
||||||
# elif target is np.str_:
|
np.str_,
|
||||||
# valid = getattr(dtype, "type", None) in (np.str_, str) or dtype in (
|
str,
|
||||||
# np.str_,
|
)
|
||||||
# str,
|
else:
|
||||||
# )
|
# try to match as any subclass, if target is a class
|
||||||
# else:
|
try:
|
||||||
# # try to match as any subclass, if target is a class
|
valid = issubclass(dtype, target)
|
||||||
# try:
|
except TypeError:
|
||||||
# valid = issubclass(dtype, target)
|
# expected, if dtype or target is not a class
|
||||||
# except TypeError:
|
valid = dtype == target
|
||||||
# # expected, if dtype or target is not a class
|
|
||||||
# valid = dtype == target
|
return valid
|
||||||
#
|
|
||||||
# return valid
|
|
||||||
|
|
||||||
|
|
||||||
def is_union(dtype: DtypeType) -> bool:
|
def is_union(dtype: DtypeType) -> bool:
|
||||||
|
|
Loading…
Reference in a new issue