mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-14 02:34: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/meta
|
||||
api/schema
|
||||
api/serialization
|
||||
api/shape
|
||||
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 typing import Any, Callable, TypeVar, Union
|
||||
|
||||
|
@ -41,7 +46,7 @@ def _relativize_paths(value: dict, relative_to: str = ".") -> dict:
|
|||
if not path.exists():
|
||||
return v
|
||||
return str(relative_path(path, relative_to))
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
return v
|
||||
|
||||
return _walk_and_apply(value, _r_path)
|
||||
|
@ -54,7 +59,7 @@ def _absolutize_paths(value: dict) -> dict:
|
|||
if not path.exists():
|
||||
return v
|
||||
return str(path.resolve())
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
return v
|
||||
|
||||
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)
|
||||
instance = model_blank(array=array)
|
||||
|
||||
context = {"zarr_dump_array": dump_array}
|
||||
context = {"dump_array": dump_array}
|
||||
as_json = json.loads(
|
||||
instance.model_dump_json(round_trip=roundtrip, context=context)
|
||||
)["array"]
|
||||
|
|
Loading…
Reference in a new issue