lint, fix zarr dump test

This commit is contained in:
sneakers-the-rat 2024-09-21 18:26:25 -07:00
parent 135b74aa2e
commit 70bf254ddd
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
4 changed files with 16 additions and 3 deletions

View file

@ -0,0 +1,7 @@
# serialization
```{eval-rst}
.. automodule:: numpydantic.serialization
:members:
:undoc-members:
```

View file

@ -491,6 +491,7 @@ api/ndarray
api/maps
api/meta
api/schema
api/serialization
api/shape
api/types

View file

@ -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)

View file

@ -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"]