mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-14 18:54:28 +00:00
lint, fix zarr dump test
This commit is contained in:
parent
135b74aa2e
commit
70bf254ddd
4 changed files with 16 additions and 3 deletions
7
docs/api/serialization.md
Normal file
7
docs/api/serialization.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# serialization
|
||||||
|
|
||||||
|
```{eval-rst}
|
||||||
|
.. automodule:: numpydantic.serialization
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
```
|
|
@ -491,6 +491,7 @@ api/ndarray
|
||||||
api/maps
|
api/maps
|
||||||
api/meta
|
api/meta
|
||||||
api/schema
|
api/schema
|
||||||
|
api/serialization
|
||||||
api/shape
|
api/shape
|
||||||
api/types
|
api/types
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
"""
|
||||||
|
Serialization helpers for :func:`pydantic.BaseModel.model_dump`
|
||||||
|
and :func:`pydantic.BaseModel.model_dump_json` .
|
||||||
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, TypeVar, Union
|
from typing import Any, Callable, TypeVar, Union
|
||||||
|
|
||||||
|
@ -41,7 +46,7 @@ def _relativize_paths(value: dict, relative_to: str = ".") -> dict:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return v
|
return v
|
||||||
return str(relative_path(path, relative_to))
|
return str(relative_path(path, relative_to))
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
return _walk_and_apply(value, _r_path)
|
return _walk_and_apply(value, _r_path)
|
||||||
|
@ -54,7 +59,7 @@ def _absolutize_paths(value: dict) -> dict:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return v
|
return v
|
||||||
return str(path.resolve())
|
return str(path.resolve())
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
return _walk_and_apply(value, _a_path)
|
return _walk_and_apply(value, _a_path)
|
||||||
|
|
|
@ -141,7 +141,7 @@ def test_zarr_to_json(store, model_blank, roundtrip, dump_array):
|
||||||
array = zarr.array(lol_array, store=store)
|
array = zarr.array(lol_array, store=store)
|
||||||
instance = model_blank(array=array)
|
instance = model_blank(array=array)
|
||||||
|
|
||||||
context = {"zarr_dump_array": dump_array}
|
context = {"dump_array": dump_array}
|
||||||
as_json = json.loads(
|
as_json = json.loads(
|
||||||
instance.model_dump_json(round_trip=roundtrip, context=context)
|
instance.model_dump_json(round_trip=roundtrip, context=context)
|
||||||
)["array"]
|
)["array"]
|
||||||
|
|
Loading…
Reference in a new issue