From 70bf254dddc8de454bde2214e023c62aca6541e8 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Sat, 21 Sep 2024 18:26:25 -0700 Subject: [PATCH] lint, fix zarr dump test --- docs/api/serialization.md | 7 +++++++ docs/index.md | 1 + src/numpydantic/serialization.py | 9 +++++++-- tests/test_interface/test_zarr.py | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 docs/api/serialization.md diff --git a/docs/api/serialization.md b/docs/api/serialization.md new file mode 100644 index 0000000..f070ea0 --- /dev/null +++ b/docs/api/serialization.md @@ -0,0 +1,7 @@ +# serialization + +```{eval-rst} +.. automodule:: numpydantic.serialization + :members: + :undoc-members: +``` \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index c75ce74..003f5c3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -491,6 +491,7 @@ api/ndarray api/maps api/meta api/schema +api/serialization api/shape api/types diff --git a/src/numpydantic/serialization.py b/src/numpydantic/serialization.py index a2b2507..2f5b578 100644 --- a/src/numpydantic/serialization.py +++ b/src/numpydantic/serialization.py @@ -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) diff --git a/tests/test_interface/test_zarr.py b/tests/test_interface/test_zarr.py index 05eb8d5..fca15ae 100644 --- a/tests/test_interface/test_zarr.py +++ b/tests/test_interface/test_zarr.py @@ -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"]