one last model generation

This commit is contained in:
sneakers-the-rat 2024-09-26 23:06:02 -07:00
parent 8c76ce82c3
commit 30e042444e
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
26 changed files with 708 additions and 44 deletions

View file

@ -31,6 +31,7 @@ from nwb_linkml.includes.base import (
BASEMODEL_COERCE_VALUE,
BASEMODEL_EXTRA_TO_VALUE,
BASEMODEL_GETITEM,
BASEMODEL_SERIALIZER,
)
from nwb_linkml.includes.hdmf import (
DYNAMIC_TABLE_IMPORTS,
@ -60,12 +61,20 @@ class NWBPydanticGenerator(PydanticGenerator):
BASEMODEL_CAST_WITH_VALUE,
BASEMODEL_COERCE_CHILD,
BASEMODEL_EXTRA_TO_VALUE,
BASEMODEL_SERIALIZER,
)
split: bool = True
imports: list[Import] = field(
default_factory=lambda: [
Import(module="numpy", alias="np"),
Import(module="pydantic", objects=[ObjectImport(name="model_validator")]),
Import(
module="pydantic",
objects=[
ObjectImport(name="model_validator"),
ObjectImport(name="model_serializer"),
],
),
Import(module="pdb"),
]
)
@ -294,12 +303,15 @@ class AfterGenerateClass:
else: # pragma: no cover - for completeness, shouldn't happen
cls.imports = DYNAMIC_TABLE_IMPORTS.model_copy()
elif cls.cls.name == "VectorData":
cls.cls.bases = ["VectorDataMixin"]
cls.cls.bases = ["VectorDataMixin[T]", "Generic[T]"]
# make ``value`` generic on T
if "value" in cls.cls.attributes:
cls.cls.attributes["value"].range = "Optional[T]"
elif cls.cls.name == "VectorIndex":
cls.cls.bases = ["VectorIndexMixin"]
cls.cls.bases = ["VectorIndexMixin[T]", "Generic[T]"]
# make ``value`` generic on T
if "value" in cls.cls.attributes:
cls.cls.attributes["value"].range = "Optional[T]"
elif cls.cls.name == "DynamicTableRegion":
cls.cls.bases = ["DynamicTableRegionMixin", "VectorData"]
elif cls.cls.name == "AlignedDynamicTable":

View file

@ -88,3 +88,17 @@ BASEMODEL_EXTRA_TO_VALUE = """
v["value"] = extras
return v
"""
BASEMODEL_SERIALIZER = """
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR":str(e), "TYPE": str(type(self))}
if 'Circular reference' in str(e):
return {"REFERENCE":"REFERENCE"}
pdb.set_trace()
json_dump_fields = ('indent', 'include', 'exclude', 'context', 'by_alias', 'exclude_unset', 'exclude_defaults', 'exclude_none', 'round_trip', 'warnings', 'serialize_as_any')
return self.model_dump_json(**{k:v for k,v in info.__dict__.items() if k in json_dump_fields})
"""

View file

@ -171,23 +171,7 @@ def _load_node(
del args[".specloc"]
model = provider.get_class(obj.attrs["namespace"], obj.attrs["neurodata_type"])
# try:
return model(**args)
# except ValidationError as e1:
# # try to restack extra fields into ``value``
# if "value" in model.model_fields:
# value_dict = {
# key: val for key, val in args.items() if key not in model.model_fields
# }
# for k in value_dict:
# del args[k]
# args["value"] = value_dict
# try:
# return model(**args)
# except Exception as e2:
# raise e2 from e1
# else:
# raise e1
else:
if "name" in args:

View file

@ -2,6 +2,7 @@
Placeholder test module to test reading from pynwb-generated NWB file
"""
import pdb
from datetime import datetime
import numpy as np
@ -11,6 +12,7 @@ from numpydantic.interface.hdf5 import H5Proxy
from pydantic import BaseModel
from pynwb import NWBHDF5IO
from pynwb import NWBFile as PyNWBFile
from pydantic_core import to_json
from nwb_linkml.io.hdf5 import HDF5IO
from nwb_models.models import NWBFile
@ -29,6 +31,13 @@ def test_read_from_nwbfile(nwb_file):
@pytest.fixture(scope="module")
def read_nwbfile(nwb_file) -> NWBFile:
res = HDF5IO(nwb_file).read()
def fallback(*args, **kwargs):
pdb.set_trace()
to_json(res, fallback=fallback)
pdb.set_trace()
return res
@ -63,6 +72,7 @@ def test_nwbfile_base(read_nwbfile, read_pynwb):
"""
Base attributes on top-level nwbfile are correct
"""
_compare_attrs(read_nwbfile, read_pynwb)

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -32,6 +33,7 @@ from pydantic import (
RootModel,
ValidationInfo,
field_validator,
model_serializer,
model_validator,
)
@ -134,6 +136,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import (
NWBDataInterface,
@ -115,6 +124,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -8,7 +9,15 @@ from enum import Enum
from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import NWBContainer
@ -108,6 +117,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -17,6 +18,7 @@ from pydantic import (
RootModel,
ValidationInfo,
field_validator,
model_serializer,
model_validator,
)
@ -126,6 +128,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -17,6 +18,7 @@ from pydantic import (
RootModel,
ValidationInfo,
field_validator,
model_serializer,
model_validator,
)
@ -124,6 +126,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import (
Images,
@ -137,6 +146,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -17,6 +18,7 @@ from pydantic import (
RootModel,
ValidationInfo,
field_validator,
model_serializer,
model_validator,
)
@ -133,6 +135,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import (
Image,
@ -116,6 +125,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -17,6 +18,7 @@ from pydantic import (
RootModel,
ValidationInfo,
field_validator,
model_serializer,
model_validator,
)
@ -126,6 +128,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import (
NWBContainer,
@ -115,6 +124,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -17,6 +18,7 @@ from pydantic import (
RootModel,
ValidationInfo,
field_validator,
model_serializer,
model_validator,
)
@ -133,6 +135,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import NWBDataInterface
@ -109,6 +118,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -8,7 +9,15 @@ from enum import Enum
from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...core.v2_7_0.core_nwb_base import (
Image,
@ -280,6 +289,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -8,7 +9,15 @@ from enum import Enum
from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
metamodel_version = "None"
@ -106,6 +115,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...hdmf_common.v1_8_0.hdmf_common_base import Container
@ -109,6 +118,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -32,6 +33,7 @@ from pydantic import (
ValidationInfo,
ValidatorFunctionWrapHandler,
field_validator,
model_serializer,
model_validator,
)
@ -133,6 +135,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}
@ -908,7 +936,7 @@ linkml_meta = LinkMLMeta(
)
class VectorData(VectorDataMixin):
class VectorData(VectorDataMixin[T], Generic[T]):
"""
An n-dimensional dataset representing a column of a DynamicTable. If used without an accompanying VectorIndex, first dimension is along the rows of the DynamicTable and each step along the first dimension is a cell of the larger table. VectorData can also be used to represent a ragged array if paired with a VectorIndex. This allows for storing arrays of varying length in a single cell of the DynamicTable by indexing into this VectorData. The first vector is at VectorData[0:VectorIndex[0]]. The second vector is at VectorData[VectorIndex[0]:VectorIndex[1]], and so on.
"""
@ -922,7 +950,7 @@ class VectorData(VectorDataMixin):
value: Optional[T] = Field(None)
class VectorIndex(VectorIndexMixin):
class VectorIndex(VectorIndexMixin[T], Generic[T]):
"""
Used with VectorData to encode a ragged array. An array of indices into the first dimension of the target VectorData, and forming a map between the rows of a DynamicTable and the indices of the VectorData. The name of the VectorIndex is expected to be the name of the target VectorData object followed by \"_index\".
"""
@ -936,14 +964,7 @@ class VectorIndex(VectorIndexMixin):
None, description="""Reference to the target dataset that this index applies to."""
)
description: str = Field(..., description="""Description of what these vectors represent.""")
value: Optional[
Union[
NDArray[Shape["* dim0"], Any],
NDArray[Shape["* dim0, * dim1"], Any],
NDArray[Shape["* dim0, * dim1, * dim2"], Any],
NDArray[Shape["* dim0, * dim1, * dim2, * dim3"], Any],
]
] = Field(None)
value: Optional[T] = Field(None)
class ElementIdentifiers(ElementIdentifiersMixin, Data):

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -8,7 +9,15 @@ from enum import Enum
from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...hdmf_common.v1_8_0.hdmf_common_base import Container, Data, SimpleMultiContainer
from ...hdmf_common.v1_8_0.hdmf_common_sparse import CSRMatrix
@ -117,6 +126,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...hdmf_common.v1_8_0.hdmf_common_table import VectorData
@ -109,6 +118,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -9,7 +10,15 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from numpydantic import NDArray, Shape
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...hdmf_common.v1_8_0.hdmf_common_base import Container, Data
@ -109,6 +118,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import pdb
import re
import sys
from datetime import date, datetime, time
@ -8,7 +9,15 @@ from enum import Enum
from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
import numpy as np
from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator, model_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
RootModel,
field_validator,
model_serializer,
model_validator,
)
from ...hdmf_common.v1_8_0.hdmf_common_base import Container, Data, SimpleMultiContainer
from ...hdmf_common.v1_8_0.hdmf_common_sparse import CSRMatrix
@ -127,6 +136,32 @@ class ConfiguredBaseModel(BaseModel):
v["value"] = extras
return v
@model_serializer(mode="wrap", when_used="json")
def serialize_model(self, nxt, info) -> Dict[str, Any]:
try:
return nxt(self, info)
except Exception as e:
return {"ERROR": str(e), "TYPE": str(type(self))}
if "Circular reference" in str(e):
return {"REFERENCE": "REFERENCE"}
pdb.set_trace()
json_dump_fields = (
"indent",
"include",
"exclude",
"context",
"by_alias",
"exclude_unset",
"exclude_defaults",
"exclude_none",
"round_trip",
"warnings",
"serialize_as_any",
)
return self.model_dump_json(
**{k: v for k, v in info.__dict__.items() if k in json_dump_fields}
)
class LinkMLMeta(RootModel):
root: Dict[str, Any] = {}

View file

@ -5,7 +5,7 @@ annotations:
value: 'False'
namespace:
tag: namespace
value: hdmf-experimental
value: core
description: Adapter objects to mimic the behavior of elements in the nwb-schema-language
id: nwb.language
imports:

View file

@ -5,7 +5,7 @@ annotations:
value: 'False'
namespace:
tag: namespace
value: hdmf-experimental
value: core
description: Adapter objects to mimic the behavior of elements in the nwb-schema-language
id: nwb.language
imports: