mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-12 17:54:29 +00:00
handle and test complex
This commit is contained in:
parent
3a6984f3f0
commit
a1a440e6ad
3 changed files with 16 additions and 4 deletions
|
@ -58,5 +58,11 @@ flat_to_nptyping = {
|
|||
}
|
||||
"""Map from NWB-style flat dtypes to nptyping types"""
|
||||
|
||||
python_to_nptyping = {float: dt.Float, str: dt.String, int: dt.Int, bool: dt.Bool}
|
||||
python_to_nptyping = {
|
||||
float: dt.Float,
|
||||
str: dt.String,
|
||||
int: dt.Int,
|
||||
bool: dt.Bool,
|
||||
complex: dt.Complex,
|
||||
}
|
||||
"""Map from python types to nptyping types"""
|
||||
|
|
|
@ -41,7 +41,6 @@ def _numeric_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema:
|
|||
|
||||
def _lol_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema:
|
||||
"""Get the innermost dtype schema to use in the generated pydantic schema"""
|
||||
|
||||
if isinstance(dtype, nptyping.structure.StructureMeta): # pragma: no cover
|
||||
raise NotImplementedError("Structured dtypes are currently unsupported")
|
||||
|
||||
|
@ -63,7 +62,10 @@ def _lol_dtype(dtype: DtypeType, _handler: _handler_type) -> CoreSchema:
|
|||
else:
|
||||
try:
|
||||
python_type = np_to_python[dtype]
|
||||
except KeyError as e:
|
||||
except KeyError as e: # pragma: no cover
|
||||
# this should pretty much only happen in downstream/3rd-party interfaces
|
||||
# that use interface-specific types. those need to provide mappings back
|
||||
# to base python types (making this more streamlined is TODO)
|
||||
if dtype in np_to_python.values():
|
||||
# it's already a python type
|
||||
python_type = dtype
|
||||
|
|
|
@ -169,6 +169,7 @@ def test_json_schema_dtype_single(dtype, array_model):
|
|||
(int, "integer"),
|
||||
(float, "number"),
|
||||
(bool, "boolean"),
|
||||
(complex, "any"),
|
||||
],
|
||||
)
|
||||
def test_json_schema_dtype_builtin(dtype, expected, array_model):
|
||||
|
@ -179,7 +180,10 @@ def test_json_schema_dtype_builtin(dtype, expected, array_model):
|
|||
model = array_model(dtype=dtype)
|
||||
schema = model.model_json_schema()
|
||||
inner_type = schema["properties"]["array"]["items"]["items"]
|
||||
assert inner_type["type"] == expected
|
||||
if expected == "any":
|
||||
assert inner_type == {}
|
||||
else:
|
||||
assert inner_type["type"] == expected
|
||||
|
||||
|
||||
@pytest.mark.skip("Not implemented yet")
|
||||
|
|
Loading…
Reference in a new issue