From 1afe3596817e5c7f14c1bd6aab932ed54b62da25 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Thu, 3 Oct 2024 18:44:43 -0700 Subject: [PATCH] messy ass checkpoint before i come back and clean it up --- src/numpydantic/interface/hdf5.py | 19 ++++++++++--------- src/numpydantic/ndarray.py | 2 ++ src/numpydantic/serialization.py | 2 ++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/numpydantic/interface/hdf5.py b/src/numpydantic/interface/hdf5.py index d2f01ad..25757c3 100644 --- a/src/numpydantic/interface/hdf5.py +++ b/src/numpydantic/interface/hdf5.py @@ -39,7 +39,6 @@ as ``S32`` isoformatted byte strings (timezones optional) like: """ -import pdb import sys from datetime import datetime from pathlib import Path @@ -171,7 +170,7 @@ class H5Proxy: __pydantic_serializer__ = SchemaSerializer( core_schema.plain_serializer_function_ser_schema( to_json, when_used="json", info_arg=True - ) + ), ) def __init__( @@ -218,17 +217,18 @@ class H5Proxy: return obj[:] def __getattr__(self, item: str): - if item not in ("shape", "__pydantic_validator__"): - pdb.set_trace() if item == "__name__": # special case for H5Proxies that don't refer to a real file during testing return "H5Proxy" elif item.startswith("__"): return object.__getattribute__(self, item) - with h5py.File(self.file, "r") as h5f: - obj = h5f.get(self.path) - val = getattr(obj, item) - return val + try: + with h5py.File(self.file, "r") as h5f: + obj = h5f.get(self.path) + val = getattr(obj, item) + return val + except AttributeError: + return object.__getattribute__(self, item) def __getitem__( self, item: Union[int, slice, Tuple[Union[int, slice], ...]] @@ -303,7 +303,8 @@ class H5Proxy: if isinstance(other, H5Proxy): return self._h5arraypath == other._h5arraypath else: - raise ValueError("Can only compare equality of two H5Proxies") + return False + # raise ValueError("Can only compare equality of two H5Proxies") def open(self, mode: str = "r") -> "h5py.Dataset": """ diff --git a/src/numpydantic/ndarray.py b/src/numpydantic/ndarray.py index fa0fdc9..297c442 100644 --- a/src/numpydantic/ndarray.py +++ b/src/numpydantic/ndarray.py @@ -13,6 +13,7 @@ Extension of nptyping NDArray for pydantic that allows for JSON-Schema serializa """ +import pdb from typing import TYPE_CHECKING, Any, Literal, Tuple, get_origin import numpy as np @@ -201,6 +202,7 @@ class NDArray(NPTypingType, metaclass=NDArrayMeta): cls, schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler ) -> core_schema.JsonSchema: shape, dtype = cls.__args__ + pdb.set_trace() json_schema = handler(schema["metadata"]) json_schema = handler.resolve_ref_schema(json_schema) diff --git a/src/numpydantic/serialization.py b/src/numpydantic/serialization.py index 502d43d..357e3c9 100644 --- a/src/numpydantic/serialization.py +++ b/src/numpydantic/serialization.py @@ -16,6 +16,8 @@ U = TypeVar("U") def jsonize_array(value: Any, info: SerializationInfo) -> Union[list, dict]: """Use an interface class to render an array as JSON""" + # return [1, 2, 3] + # pdb.set_trace() interface_cls = Interface.match_output(value) array = interface_cls.to_json(value, info) array = postprocess_json(array, info)