From 886d3db8604427d67bd0bfcc8fc4802c80fb2dbf Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Wed, 25 Sep 2024 22:58:02 -0700 Subject: [PATCH] model checkpoint before fixing group generation --- nwb_linkml/src/nwb_linkml/includes/base.py | 14 +- .../pydantic/core/v2_2_0/core_nwb_base.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_behavior.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_device.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_ecephys.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_file.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_icephys.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_image.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_misc.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_ogen.py | 19 ++- .../pydantic/core/v2_2_0/core_nwb_ophys.py | 19 ++- .../core/v2_2_0/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_2_0/namespace.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_base.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_behavior.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_device.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_ecephys.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_file.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_icephys.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_image.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_misc.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_ogen.py | 19 ++- .../pydantic/core/v2_2_1/core_nwb_ophys.py | 19 ++- .../core/v2_2_1/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_2_1/namespace.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_base.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_behavior.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_device.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_ecephys.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_file.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_icephys.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_image.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_misc.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_ogen.py | 19 ++- .../pydantic/core/v2_2_2/core_nwb_ophys.py | 19 ++- .../core/v2_2_2/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_2_2/namespace.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_base.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_behavior.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_device.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_ecephys.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_file.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_icephys.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_image.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_misc.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_ogen.py | 19 ++- .../pydantic/core/v2_2_4/core_nwb_ophys.py | 19 ++- .../core/v2_2_4/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_2_4/namespace.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_base.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_behavior.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_device.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_ecephys.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_file.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_icephys.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_image.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_misc.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_ogen.py | 19 ++- .../pydantic/core/v2_2_5/core_nwb_ophys.py | 19 ++- .../core/v2_2_5/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_2_5/namespace.py | 19 ++- .../pydantic/core/v2_3_0/core_nwb_base.py | 30 +++- .../pydantic/core/v2_3_0/core_nwb_behavior.py | 55 ++++++-- .../pydantic/core/v2_3_0/core_nwb_device.py | 19 ++- .../pydantic/core/v2_3_0/core_nwb_ecephys.py | 39 +++-- .../pydantic/core/v2_3_0/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_3_0/core_nwb_file.py | 19 ++- .../pydantic/core/v2_3_0/core_nwb_icephys.py | 29 +++- .../pydantic/core/v2_3_0/core_nwb_image.py | 33 +++-- .../pydantic/core/v2_3_0/core_nwb_misc.py | 49 ++++--- .../pydantic/core/v2_3_0/core_nwb_ogen.py | 21 ++- .../pydantic/core/v2_3_0/core_nwb_ophys.py | 38 ++++- .../core/v2_3_0/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_3_0/namespace.py | 19 ++- .../pydantic/core/v2_4_0/core_nwb_base.py | 32 ++++- .../pydantic/core/v2_4_0/core_nwb_behavior.py | 55 ++++++-- .../pydantic/core/v2_4_0/core_nwb_device.py | 19 ++- .../pydantic/core/v2_4_0/core_nwb_ecephys.py | 39 +++-- .../pydantic/core/v2_4_0/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_4_0/core_nwb_file.py | 19 ++- .../pydantic/core/v2_4_0/core_nwb_icephys.py | 33 ++++- .../pydantic/core/v2_4_0/core_nwb_image.py | 33 +++-- .../pydantic/core/v2_4_0/core_nwb_misc.py | 49 ++++--- .../pydantic/core/v2_4_0/core_nwb_ogen.py | 21 ++- .../pydantic/core/v2_4_0/core_nwb_ophys.py | 38 ++++- .../core/v2_4_0/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_4_0/namespace.py | 19 ++- .../pydantic/core/v2_5_0/core_nwb_base.py | 32 ++++- .../pydantic/core/v2_5_0/core_nwb_behavior.py | 59 ++++++-- .../pydantic/core/v2_5_0/core_nwb_device.py | 19 ++- .../pydantic/core/v2_5_0/core_nwb_ecephys.py | 39 +++-- .../pydantic/core/v2_5_0/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_5_0/core_nwb_file.py | 19 ++- .../pydantic/core/v2_5_0/core_nwb_icephys.py | 33 ++++- .../pydantic/core/v2_5_0/core_nwb_image.py | 33 +++-- .../pydantic/core/v2_5_0/core_nwb_misc.py | 49 ++++--- .../pydantic/core/v2_5_0/core_nwb_ogen.py | 21 ++- .../pydantic/core/v2_5_0/core_nwb_ophys.py | 38 ++++- .../core/v2_5_0/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_5_0/namespace.py | 19 ++- .../core/v2_6_0_alpha/core_nwb_base.py | 32 ++++- .../core/v2_6_0_alpha/core_nwb_behavior.py | 59 ++++++-- .../core/v2_6_0_alpha/core_nwb_device.py | 19 ++- .../core/v2_6_0_alpha/core_nwb_ecephys.py | 39 +++-- .../core/v2_6_0_alpha/core_nwb_epoch.py | 19 ++- .../core/v2_6_0_alpha/core_nwb_file.py | 19 ++- .../core/v2_6_0_alpha/core_nwb_icephys.py | 33 ++++- .../core/v2_6_0_alpha/core_nwb_image.py | 33 +++-- .../core/v2_6_0_alpha/core_nwb_misc.py | 49 ++++--- .../core/v2_6_0_alpha/core_nwb_ogen.py | 21 ++- .../core/v2_6_0_alpha/core_nwb_ophys.py | 38 ++++- .../core/v2_6_0_alpha/core_nwb_retinotopy.py | 19 ++- .../pydantic/core/v2_6_0_alpha/namespace.py | 19 ++- .../pydantic/core/v2_7_0/core_nwb_base.py | 32 ++++- .../pydantic/core/v2_7_0/core_nwb_behavior.py | 59 ++++++-- .../pydantic/core/v2_7_0/core_nwb_device.py | 19 ++- .../pydantic/core/v2_7_0/core_nwb_ecephys.py | 39 +++-- .../pydantic/core/v2_7_0/core_nwb_epoch.py | 19 ++- .../pydantic/core/v2_7_0/core_nwb_file.py | 19 ++- .../pydantic/core/v2_7_0/core_nwb_icephys.py | 33 ++++- .../pydantic/core/v2_7_0/core_nwb_image.py | 33 +++-- .../pydantic/core/v2_7_0/core_nwb_misc.py | 49 ++++--- .../pydantic/core/v2_7_0/core_nwb_ogen.py | 22 ++- .../pydantic/core/v2_7_0/core_nwb_ophys.py | 38 ++++- .../core/v2_7_0/core_nwb_retinotopy.py | 19 ++- .../models/pydantic/core/v2_7_0/namespace.py | 19 ++- .../models/pydantic/hdmf_common/__init__.py | 1 + .../hdmf_common/v1_1_0/hdmf_common_sparse.py | 21 ++- .../hdmf_common/v1_1_0/hdmf_common_table.py | 60 +++++--- .../pydantic/hdmf_common/v1_1_0/namespace.py | 21 ++- .../hdmf_common/v1_1_2/hdmf_common_sparse.py | 21 ++- .../hdmf_common/v1_1_2/hdmf_common_table.py | 60 +++++--- .../pydantic/hdmf_common/v1_1_2/namespace.py | 21 ++- .../hdmf_common/v1_1_3/hdmf_common_sparse.py | 21 ++- .../hdmf_common/v1_1_3/hdmf_common_table.py | 60 +++++--- .../pydantic/hdmf_common/v1_1_3/namespace.py | 21 ++- .../hdmf_common/v1_2_0/hdmf_common_base.py | 28 +++- .../hdmf_common/v1_2_0/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_2_0/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_2_0/namespace.py | 28 +++- .../hdmf_common/v1_2_1/hdmf_common_base.py | 28 +++- .../hdmf_common/v1_2_1/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_2_1/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_2_1/namespace.py | 28 +++- .../hdmf_common/v1_3_0/hdmf_common_base.py | 28 +++- .../v1_3_0/hdmf_common_resources.py | 28 +++- .../hdmf_common/v1_3_0/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_3_0/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_3_0/namespace.py | 28 +++- .../hdmf_common/v1_4_0/hdmf_common_base.py | 28 +++- .../hdmf_common/v1_4_0/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_4_0/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_4_0/namespace.py | 28 +++- .../hdmf_common/v1_5_0/hdmf_common_base.py | 23 ++- .../hdmf_common/v1_5_0/hdmf_common_sparse.py | 21 ++- .../hdmf_common/v1_5_0/hdmf_common_table.py | 66 ++++++--- .../pydantic/hdmf_common/v1_5_0/namespace.py | 21 ++- .../hdmf_common/v1_5_1/hdmf_common_base.py | 28 +++- .../hdmf_common/v1_5_1/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_5_1/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_5_1/namespace.py | 28 +++- .../hdmf_common/v1_6_0/hdmf_common_base.py | 28 +++- .../hdmf_common/v1_6_0/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_6_0/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_6_0/namespace.py | 28 +++- .../hdmf_common/v1_7_0/hdmf_common_base.py | 28 +++- .../hdmf_common/v1_7_0/hdmf_common_sparse.py | 28 +++- .../hdmf_common/v1_7_0/hdmf_common_table.py | 51 +++++-- .../pydantic/hdmf_common/v1_7_0/namespace.py | 28 +++- .../hdmf_common/v1_8_0/hdmf_common_base.py | 23 ++- .../hdmf_common/v1_8_0/hdmf_common_sparse.py | 21 ++- .../hdmf_common/v1_8_0/hdmf_common_table.py | 66 ++++++--- .../pydantic/hdmf_common/v1_8_0/namespace.py | 21 ++- .../v0_1_0/hdmf_experimental_experimental.py | 25 +++- .../v0_1_0/hdmf_experimental_resources.py | 25 +++- .../hdmf_experimental/v0_1_0/namespace.py | 28 +++- .../v0_2_0/hdmf_experimental_experimental.py | 28 +++- .../v0_2_0/hdmf_experimental_resources.py | 28 +++- .../hdmf_experimental/v0_2_0/namespace.py | 28 +++- .../v0_3_0/hdmf_experimental_experimental.py | 28 +++- .../v0_3_0/hdmf_experimental_resources.py | 28 +++- .../hdmf_experimental/v0_3_0/namespace.py | 28 +++- .../v0_4_0/hdmf_experimental_experimental.py | 28 +++- .../v0_4_0/hdmf_experimental_resources.py | 28 +++- .../hdmf_experimental/v0_4_0/namespace.py | 28 +++- .../v0_5_0/hdmf_experimental_experimental.py | 21 ++- .../v0_5_0/hdmf_experimental_resources.py | 21 ++- .../hdmf_experimental/v0_5_0/namespace.py | 21 ++- .../linkml/core/v2_3_0/core.nwb.base.yaml | 25 +++- .../linkml/core/v2_3_0/core.nwb.behavior.yaml | 133 ++++++++++++------ .../linkml/core/v2_3_0/core.nwb.ecephys.yaml | 57 +++++--- .../linkml/core/v2_3_0/core.nwb.language.yaml | 1 + .../linkml/core/v2_3_0/core.nwb.ophys.yaml | 76 ++++++---- .../linkml/core/v2_4_0/core.nwb.base.yaml | 25 +++- .../linkml/core/v2_4_0/core.nwb.behavior.yaml | 133 ++++++++++++------ .../linkml/core/v2_4_0/core.nwb.ecephys.yaml | 57 +++++--- .../linkml/core/v2_4_0/core.nwb.language.yaml | 1 + .../linkml/core/v2_4_0/core.nwb.ophys.yaml | 76 ++++++---- .../linkml/core/v2_5_0/core.nwb.base.yaml | 25 +++- .../linkml/core/v2_5_0/core.nwb.behavior.yaml | 133 ++++++++++++------ .../linkml/core/v2_5_0/core.nwb.ecephys.yaml | 57 +++++--- .../linkml/core/v2_5_0/core.nwb.language.yaml | 1 + .../linkml/core/v2_5_0/core.nwb.ophys.yaml | 76 ++++++---- .../core/v2_6_0_alpha/core.nwb.base.yaml | 25 +++- .../core/v2_6_0_alpha/core.nwb.behavior.yaml | 133 ++++++++++++------ .../core/v2_6_0_alpha/core.nwb.ecephys.yaml | 57 +++++--- .../core/v2_6_0_alpha/core.nwb.language.yaml | 1 + .../core/v2_6_0_alpha/core.nwb.ophys.yaml | 76 ++++++---- .../linkml/core/v2_7_0/core.nwb.base.yaml | 25 +++- .../linkml/core/v2_7_0/core.nwb.behavior.yaml | 133 ++++++++++++------ .../linkml/core/v2_7_0/core.nwb.ecephys.yaml | 57 +++++--- .../linkml/core/v2_7_0/core.nwb.language.yaml | 1 + .../linkml/core/v2_7_0/core.nwb.ophys.yaml | 76 ++++++---- .../v1_4_0/hdmf-common.nwb.language.yaml | 1 + .../hdmf_common/v1_5_0/hdmf-common.base.yaml | 18 ++- .../v1_5_0/hdmf-common.nwb.language.yaml | 3 +- .../hdmf_common/v1_5_0/hdmf-common.table.yaml | 28 +++- .../v1_5_1/hdmf-common.nwb.language.yaml | 1 + .../v1_6_0/hdmf-common.nwb.language.yaml | 1 + .../v1_7_0/hdmf-common.nwb.language.yaml | 1 + .../hdmf_common/v1_8_0/hdmf-common.base.yaml | 18 ++- .../v1_8_0/hdmf-common.nwb.language.yaml | 3 +- .../hdmf_common/v1_8_0/hdmf-common.table.yaml | 28 +++- .../hdmf-experimental.experimental.yaml | 2 +- .../hdmf-experimental.nwb.language.yaml | 3 +- .../v0_1_0/hdmf-experimental.resources.yaml | 2 +- .../hdmf-experimental.nwb.language.yaml | 1 + .../hdmf-experimental.nwb.language.yaml | 1 + .../hdmf-experimental.nwb.language.yaml | 1 + .../hdmf-experimental.nwb.language.yaml | 3 +- 235 files changed, 5356 insertions(+), 1385 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/includes/base.py b/nwb_linkml/src/nwb_linkml/includes/base.py index 2a6e84d..c081587 100644 --- a/nwb_linkml/src/nwb_linkml/includes/base.py +++ b/nwb_linkml/src/nwb_linkml/includes/base.py @@ -27,12 +27,7 @@ BASEMODEL_COERCE_VALUE = """ try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise ValueError( - f"coerce_value: Could not use the value field of {type(v)} " - f"to construct {cls.__name__}.{info.field_name}, " - f"expected type: {cls.model_fields[info.field_name].annotation}\\n" - f"inner error: {str(e1)}" - ) from e1 + raise e1 """ BASEMODEL_CAST_WITH_VALUE = """ @@ -46,12 +41,7 @@ BASEMODEL_CAST_WITH_VALUE = """ try: return handler({"value": v}) except Exception: - raise ValueError( - f"cast_with_value: Could not cast {type(v)} as value field for " - f"{cls.__name__}.{info.field_name}," - f" expected_type: {cls.model_fields[info.field_name].annotation}\\n" - f"inner error: {str(e1)}" - ) from e1 + raise e1 """ BASEMODEL_COERCE_CHILD = """ diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_base.py index 3a7121f..0aca06c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_base.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_behavior.py index 3cdb697..5136ecd 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_device.py index 35e469e..c08c6ff 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ecephys.py index 50c35df..42d8653 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_epoch.py index d9e8670..3eef400 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_file.py index 574b467..613b948 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_file.py @@ -61,7 +61,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -74,6 +74,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -84,7 +96,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_icephys.py index c118384..be65250 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_icephys.py @@ -63,7 +63,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -76,6 +76,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -86,7 +98,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_image.py index 1f4d01f..8185f44 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_image.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_misc.py index 97cc604..e7e1279 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ogen.py index 1fec83c..100fc9b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ophys.py index 587c4a8..a8f98a2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_ophys.py @@ -60,7 +60,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -73,6 +73,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -83,7 +95,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_retinotopy.py index 66760ac..718a1c6 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/core_nwb_retinotopy.py @@ -52,7 +52,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -65,6 +65,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -75,7 +87,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/namespace.py index 39065e8..92e7d3e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_0/namespace.py @@ -170,7 +170,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -183,6 +183,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -193,7 +205,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_base.py index d509055..d92282c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_base.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_behavior.py index 9520fc7..2c853af 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_device.py index c6c0821..b1b1b16 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ecephys.py index 59392d2..f74a7e7 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_epoch.py index 6b07a73..7f4bb40 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_file.py index bb40dc6..b203b9b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_file.py @@ -61,7 +61,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -74,6 +74,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -84,7 +96,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_icephys.py index e55e757..772841e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_icephys.py @@ -63,7 +63,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -76,6 +76,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -86,7 +98,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_image.py index ee1b247..5e824fa 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_image.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_misc.py index 4ccb41a..e212e58 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ogen.py index c26180e..81dcca7 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ophys.py index 27ca8a7..e054ec2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_ophys.py @@ -60,7 +60,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -73,6 +73,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -83,7 +95,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_retinotopy.py index 8b286c0..0b7b720 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/core_nwb_retinotopy.py @@ -52,7 +52,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -65,6 +65,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -75,7 +87,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/namespace.py index 1000273..228bdac 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_1/namespace.py @@ -170,7 +170,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -183,6 +183,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -193,7 +205,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_base.py index 1608518..d2b5e5c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_base.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_behavior.py index 7a295d0..0935da2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_device.py index 952fd14..4aa5ede 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ecephys.py index 678627d..4336705 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_epoch.py index 4398b2e..7731ed5 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_file.py index a754163..f694d2c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_file.py @@ -61,7 +61,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -74,6 +74,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -84,7 +96,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_icephys.py index 7e8e860..4858631 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_icephys.py @@ -63,7 +63,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -76,6 +76,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -86,7 +98,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_image.py index c6a1bdf..56bc5e9 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_image.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_misc.py index 6ebbb31..59564fe 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ogen.py index d8706fb..36196b3 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ophys.py index 9355878..f2b41df 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_ophys.py @@ -60,7 +60,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -73,6 +73,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -83,7 +95,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_retinotopy.py index 4a6bba8..3f6e756 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/namespace.py index 68aa1ca..b89e5a5 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_2/namespace.py @@ -173,7 +173,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -186,6 +186,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -196,7 +208,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_base.py index 79dbd8e..b163e24 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_base.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_behavior.py index d8c8111..5bcab66 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_device.py index bd4959b..f370d51 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ecephys.py index d5ca311..f28980b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_epoch.py index 7d0e888..cb37363 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_file.py index ffc9887..8172d22 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_file.py @@ -62,7 +62,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -75,6 +75,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -85,7 +97,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_icephys.py index 944696c..4c5a2cf 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_icephys.py @@ -63,7 +63,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -76,6 +76,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -86,7 +98,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_image.py index ec713bb..bf08d2b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_image.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_misc.py index 6fb5183..f98882b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ogen.py index 959ec53..38f8335 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ophys.py index f8b39ac..1199e61 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_ophys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_retinotopy.py index 271df8c..0af340d 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/namespace.py index ba443d7..69651fd 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_4/namespace.py @@ -180,7 +180,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -193,6 +193,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -203,7 +215,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_base.py index 14986e7..3afefe9 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_base.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_behavior.py index 686f581..f6ae2e5 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_device.py index cc5f2a1..eec3289 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ecephys.py index 78d83f8..90b585e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_epoch.py index 69289cd..71eeb95 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_file.py index 2a7b510..6648e37 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_file.py @@ -62,7 +62,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -75,6 +75,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -85,7 +97,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_icephys.py index 4d04eec..403fec4 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_icephys.py @@ -63,7 +63,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -76,6 +76,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -86,7 +98,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_image.py index 22bc4dc..9c670dd 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_image.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_misc.py index 2730432..e73895a 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ogen.py index 7a31e4c..8c8b746 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ophys.py index f7e0674..a31241c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_ophys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_retinotopy.py index 5594f52..5d13706 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/namespace.py index 4f78598..6be8c81 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_2_5/namespace.py @@ -180,7 +180,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -193,6 +193,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -203,7 +215,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_base.py index 0450a89..5f82fcd 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_base.py @@ -44,7 +44,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -57,6 +57,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -67,7 +79,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -138,9 +153,9 @@ class Image(NWBData): description: Optional[str] = Field(None, description="""Description of the image.""") value: Optional[ Union[ - NDArray[Shape["* x, * y"], float], - NDArray[Shape["* x, * y, 3 r_g_b"], float], - NDArray[Shape["* x, * y, 4 r_g_b_a"], float], + NDArray[Shape["* x, * y"], float | int], + NDArray[Shape["* x, * y, 3 r_g_b"], float | int], + NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int], ] ] = Field(None) @@ -305,13 +320,16 @@ class ProcessingModule(NWBContainer): {"from_schema": "core.nwb.base", "tree_root": True} ) + name: str = Field(...) + description: str = Field( + ..., description="""Description of this collection of processed data.""" + ) value: Optional[Dict[str, Union[DynamicTable, NWBDataInterface]]] = Field( None, json_schema_extra={ "linkml_meta": {"any_of": [{"range": "NWBDataInterface"}, {"range": "DynamicTable"}]} }, ) - name: str = Field(...) class Images(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_behavior.py index fbf64a4..afb8921 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -197,8 +212,8 @@ class SpatialSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -212,10 +227,13 @@ class BehavioralEpochs(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEpochs", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEpochs)"}}, + ) value: Optional[Dict[str, IntervalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "IntervalSeries"}]}} ) - name: str = Field(...) class BehavioralEvents(NWBDataInterface): @@ -227,10 +245,13 @@ class BehavioralEvents(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEvents", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEvents)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class BehavioralTimeSeries(NWBDataInterface): @@ -242,10 +263,13 @@ class BehavioralTimeSeries(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralTimeSeries", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralTimeSeries)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class PupilTracking(NWBDataInterface): @@ -257,10 +281,12 @@ class PupilTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "PupilTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(PupilTracking)"}} + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class EyeTracking(NWBDataInterface): @@ -272,10 +298,12 @@ class EyeTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "EyeTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(EyeTracking)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class CompassDirection(NWBDataInterface): @@ -287,10 +315,13 @@ class CompassDirection(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "CompassDirection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(CompassDirection)"}}, + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class Position(NWBDataInterface): @@ -302,10 +333,12 @@ class Position(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "Position", json_schema_extra={"linkml_meta": {"ifabsent": "string(Position)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_device.py index 08d5073..2fc40f2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ecephys.py index 6630b23..6af7ff2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -243,9 +258,9 @@ class ElectricalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_channels"], float], - NDArray[Shape["* num_times, * num_channels, * num_samples"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_channels"], float | int], + NDArray[Shape["* num_times, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -351,8 +366,8 @@ class SpikeEventSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_events, * num_samples"], float], - NDArray[Shape["* num_events, * num_channels, * num_samples"], float], + NDArray[Shape["* num_events, * num_samples"], float | int], + NDArray[Shape["* num_events, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -455,10 +470,12 @@ class EventWaveform(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "EventWaveform", json_schema_extra={"linkml_meta": {"ifabsent": "string(EventWaveform)"}} + ) value: Optional[Dict[str, SpikeEventSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpikeEventSeries"}]}} ) - name: str = Field(...) class FilteredEphys(NWBDataInterface): @@ -470,10 +487,12 @@ class FilteredEphys(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "FilteredEphys", json_schema_extra={"linkml_meta": {"ifabsent": "string(FilteredEphys)"}} + ) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class LFP(NWBDataInterface): @@ -485,10 +504,10 @@ class LFP(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field("LFP", json_schema_extra={"linkml_meta": {"ifabsent": "string(LFP)"}}) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class ElectrodeGroup(NWBContainer): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_epoch.py index 96ec1a4..0a22431 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_file.py index 7cb5cb1..13d67cb 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_file.py @@ -62,7 +62,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -75,6 +75,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -85,7 +97,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_icephys.py index 6be9e7e..6094a09 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_icephys.py @@ -63,7 +63,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -76,6 +76,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -86,7 +98,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -242,7 +257,7 @@ class PatchClampSeriesData(ConfiguredBaseModel): ..., description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -349,7 +364,7 @@ class CurrentClampSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -527,7 +542,7 @@ class CurrentClampStimulusSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -704,7 +719,7 @@ class VoltageClampSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -932,7 +947,7 @@ class VoltageClampStimulusSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_image.py index b080a46..4964397 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_image.py @@ -44,7 +44,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -57,6 +57,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -67,7 +79,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -116,7 +131,7 @@ class GrayscaleImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": {"array": {"dimensions": [{"alias": "x"}, {"alias": "y"}]}} @@ -138,7 +153,7 @@ class RGBImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -168,7 +183,7 @@ class RGBAImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -292,8 +307,8 @@ class ImageSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, * z"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, * z"], float | int], ] ] = Field(None) @@ -518,8 +533,8 @@ class OpticalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float | int], ] ] = Field(None) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_misc.py index 90ee48e..95576ab 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -234,8 +249,8 @@ class AbstractFeatureSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -520,19 +535,21 @@ class DecompositionSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"ifabsent": "string(no unit)"}}, ) - value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float]] = Field( - None, - json_schema_extra={ - "linkml_meta": { - "array": { - "dimensions": [ - {"alias": "num_times"}, - {"alias": "num_channels"}, - {"alias": "num_bands"}, - ] + value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float | int]] = ( + Field( + None, + json_schema_extra={ + "linkml_meta": { + "array": { + "dimensions": [ + {"alias": "num_times"}, + {"alias": "num_channels"}, + {"alias": "num_bands"}, + ] + } } - } - }, + }, + ) ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ogen.py index e55129b..e66477e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -200,7 +215,7 @@ class OptogeneticSeriesData(ConfiguredBaseModel): description="""Unit of measurement for data, which is fixed to 'watts'.""", json_schema_extra={"linkml_meta": {"equals_string": "watts", "ifabsent": "string(watts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ophys.py index f6eb103..6813220 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_ophys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -333,7 +348,8 @@ class RoiResponseSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], NDArray[Shape["* num_times, * num_rois"], float] + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_rois"], float | int], ] ] = Field(None) @@ -347,10 +363,10 @@ class DfOverF(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field("DfOverF", json_schema_extra={"linkml_meta": {"ifabsent": "string(DfOverF)"}}) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class Fluorescence(NWBDataInterface): @@ -362,10 +378,12 @@ class Fluorescence(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "Fluorescence", json_schema_extra={"linkml_meta": {"ifabsent": "string(Fluorescence)"}} + ) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class ImageSegmentation(NWBDataInterface): @@ -377,10 +395,13 @@ class ImageSegmentation(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "ImageSegmentation", + json_schema_extra={"linkml_meta": {"ifabsent": "string(ImageSegmentation)"}}, + ) value: Optional[Dict[str, PlaneSegmentation]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "PlaneSegmentation"}]}} ) - name: str = Field(...) class PlaneSegmentation(DynamicTable): @@ -696,10 +717,13 @@ class MotionCorrection(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "MotionCorrection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(MotionCorrection)"}}, + ) value: Optional[Dict[str, CorrectedImageStack]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "CorrectedImageStack"}]}} ) - name: str = Field(...) class CorrectedImageStack(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_retinotopy.py index 38f2e67..67ebc9b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/namespace.py index a0842a1..c562bb8 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_3_0/namespace.py @@ -197,7 +197,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -210,6 +210,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -220,7 +232,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_base.py index 0948248..a3f929e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_base.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -109,7 +124,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -333,9 +348,9 @@ class Image(NWBData): description: Optional[str] = Field(None, description="""Description of the image.""") value: Optional[ Union[ - NDArray[Shape["* x, * y"], float], - NDArray[Shape["* x, * y, 3 r_g_b"], float], - NDArray[Shape["* x, * y, 4 r_g_b_a"], float], + NDArray[Shape["* x, * y"], float | int], + NDArray[Shape["* x, * y, 3 r_g_b"], float | int], + NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int], ] ] = Field(None) @@ -500,13 +515,16 @@ class ProcessingModule(NWBContainer): {"from_schema": "core.nwb.base", "tree_root": True} ) + name: str = Field(...) + description: str = Field( + ..., description="""Description of this collection of processed data.""" + ) value: Optional[Dict[str, Union[DynamicTable, NWBDataInterface]]] = Field( None, json_schema_extra={ "linkml_meta": {"any_of": [{"range": "NWBDataInterface"}, {"range": "DynamicTable"}]} }, ) - name: str = Field(...) class Images(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_behavior.py index 074546e..7a46192 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -197,8 +212,8 @@ class SpatialSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -212,10 +227,13 @@ class BehavioralEpochs(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEpochs", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEpochs)"}}, + ) value: Optional[Dict[str, IntervalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "IntervalSeries"}]}} ) - name: str = Field(...) class BehavioralEvents(NWBDataInterface): @@ -227,10 +245,13 @@ class BehavioralEvents(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEvents", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEvents)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class BehavioralTimeSeries(NWBDataInterface): @@ -242,10 +263,13 @@ class BehavioralTimeSeries(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralTimeSeries", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralTimeSeries)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class PupilTracking(NWBDataInterface): @@ -257,10 +281,12 @@ class PupilTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "PupilTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(PupilTracking)"}} + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class EyeTracking(NWBDataInterface): @@ -272,10 +298,12 @@ class EyeTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "EyeTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(EyeTracking)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class CompassDirection(NWBDataInterface): @@ -287,10 +315,13 @@ class CompassDirection(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "CompassDirection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(CompassDirection)"}}, + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class Position(NWBDataInterface): @@ -302,10 +333,12 @@ class Position(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "Position", json_schema_extra={"linkml_meta": {"ifabsent": "string(Position)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_device.py index c253e9e..9510135 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ecephys.py index 64c0ab0..44503f1 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -243,9 +258,9 @@ class ElectricalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_channels"], float], - NDArray[Shape["* num_times, * num_channels, * num_samples"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_channels"], float | int], + NDArray[Shape["* num_times, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -351,8 +366,8 @@ class SpikeEventSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_events, * num_samples"], float], - NDArray[Shape["* num_events, * num_channels, * num_samples"], float], + NDArray[Shape["* num_events, * num_samples"], float | int], + NDArray[Shape["* num_events, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -455,10 +470,12 @@ class EventWaveform(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "EventWaveform", json_schema_extra={"linkml_meta": {"ifabsent": "string(EventWaveform)"}} + ) value: Optional[Dict[str, SpikeEventSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpikeEventSeries"}]}} ) - name: str = Field(...) class FilteredEphys(NWBDataInterface): @@ -470,10 +487,12 @@ class FilteredEphys(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "FilteredEphys", json_schema_extra={"linkml_meta": {"ifabsent": "string(FilteredEphys)"}} + ) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class LFP(NWBDataInterface): @@ -485,10 +504,10 @@ class LFP(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field("LFP", json_schema_extra={"linkml_meta": {"ifabsent": "string(LFP)"}}) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class ElectrodeGroup(NWBContainer): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_epoch.py index 6904077..1c1b5ef 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_file.py index c92a64b..26bd1fa 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_file.py @@ -70,7 +70,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -83,6 +83,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -93,7 +105,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_icephys.py index 0fd2950..d6191fa 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_icephys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -245,7 +260,7 @@ class PatchClampSeriesData(ConfiguredBaseModel): ..., description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -352,7 +367,7 @@ class CurrentClampSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -530,7 +545,7 @@ class CurrentClampStimulusSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -707,7 +722,7 @@ class VoltageClampSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -935,7 +950,7 @@ class VoltageClampStimulusSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -1204,6 +1219,10 @@ class IntracellularRecordingsTable(AlignedDynamicTable): stimuli: IntracellularStimuliTable = Field( ..., description="""Table for storing intracellular stimulus related metadata.""" ) + categories: List[str] = Field( + ..., + description="""The names of the categories in this AlignedDynamicTable. Each category is represented by one DynamicTable stored in the parent group. This attribute should be used to specify an order of categories and the category names must match the names of the corresponding DynamicTable in the group.""", + ) value: Optional[Dict[str, DynamicTable]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "DynamicTable"}]}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_image.py index 10a1d92..1ed0f7f 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_image.py @@ -44,7 +44,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -57,6 +57,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -67,7 +79,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -116,7 +131,7 @@ class GrayscaleImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": {"array": {"dimensions": [{"alias": "x"}, {"alias": "y"}]}} @@ -138,7 +153,7 @@ class RGBImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -168,7 +183,7 @@ class RGBAImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -293,8 +308,8 @@ class ImageSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, * z"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, * z"], float | int], ] ] = Field(None) @@ -520,8 +535,8 @@ class OpticalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float | int], ] ] = Field(None) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_misc.py index 3ccb411..4f4825b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -234,8 +249,8 @@ class AbstractFeatureSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -520,19 +535,21 @@ class DecompositionSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"ifabsent": "string(no unit)"}}, ) - value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float]] = Field( - None, - json_schema_extra={ - "linkml_meta": { - "array": { - "dimensions": [ - {"alias": "num_times"}, - {"alias": "num_channels"}, - {"alias": "num_bands"}, - ] + value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float | int]] = ( + Field( + None, + json_schema_extra={ + "linkml_meta": { + "array": { + "dimensions": [ + {"alias": "num_times"}, + {"alias": "num_channels"}, + {"alias": "num_bands"}, + ] + } } - } - }, + }, + ) ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ogen.py index bddf0ea..64478a5 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -200,7 +215,7 @@ class OptogeneticSeriesData(ConfiguredBaseModel): description="""Unit of measurement for data, which is fixed to 'watts'.""", json_schema_extra={"linkml_meta": {"equals_string": "watts", "ifabsent": "string(watts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ophys.py index 73f8fcd..6e69afa 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_ophys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -334,7 +349,8 @@ class RoiResponseSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], NDArray[Shape["* num_times, * num_rois"], float] + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_rois"], float | int], ] ] = Field(None) @@ -348,10 +364,10 @@ class DfOverF(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field("DfOverF", json_schema_extra={"linkml_meta": {"ifabsent": "string(DfOverF)"}}) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class Fluorescence(NWBDataInterface): @@ -363,10 +379,12 @@ class Fluorescence(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "Fluorescence", json_schema_extra={"linkml_meta": {"ifabsent": "string(Fluorescence)"}} + ) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class ImageSegmentation(NWBDataInterface): @@ -378,10 +396,13 @@ class ImageSegmentation(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "ImageSegmentation", + json_schema_extra={"linkml_meta": {"ifabsent": "string(ImageSegmentation)"}}, + ) value: Optional[Dict[str, PlaneSegmentation]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "PlaneSegmentation"}]}} ) - name: str = Field(...) class PlaneSegmentation(DynamicTable): @@ -697,10 +718,13 @@ class MotionCorrection(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "MotionCorrection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(MotionCorrection)"}}, + ) value: Optional[Dict[str, CorrectedImageStack]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "CorrectedImageStack"}]}} ) - name: str = Field(...) class CorrectedImageStack(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_retinotopy.py index 60f8b4c..3024bed 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/namespace.py index 775c660..2055051 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_4_0/namespace.py @@ -210,7 +210,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -223,6 +223,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -233,7 +245,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_base.py index 7dcc142..abb0545 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_base.py @@ -68,7 +68,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -81,6 +81,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -91,7 +103,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -120,7 +135,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -359,9 +374,9 @@ class Image(NWBData): description: Optional[str] = Field(None, description="""Description of the image.""") value: Optional[ Union[ - NDArray[Shape["* x, * y"], float], - NDArray[Shape["* x, * y, 3 r_g_b"], float], - NDArray[Shape["* x, * y, 4 r_g_b_a"], float], + NDArray[Shape["* x, * y"], float | int], + NDArray[Shape["* x, * y, 3 r_g_b"], float | int], + NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int], ] ] = Field(None) @@ -551,13 +566,16 @@ class ProcessingModule(NWBContainer): {"from_schema": "core.nwb.base", "tree_root": True} ) + name: str = Field(...) + description: str = Field( + ..., description="""Description of this collection of processed data.""" + ) value: Optional[Dict[str, Union[DynamicTable, NWBDataInterface]]] = Field( None, json_schema_extra={ "linkml_meta": {"any_of": [{"range": "NWBDataInterface"}, {"range": "DynamicTable"}]} }, ) - name: str = Field(...) class Images(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_behavior.py index cfa3239..3df8abe 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -201,10 +216,10 @@ class SpatialSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, 1 x"], float], - NDArray[Shape["* num_times, 2 x_y"], float], - NDArray[Shape["* num_times, 3 x_y_z"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, 1 x"], float | int], + NDArray[Shape["* num_times, 2 x_y"], float | int], + NDArray[Shape["* num_times, 3 x_y_z"], float | int], ] ] = Field(None) @@ -218,10 +233,13 @@ class BehavioralEpochs(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEpochs", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEpochs)"}}, + ) value: Optional[Dict[str, IntervalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "IntervalSeries"}]}} ) - name: str = Field(...) class BehavioralEvents(NWBDataInterface): @@ -233,10 +251,13 @@ class BehavioralEvents(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEvents", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEvents)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class BehavioralTimeSeries(NWBDataInterface): @@ -248,10 +269,13 @@ class BehavioralTimeSeries(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralTimeSeries", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralTimeSeries)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class PupilTracking(NWBDataInterface): @@ -263,10 +287,12 @@ class PupilTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "PupilTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(PupilTracking)"}} + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class EyeTracking(NWBDataInterface): @@ -278,10 +304,12 @@ class EyeTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "EyeTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(EyeTracking)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class CompassDirection(NWBDataInterface): @@ -293,10 +321,13 @@ class CompassDirection(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "CompassDirection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(CompassDirection)"}}, + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class Position(NWBDataInterface): @@ -308,10 +339,12 @@ class Position(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "Position", json_schema_extra={"linkml_meta": {"ifabsent": "string(Position)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_device.py index b52ccd6..6ac30a8 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ecephys.py index 0fa24fc..eec63d7 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -247,9 +262,9 @@ class ElectricalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_channels"], float], - NDArray[Shape["* num_times, * num_channels, * num_samples"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_channels"], float | int], + NDArray[Shape["* num_times, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -359,8 +374,8 @@ class SpikeEventSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_events, * num_samples"], float], - NDArray[Shape["* num_events, * num_channels, * num_samples"], float], + NDArray[Shape["* num_events, * num_samples"], float | int], + NDArray[Shape["* num_events, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -463,10 +478,12 @@ class EventWaveform(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "EventWaveform", json_schema_extra={"linkml_meta": {"ifabsent": "string(EventWaveform)"}} + ) value: Optional[Dict[str, SpikeEventSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpikeEventSeries"}]}} ) - name: str = Field(...) class FilteredEphys(NWBDataInterface): @@ -478,10 +495,12 @@ class FilteredEphys(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "FilteredEphys", json_schema_extra={"linkml_meta": {"ifabsent": "string(FilteredEphys)"}} + ) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class LFP(NWBDataInterface): @@ -493,10 +512,10 @@ class LFP(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field("LFP", json_schema_extra={"linkml_meta": {"ifabsent": "string(LFP)"}}) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class ElectrodeGroup(NWBContainer): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_epoch.py index 94de21c..39d2d4f 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_file.py index d0e41d7..338a1cb 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_file.py @@ -71,7 +71,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -84,6 +84,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -94,7 +106,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_icephys.py index baaa066..5628183 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_icephys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -249,7 +264,7 @@ class PatchClampSeriesData(ConfiguredBaseModel): ..., description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -360,7 +375,7 @@ class CurrentClampSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -542,7 +557,7 @@ class CurrentClampStimulusSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -723,7 +738,7 @@ class VoltageClampSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -955,7 +970,7 @@ class VoltageClampStimulusSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -1225,6 +1240,10 @@ class IntracellularRecordingsTable(AlignedDynamicTable): stimuli: IntracellularStimuliTable = Field( ..., description="""Table for storing intracellular stimulus related metadata.""" ) + categories: List[str] = Field( + ..., + description="""The names of the categories in this AlignedDynamicTable. Each category is represented by one DynamicTable stored in the parent group. This attribute should be used to specify an order of categories and the category names must match the names of the corresponding DynamicTable in the group.""", + ) value: Optional[Dict[str, DynamicTable]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "DynamicTable"}]}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_image.py index 4b9edee..4d62c19 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_image.py @@ -50,7 +50,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -63,6 +63,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -73,7 +85,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -122,7 +137,7 @@ class GrayscaleImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": {"array": {"dimensions": [{"alias": "x"}, {"alias": "y"}]}} @@ -144,7 +159,7 @@ class RGBImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -174,7 +189,7 @@ class RGBAImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -303,8 +318,8 @@ class ImageSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, * z"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, * z"], float | int], ] ] = Field(None) @@ -534,8 +549,8 @@ class OpticalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float | int], ] ] = Field(None) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_misc.py index 5646cd8..13bfb53 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -238,8 +253,8 @@ class AbstractFeatureSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -536,19 +551,21 @@ class DecompositionSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"ifabsent": "string(no unit)"}}, ) - value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float]] = Field( - None, - json_schema_extra={ - "linkml_meta": { - "array": { - "dimensions": [ - {"alias": "num_times"}, - {"alias": "num_channels"}, - {"alias": "num_bands"}, - ] + value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float | int]] = ( + Field( + None, + json_schema_extra={ + "linkml_meta": { + "array": { + "dimensions": [ + {"alias": "num_times"}, + {"alias": "num_channels"}, + {"alias": "num_bands"}, + ] + } } - } - }, + }, + ) ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ogen.py index 29938d6..724bd92 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -204,7 +219,7 @@ class OptogeneticSeriesData(ConfiguredBaseModel): description="""Unit of measurement for data, which is fixed to 'watts'.""", json_schema_extra={"linkml_meta": {"equals_string": "watts", "ifabsent": "string(watts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ophys.py index ba37576..78e9c62 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_ophys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -338,7 +353,8 @@ class RoiResponseSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], NDArray[Shape["* num_times, * num_rois"], float] + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_rois"], float | int], ] ] = Field(None) @@ -352,10 +368,10 @@ class DfOverF(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field("DfOverF", json_schema_extra={"linkml_meta": {"ifabsent": "string(DfOverF)"}}) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class Fluorescence(NWBDataInterface): @@ -367,10 +383,12 @@ class Fluorescence(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "Fluorescence", json_schema_extra={"linkml_meta": {"ifabsent": "string(Fluorescence)"}} + ) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class ImageSegmentation(NWBDataInterface): @@ -382,10 +400,13 @@ class ImageSegmentation(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "ImageSegmentation", + json_schema_extra={"linkml_meta": {"ifabsent": "string(ImageSegmentation)"}}, + ) value: Optional[Dict[str, PlaneSegmentation]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "PlaneSegmentation"}]}} ) - name: str = Field(...) class PlaneSegmentation(DynamicTable): @@ -701,10 +722,13 @@ class MotionCorrection(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "MotionCorrection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(MotionCorrection)"}}, + ) value: Optional[Dict[str, CorrectedImageStack]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "CorrectedImageStack"}]}} ) - name: str = Field(...) class CorrectedImageStack(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_retinotopy.py index 82f1e30..f886ffc 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/namespace.py index ff571fa..08d0b93 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_5_0/namespace.py @@ -211,7 +211,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -224,6 +224,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -234,7 +246,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py index 1881de9..5a1224a 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py @@ -68,7 +68,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -81,6 +81,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -91,7 +103,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -120,7 +135,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -359,9 +374,9 @@ class Image(NWBData): description: Optional[str] = Field(None, description="""Description of the image.""") value: Optional[ Union[ - NDArray[Shape["* x, * y"], float], - NDArray[Shape["* x, * y, 3 r_g_b"], float], - NDArray[Shape["* x, * y, 4 r_g_b_a"], float], + NDArray[Shape["* x, * y"], float | int], + NDArray[Shape["* x, * y, 3 r_g_b"], float | int], + NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int], ] ] = Field(None) @@ -551,13 +566,16 @@ class ProcessingModule(NWBContainer): {"from_schema": "core.nwb.base", "tree_root": True} ) + name: str = Field(...) + description: str = Field( + ..., description="""Description of this collection of processed data.""" + ) value: Optional[Dict[str, Union[DynamicTable, NWBDataInterface]]] = Field( None, json_schema_extra={ "linkml_meta": {"any_of": [{"range": "NWBDataInterface"}, {"range": "DynamicTable"}]} }, ) - name: str = Field(...) class Images(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_behavior.py index 9a19768..2abebb7 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -201,10 +216,10 @@ class SpatialSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, 1 x"], float], - NDArray[Shape["* num_times, 2 x_y"], float], - NDArray[Shape["* num_times, 3 x_y_z"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, 1 x"], float | int], + NDArray[Shape["* num_times, 2 x_y"], float | int], + NDArray[Shape["* num_times, 3 x_y_z"], float | int], ] ] = Field(None) @@ -218,10 +233,13 @@ class BehavioralEpochs(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEpochs", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEpochs)"}}, + ) value: Optional[Dict[str, IntervalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "IntervalSeries"}]}} ) - name: str = Field(...) class BehavioralEvents(NWBDataInterface): @@ -233,10 +251,13 @@ class BehavioralEvents(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEvents", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEvents)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class BehavioralTimeSeries(NWBDataInterface): @@ -248,10 +269,13 @@ class BehavioralTimeSeries(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralTimeSeries", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralTimeSeries)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class PupilTracking(NWBDataInterface): @@ -263,10 +287,12 @@ class PupilTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "PupilTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(PupilTracking)"}} + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class EyeTracking(NWBDataInterface): @@ -278,10 +304,12 @@ class EyeTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "EyeTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(EyeTracking)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class CompassDirection(NWBDataInterface): @@ -293,10 +321,13 @@ class CompassDirection(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "CompassDirection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(CompassDirection)"}}, + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class Position(NWBDataInterface): @@ -308,10 +339,12 @@ class Position(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "Position", json_schema_extra={"linkml_meta": {"ifabsent": "string(Position)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_device.py index 2792e91..4aa7351 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ecephys.py index 0e59233..d3bc1a8 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -247,9 +262,9 @@ class ElectricalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_channels"], float], - NDArray[Shape["* num_times, * num_channels, * num_samples"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_channels"], float | int], + NDArray[Shape["* num_times, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -359,8 +374,8 @@ class SpikeEventSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_events, * num_samples"], float], - NDArray[Shape["* num_events, * num_channels, * num_samples"], float], + NDArray[Shape["* num_events, * num_samples"], float | int], + NDArray[Shape["* num_events, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -463,10 +478,12 @@ class EventWaveform(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "EventWaveform", json_schema_extra={"linkml_meta": {"ifabsent": "string(EventWaveform)"}} + ) value: Optional[Dict[str, SpikeEventSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpikeEventSeries"}]}} ) - name: str = Field(...) class FilteredEphys(NWBDataInterface): @@ -478,10 +495,12 @@ class FilteredEphys(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "FilteredEphys", json_schema_extra={"linkml_meta": {"ifabsent": "string(FilteredEphys)"}} + ) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class LFP(NWBDataInterface): @@ -493,10 +512,10 @@ class LFP(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field("LFP", json_schema_extra={"linkml_meta": {"ifabsent": "string(LFP)"}}) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class ElectrodeGroup(NWBContainer): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_epoch.py index fca71ae..907f235 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_file.py index aaea52c..5ad7185 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_file.py @@ -71,7 +71,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -84,6 +84,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -94,7 +106,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_icephys.py index 17e121f..84a24e2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_icephys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -249,7 +264,7 @@ class PatchClampSeriesData(ConfiguredBaseModel): ..., description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -360,7 +375,7 @@ class CurrentClampSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -542,7 +557,7 @@ class CurrentClampStimulusSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -723,7 +738,7 @@ class VoltageClampSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -955,7 +970,7 @@ class VoltageClampStimulusSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -1225,6 +1240,10 @@ class IntracellularRecordingsTable(AlignedDynamicTable): stimuli: IntracellularStimuliTable = Field( ..., description="""Table for storing intracellular stimulus related metadata.""" ) + categories: List[str] = Field( + ..., + description="""The names of the categories in this AlignedDynamicTable. Each category is represented by one DynamicTable stored in the parent group. This attribute should be used to specify an order of categories and the category names must match the names of the corresponding DynamicTable in the group.""", + ) value: Optional[Dict[str, DynamicTable]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "DynamicTable"}]}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_image.py index e8d4430..733114f 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_image.py @@ -50,7 +50,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -63,6 +63,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -73,7 +85,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -122,7 +137,7 @@ class GrayscaleImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": {"array": {"dimensions": [{"alias": "x"}, {"alias": "y"}]}} @@ -144,7 +159,7 @@ class RGBImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -174,7 +189,7 @@ class RGBAImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -303,8 +318,8 @@ class ImageSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, * z"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, * z"], float | int], ] ] = Field(None) @@ -534,8 +549,8 @@ class OpticalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float | int], ] ] = Field(None) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_misc.py index 4278604..43160a9 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -238,8 +253,8 @@ class AbstractFeatureSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -536,19 +551,21 @@ class DecompositionSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"ifabsent": "string(no unit)"}}, ) - value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float]] = Field( - None, - json_schema_extra={ - "linkml_meta": { - "array": { - "dimensions": [ - {"alias": "num_times"}, - {"alias": "num_channels"}, - {"alias": "num_bands"}, - ] + value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float | int]] = ( + Field( + None, + json_schema_extra={ + "linkml_meta": { + "array": { + "dimensions": [ + {"alias": "num_times"}, + {"alias": "num_channels"}, + {"alias": "num_bands"}, + ] + } } - } - }, + }, + ) ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ogen.py index d94f420..f3e6a15 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -204,7 +219,7 @@ class OptogeneticSeriesData(ConfiguredBaseModel): description="""Unit of measurement for data, which is fixed to 'watts'.""", json_schema_extra={"linkml_meta": {"equals_string": "watts", "ifabsent": "string(watts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ophys.py index d9ba753..d736ef5 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_ophys.py @@ -70,7 +70,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -83,6 +83,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -93,7 +105,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -440,7 +455,8 @@ class RoiResponseSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], NDArray[Shape["* num_times, * num_rois"], float] + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_rois"], float | int], ] ] = Field(None) @@ -454,10 +470,10 @@ class DfOverF(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field("DfOverF", json_schema_extra={"linkml_meta": {"ifabsent": "string(DfOverF)"}}) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class Fluorescence(NWBDataInterface): @@ -469,10 +485,12 @@ class Fluorescence(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "Fluorescence", json_schema_extra={"linkml_meta": {"ifabsent": "string(Fluorescence)"}} + ) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class ImageSegmentation(NWBDataInterface): @@ -484,10 +502,13 @@ class ImageSegmentation(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "ImageSegmentation", + json_schema_extra={"linkml_meta": {"ifabsent": "string(ImageSegmentation)"}}, + ) value: Optional[Dict[str, PlaneSegmentation]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "PlaneSegmentation"}]}} ) - name: str = Field(...) class PlaneSegmentation(DynamicTable): @@ -803,10 +824,13 @@ class MotionCorrection(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "MotionCorrection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(MotionCorrection)"}}, + ) value: Optional[Dict[str, CorrectedImageStack]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "CorrectedImageStack"}]}} ) - name: str = Field(...) class CorrectedImageStack(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_retinotopy.py index f0ac913..334a02e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/namespace.py index df0db47..dd19a19 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_6_0_alpha/namespace.py @@ -213,7 +213,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -226,6 +226,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -236,7 +248,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_base.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_base.py index 5a67fdf..6031ce0 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_base.py @@ -68,7 +68,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -81,6 +81,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -91,7 +103,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -120,7 +135,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -359,9 +374,9 @@ class Image(NWBData): description: Optional[str] = Field(None, description="""Description of the image.""") value: Optional[ Union[ - NDArray[Shape["* x, * y"], float], - NDArray[Shape["* x, * y, 3 r_g_b"], float], - NDArray[Shape["* x, * y, 4 r_g_b_a"], float], + NDArray[Shape["* x, * y"], float | int], + NDArray[Shape["* x, * y, 3 r_g_b"], float | int], + NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int], ] ] = Field(None) @@ -551,13 +566,16 @@ class ProcessingModule(NWBContainer): {"from_schema": "core.nwb.base", "tree_root": True} ) + name: str = Field(...) + description: str = Field( + ..., description="""Description of this collection of processed data.""" + ) value: Optional[Dict[str, Union[DynamicTable, NWBDataInterface]]] = Field( None, json_schema_extra={ "linkml_meta": {"any_of": [{"range": "NWBDataInterface"}, {"range": "DynamicTable"}]} }, ) - name: str = Field(...) class Images(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_behavior.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_behavior.py index a67672a..d0d1919 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_behavior.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_behavior.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -201,10 +216,10 @@ class SpatialSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, 1 x"], float], - NDArray[Shape["* num_times, 2 x_y"], float], - NDArray[Shape["* num_times, 3 x_y_z"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, 1 x"], float | int], + NDArray[Shape["* num_times, 2 x_y"], float | int], + NDArray[Shape["* num_times, 3 x_y_z"], float | int], ] ] = Field(None) @@ -218,10 +233,13 @@ class BehavioralEpochs(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEpochs", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEpochs)"}}, + ) value: Optional[Dict[str, IntervalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "IntervalSeries"}]}} ) - name: str = Field(...) class BehavioralEvents(NWBDataInterface): @@ -233,10 +251,13 @@ class BehavioralEvents(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralEvents", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralEvents)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class BehavioralTimeSeries(NWBDataInterface): @@ -248,10 +269,13 @@ class BehavioralTimeSeries(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "BehavioralTimeSeries", + json_schema_extra={"linkml_meta": {"ifabsent": "string(BehavioralTimeSeries)"}}, + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class PupilTracking(NWBDataInterface): @@ -263,10 +287,12 @@ class PupilTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "PupilTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(PupilTracking)"}} + ) value: Optional[Dict[str, TimeSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "TimeSeries"}]}} ) - name: str = Field(...) class EyeTracking(NWBDataInterface): @@ -278,10 +304,12 @@ class EyeTracking(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "EyeTracking", json_schema_extra={"linkml_meta": {"ifabsent": "string(EyeTracking)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class CompassDirection(NWBDataInterface): @@ -293,10 +321,13 @@ class CompassDirection(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "CompassDirection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(CompassDirection)"}}, + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) class Position(NWBDataInterface): @@ -308,10 +339,12 @@ class Position(NWBDataInterface): {"from_schema": "core.nwb.behavior", "tree_root": True} ) + name: str = Field( + "Position", json_schema_extra={"linkml_meta": {"ifabsent": "string(Position)"}} + ) value: Optional[Dict[str, SpatialSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpatialSeries"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_device.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_device.py index 8a24ab1..6d85cf6 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_device.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_device.py @@ -42,7 +42,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -55,6 +55,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -65,7 +77,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ecephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ecephys.py index 195633b..13b1cad 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ecephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ecephys.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -247,9 +262,9 @@ class ElectricalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_channels"], float], - NDArray[Shape["* num_times, * num_channels, * num_samples"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_channels"], float | int], + NDArray[Shape["* num_times, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -359,8 +374,8 @@ class SpikeEventSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_events, * num_samples"], float], - NDArray[Shape["* num_events, * num_channels, * num_samples"], float], + NDArray[Shape["* num_events, * num_samples"], float | int], + NDArray[Shape["* num_events, * num_channels, * num_samples"], float | int], ] ] = Field(None) @@ -463,10 +478,12 @@ class EventWaveform(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "EventWaveform", json_schema_extra={"linkml_meta": {"ifabsent": "string(EventWaveform)"}} + ) value: Optional[Dict[str, SpikeEventSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "SpikeEventSeries"}]}} ) - name: str = Field(...) class FilteredEphys(NWBDataInterface): @@ -478,10 +495,12 @@ class FilteredEphys(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field( + "FilteredEphys", json_schema_extra={"linkml_meta": {"ifabsent": "string(FilteredEphys)"}} + ) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class LFP(NWBDataInterface): @@ -493,10 +512,10 @@ class LFP(NWBDataInterface): {"from_schema": "core.nwb.ecephys", "tree_root": True} ) + name: str = Field("LFP", json_schema_extra={"linkml_meta": {"ifabsent": "string(LFP)"}}) value: Optional[Dict[str, ElectricalSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "ElectricalSeries"}]}} ) - name: str = Field(...) class ElectrodeGroup(NWBContainer): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_epoch.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_epoch.py index eb514b2..d114b30 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_epoch.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_epoch.py @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_file.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_file.py index b21e028..bcaf029 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_file.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_file.py @@ -71,7 +71,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -84,6 +84,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -94,7 +106,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_icephys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_icephys.py index 3cb28da..937b260 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_icephys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_icephys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -249,7 +264,7 @@ class PatchClampSeriesData(ConfiguredBaseModel): ..., description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -360,7 +375,7 @@ class CurrentClampSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -542,7 +557,7 @@ class CurrentClampStimulusSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -723,7 +738,7 @@ class VoltageClampSeriesData(ConfiguredBaseModel): "linkml_meta": {"equals_string": "amperes", "ifabsent": "string(amperes)"} }, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -955,7 +970,7 @@ class VoltageClampStimulusSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. which is fixed to 'volts'. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion' and add 'offset'.""", json_schema_extra={"linkml_meta": {"equals_string": "volts", "ifabsent": "string(volts)"}}, ) - value: Optional[NDArray[Shape["* num_times"], float]] = Field( + value: Optional[NDArray[Shape["* num_times"], float | int]] = Field( None, json_schema_extra={"linkml_meta": {"array": {"dimensions": [{"alias": "num_times"}]}}} ) @@ -1237,6 +1252,10 @@ class IntracellularRecordingsTable(AlignedDynamicTable): stimuli: IntracellularStimuliTable = Field( ..., description="""Table for storing intracellular stimulus related metadata.""" ) + categories: List[str] = Field( + ..., + description="""The names of the categories in this AlignedDynamicTable. Each category is represented by one DynamicTable stored in the parent group. This attribute should be used to specify an order of categories and the category names must match the names of the corresponding DynamicTable in the group.""", + ) value: Optional[Dict[str, DynamicTable]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "DynamicTable"}]}} ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_image.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_image.py index 263bf5b..331bb3a 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_image.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_image.py @@ -50,7 +50,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -63,6 +63,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -73,7 +85,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -122,7 +137,7 @@ class GrayscaleImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": {"array": {"dimensions": [{"alias": "x"}, {"alias": "y"}]}} @@ -144,7 +159,7 @@ class RGBImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 3 r_g_b"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -174,7 +189,7 @@ class RGBAImage(Image): ) name: str = Field(...) - value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float]] = Field( + value: Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], float | int]] = Field( None, json_schema_extra={ "linkml_meta": { @@ -303,8 +318,8 @@ class ImageSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, * z"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, * z"], float | int], ] ] = Field(None) @@ -534,8 +549,8 @@ class OpticalSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* frame, * x, * y"], float], - NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float], + NDArray[Shape["* frame, * x, * y"], float | int], + NDArray[Shape["* frame, * x, * y, 3 r_g_b"], float | int], ] ] = Field(None) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_misc.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_misc.py index e1dbe0e..8c06050 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_misc.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_misc.py @@ -59,7 +59,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +72,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +94,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -238,8 +253,8 @@ class AbstractFeatureSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], - NDArray[Shape["* num_times, * num_features"], float], + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_features"], float | int], ] ] = Field(None) @@ -536,19 +551,21 @@ class DecompositionSeriesData(ConfiguredBaseModel): description="""Base unit of measurement for working with the data. Actual stored values are not necessarily stored in these units. To access the data in these units, multiply 'data' by 'conversion'.""", json_schema_extra={"linkml_meta": {"ifabsent": "string(no unit)"}}, ) - value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float]] = Field( - None, - json_schema_extra={ - "linkml_meta": { - "array": { - "dimensions": [ - {"alias": "num_times"}, - {"alias": "num_channels"}, - {"alias": "num_bands"}, - ] + value: Optional[NDArray[Shape["* num_times, * num_channels, * num_bands"], float | int]] = ( + Field( + None, + json_schema_extra={ + "linkml_meta": { + "array": { + "dimensions": [ + {"alias": "num_times"}, + {"alias": "num_channels"}, + {"alias": "num_bands"}, + ] + } } - } - }, + }, + ) ) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ogen.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ogen.py index bc21582..f2f31a2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ogen.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ogen.py @@ -49,7 +49,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,6 +62,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -72,7 +84,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -207,7 +222,8 @@ class OptogeneticSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], NDArray[Shape["* num_times, * num_rois"], float] + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_rois"], float | int], ] ] = Field(None) diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ophys.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ophys.py index 8104916..c842819 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ophys.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_ophys.py @@ -66,7 +66,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -79,6 +79,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -89,7 +101,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -436,7 +451,8 @@ class RoiResponseSeriesData(ConfiguredBaseModel): ) value: Optional[ Union[ - NDArray[Shape["* num_times"], float], NDArray[Shape["* num_times, * num_rois"], float] + NDArray[Shape["* num_times"], float | int], + NDArray[Shape["* num_times, * num_rois"], float | int], ] ] = Field(None) @@ -450,10 +466,10 @@ class DfOverF(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field("DfOverF", json_schema_extra={"linkml_meta": {"ifabsent": "string(DfOverF)"}}) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class Fluorescence(NWBDataInterface): @@ -465,10 +481,12 @@ class Fluorescence(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "Fluorescence", json_schema_extra={"linkml_meta": {"ifabsent": "string(Fluorescence)"}} + ) value: Optional[Dict[str, RoiResponseSeries]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "RoiResponseSeries"}]}} ) - name: str = Field(...) class ImageSegmentation(NWBDataInterface): @@ -480,10 +498,13 @@ class ImageSegmentation(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "ImageSegmentation", + json_schema_extra={"linkml_meta": {"ifabsent": "string(ImageSegmentation)"}}, + ) value: Optional[Dict[str, PlaneSegmentation]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "PlaneSegmentation"}]}} ) - name: str = Field(...) class PlaneSegmentation(DynamicTable): @@ -799,10 +820,13 @@ class MotionCorrection(NWBDataInterface): {"from_schema": "core.nwb.ophys", "tree_root": True} ) + name: str = Field( + "MotionCorrection", + json_schema_extra={"linkml_meta": {"ifabsent": "string(MotionCorrection)"}}, + ) value: Optional[Dict[str, CorrectedImageStack]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "CorrectedImageStack"}]}} ) - name: str = Field(...) class CorrectedImageStack(NWBDataInterface): diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_retinotopy.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_retinotopy.py index c7ced82..0cdfaac 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_retinotopy.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/core_nwb_retinotopy.py @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/namespace.py index fd6b259..95df714 100644 --- a/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/core/v2_7_0/namespace.py @@ -214,7 +214,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -227,6 +227,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -237,7 +249,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/__init__.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/__init__.py index e69de29..8b13789 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/__init__.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/__init__.py @@ -0,0 +1 @@ + diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_sparse.py index 56af1b8..f4811e5 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_sparse.py @@ -20,7 +20,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -41,7 +41,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,6 +54,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -64,7 +76,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py index e52b294..0e5173a 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/hdmf_common_table.py @@ -44,7 +44,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -65,7 +65,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,6 +78,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -88,7 +100,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -117,7 +132,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -168,7 +183,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -260,7 +275,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -316,7 +331,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -571,13 +586,19 @@ class DynamicTableMixin(BaseModel): model[key] = to_cast(name=key, description="", value=val) except ValidationError as e: # pragma: no cover raise ValidationError.from_exception_data( - title=f"field {key} cannot be cast to VectorData from {val}", + title="cast_extra_columns", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "value_error", "input": val, - } + "loc": ("DynamicTableMixin", "cast_extra_columns"), + "ctx": { + "error": ValueError( + f"field {key} cannot be cast to {to_cast} from {val}" + ) + }, + }, + *e.errors(), ], ) from e return model @@ -640,18 +661,21 @@ class DynamicTableMixin(BaseModel): # should pass if we're supposed to be a VectorData column # don't want to override intention here by insisting that it is # *actually* a VectorData column in case an NDArray has been specified for now + description = cls.model_fields[info.field_name].description + description = description if description is not None else "" + return handler( annotation( val, name=info.field_name, - description=cls.model_fields[info.field_name].description, + description=description, ) ) except Exception: raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -887,7 +911,7 @@ class Index(Data): ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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)+1]. The second vector is at VectorData[VectorIndex(0)+1:VectorIndex(1)+1], and so on. """ @@ -900,7 +924,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): description: str = Field(..., description="""Description of what these vectors represent.""") -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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. """ @@ -915,7 +939,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -933,7 +957,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -963,7 +987,7 @@ class Container(ConfiguredBaseModel): name: str = Field(...) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). Apart from a column that contains unique identifiers for each row there are no other required datasets. Users are free to add any number of VectorData objects here. Table functionality is already supported through compound types, which is analogous to storing an array-of-structs. DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. For example, DynamicTable was originally developed for storing trial data and spike unit metadata. Both of these use cases are expected to produce relatively small tables, so the spatial locality of multiple datasets present in a DynamicTable is not expected to have a significant performance impact. Additionally, requirements of trial and unit metadata tables are sufficiently diverse that performance implications can be overlooked in favor of usability. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/namespace.py index dcc5707..b494ff8 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_0/namespace.py @@ -36,7 +36,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_sparse.py index 8ce7f43..96a432f 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_sparse.py @@ -20,7 +20,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -41,7 +41,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,6 +54,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -64,7 +76,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py index 9065b81..f763497 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/hdmf_common_table.py @@ -44,7 +44,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -65,7 +65,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,6 +78,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -88,7 +100,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -117,7 +132,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -168,7 +183,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -260,7 +275,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -316,7 +331,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -571,13 +586,19 @@ class DynamicTableMixin(BaseModel): model[key] = to_cast(name=key, description="", value=val) except ValidationError as e: # pragma: no cover raise ValidationError.from_exception_data( - title=f"field {key} cannot be cast to VectorData from {val}", + title="cast_extra_columns", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "value_error", "input": val, - } + "loc": ("DynamicTableMixin", "cast_extra_columns"), + "ctx": { + "error": ValueError( + f"field {key} cannot be cast to {to_cast} from {val}" + ) + }, + }, + *e.errors(), ], ) from e return model @@ -640,18 +661,21 @@ class DynamicTableMixin(BaseModel): # should pass if we're supposed to be a VectorData column # don't want to override intention here by insisting that it is # *actually* a VectorData column in case an NDArray has been specified for now + description = cls.model_fields[info.field_name].description + description = description if description is not None else "" + return handler( annotation( val, name=info.field_name, - description=cls.model_fields[info.field_name].description, + description=description, ) ) except Exception: raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -887,7 +911,7 @@ class Index(Data): ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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)+1]. The second vector is at VectorData[VectorIndex(0)+1:VectorIndex(1)+1], and so on. """ @@ -900,7 +924,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): description: str = Field(..., description="""Description of what these vectors represent.""") -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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. """ @@ -915,7 +939,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -933,7 +957,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -963,7 +987,7 @@ class Container(ConfiguredBaseModel): name: str = Field(...) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). Apart from a column that contains unique identifiers for each row there are no other required datasets. Users are free to add any number of VectorData objects here. Table functionality is already supported through compound types, which is analogous to storing an array-of-structs. DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. For example, DynamicTable was originally developed for storing trial data and spike unit metadata. Both of these use cases are expected to produce relatively small tables, so the spatial locality of multiple datasets present in a DynamicTable is not expected to have a significant performance impact. Additionally, requirements of trial and unit metadata tables are sufficiently diverse that performance implications can be overlooked in favor of usability. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/namespace.py index 0f66985..a7b07c0 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_2/namespace.py @@ -36,7 +36,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_sparse.py index c0f7fcc..a702232 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_sparse.py @@ -20,7 +20,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -41,7 +41,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,6 +54,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -64,7 +76,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py index 749fab9..b047088 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/hdmf_common_table.py @@ -44,7 +44,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -65,7 +65,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,6 +78,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -88,7 +100,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -117,7 +132,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -168,7 +183,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -260,7 +275,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -316,7 +331,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -571,13 +586,19 @@ class DynamicTableMixin(BaseModel): model[key] = to_cast(name=key, description="", value=val) except ValidationError as e: # pragma: no cover raise ValidationError.from_exception_data( - title=f"field {key} cannot be cast to VectorData from {val}", + title="cast_extra_columns", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "value_error", "input": val, - } + "loc": ("DynamicTableMixin", "cast_extra_columns"), + "ctx": { + "error": ValueError( + f"field {key} cannot be cast to {to_cast} from {val}" + ) + }, + }, + *e.errors(), ], ) from e return model @@ -640,18 +661,21 @@ class DynamicTableMixin(BaseModel): # should pass if we're supposed to be a VectorData column # don't want to override intention here by insisting that it is # *actually* a VectorData column in case an NDArray has been specified for now + description = cls.model_fields[info.field_name].description + description = description if description is not None else "" + return handler( annotation( val, name=info.field_name, - description=cls.model_fields[info.field_name].description, + description=description, ) ) except Exception: raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -887,7 +911,7 @@ class Index(Data): ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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)+1]. The second vector is at VectorData[VectorIndex(0)+1:VectorIndex(1)+1], and so on. """ @@ -901,7 +925,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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. """ @@ -919,7 +943,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -937,7 +961,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -975,7 +999,7 @@ class Container(ConfiguredBaseModel): name: str = Field(...) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). Apart from a column that contains unique identifiers for each row there are no other required datasets. Users are free to add any number of VectorData objects here. Table functionality is already supported through compound types, which is analogous to storing an array-of-structs. DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. For example, DynamicTable was originally developed for storing trial data and spike unit metadata. Both of these use cases are expected to produce relatively small tables, so the spatial locality of multiple datasets present in a DynamicTable is not expected to have a significant performance impact. Additionally, requirements of trial and unit metadata tables are sufficiently diverse that performance implications can be overlooked in favor of usability. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/namespace.py index c505d77..d0eb276 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_1_3/namespace.py @@ -36,7 +36,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -57,7 +57,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -70,6 +70,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -80,7 +92,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_base.py index 656629d..62ac415 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_sparse.py index 13824fe..2e171cb 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_sparse.py @@ -20,7 +20,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -41,7 +41,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -52,7 +52,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py index fdd6bcc..135e3c6 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -970,7 +991,7 @@ class VocabData(VectorData): ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/namespace.py index 25e5651..1bdd7c4 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_0/namespace.py @@ -35,7 +35,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -56,7 +56,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -67,7 +67,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_base.py index affaa59..c166f2b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_sparse.py index 01484f3..d68c966 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py index cc9029d..1bcfbb6 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -970,7 +991,7 @@ class VocabData(VectorData): ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/namespace.py index 1338679..69a3e11 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_2_1/namespace.py @@ -35,7 +35,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -56,7 +56,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -67,7 +67,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_base.py index a7ed66d..ac4722f 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_resources.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_resources.py index 4d4850c..d24f662 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_resources.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_resources.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_sparse.py index 2620eb6..542738c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py index a55c212..724cfba 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -970,7 +991,7 @@ class VocabData(VectorData): ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/namespace.py index 040adf7..96107ed 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_3_0/namespace.py @@ -37,7 +37,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -58,7 +58,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -69,7 +69,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_base.py index 02d67bf..80ff949 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_sparse.py index ad70998..2633579 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py index c704fa9..248a227 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -944,7 +965,7 @@ class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseMode ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/namespace.py index 0a85a76..5e9f469 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_4_0/namespace.py @@ -29,7 +29,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -50,7 +50,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -61,7 +61,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_base.py index 7c62f93..47eee69 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -53,6 +53,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -63,7 +75,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -134,10 +149,10 @@ class SimpleMultiContainer(Container): {"from_schema": "hdmf-common.base", "tree_root": True} ) + name: str = Field(...) value: Optional[Dict[str, Container]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "Container"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_sparse.py index d434cd9..e805809 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py index c604b38..00fa3ed 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -80,6 +80,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -90,7 +102,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -119,7 +134,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +185,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +277,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +333,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -573,13 +588,19 @@ class DynamicTableMixin(BaseModel): model[key] = to_cast(name=key, description="", value=val) except ValidationError as e: # pragma: no cover raise ValidationError.from_exception_data( - title=f"field {key} cannot be cast to VectorData from {val}", + title="cast_extra_columns", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "value_error", "input": val, - } + "loc": ("DynamicTableMixin", "cast_extra_columns"), + "ctx": { + "error": ValueError( + f"field {key} cannot be cast to {to_cast} from {val}" + ) + }, + }, + *e.errors(), ], ) from e return model @@ -642,18 +663,21 @@ class DynamicTableMixin(BaseModel): # should pass if we're supposed to be a VectorData column # don't want to override intention here by insisting that it is # *actually* a VectorData column in case an NDArray has been specified for now + description = cls.model_fields[info.field_name].description + description = description if description is not None else "" + return handler( annotation( val, name=info.field_name, - description=cls.model_fields[info.field_name].description, + description=description, ) ) except Exception: raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +886,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +900,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +924,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +942,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -944,7 +968,7 @@ class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseMode ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ @@ -975,10 +999,14 @@ class AlignedDynamicTable(AlignedDynamicTableMixin, DynamicTable): {"from_schema": "hdmf-common.table", "tree_root": True} ) + name: str = Field(...) + categories: List[str] = Field( + ..., + description="""The names of the categories in this AlignedDynamicTable. Each category is represented by one DynamicTable stored in the parent group. This attribute should be used to specify an order of categories and the category names must match the names of the corresponding DynamicTable in the group.""", + ) value: Optional[Dict[str, DynamicTable]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "DynamicTable"}]}} ) - name: str = Field(...) colnames: List[str] = Field( ..., description="""The names of the columns in this table. This should be used to specify an order to the columns.""", diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/namespace.py index 6e04fd0..6a2b5ed 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_0/namespace.py @@ -30,7 +30,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -51,7 +51,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -64,6 +64,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -74,7 +86,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_base.py index df22948..adb45dd 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_sparse.py index 4e921cc..9731e34 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py index 6719d89..68e87e2 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -944,7 +965,7 @@ class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseMode ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/namespace.py index fa4ea72..83568c9 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_5_1/namespace.py @@ -30,7 +30,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -51,7 +51,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,7 +62,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_base.py index 57c9079..0ee3b97 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_sparse.py index 73a6043..a94523d 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py index d47f747..1fd0a39 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -944,7 +965,7 @@ class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseMode ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/namespace.py index 981e600..a8f55a0 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_6_0/namespace.py @@ -30,7 +30,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -51,7 +51,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,7 +62,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_base.py index e785e04..08c9fda 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -51,7 +51,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_sparse.py index b2fe190..a6cd2db 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py index dceaa2e..a81bd63 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -78,7 +78,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod @@ -119,7 +141,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +192,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +284,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +340,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -576,8 +598,7 @@ class DynamicTableMixin(BaseModel): title=f"field {key} cannot be cast to VectorData from {val}", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "model_type", "input": val, } ], @@ -653,7 +674,7 @@ class DynamicTableMixin(BaseModel): raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +883,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +897,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +921,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +939,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -944,7 +965,7 @@ class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseMode ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/namespace.py index 4aaa46d..ed5ddbe 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_7_0/namespace.py @@ -30,7 +30,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -51,7 +51,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -62,7 +62,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_base.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_base.py index 7731368..d58cc4b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_base.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_base.py @@ -19,7 +19,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -53,6 +53,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -63,7 +75,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -134,10 +149,10 @@ class SimpleMultiContainer(Container): {"from_schema": "hdmf-common.base", "tree_root": True} ) + name: str = Field(...) value: Optional[Dict[str, Container]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "Container"}]}} ) - name: str = Field(...) # Model rebuild diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_sparse.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_sparse.py index 7a3e72c..09428fa 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_sparse.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_sparse.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py index d6699e6..39b7af0 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/hdmf_common_table.py @@ -46,7 +46,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -67,7 +67,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -80,6 +80,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -90,7 +102,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -119,7 +134,7 @@ NUMPYDANTIC_VERSION = "1.2.1" T = TypeVar("T", bound=NDArray) -class VectorDataMixin(BaseModel, Generic[T]): +class VectorDataMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorData indexing abilities """ @@ -170,7 +185,7 @@ class VectorDataMixin(BaseModel, Generic[T]): return len(self.value) -class VectorIndexMixin(BaseModel, Generic[T]): +class VectorIndexMixin(ConfiguredBaseModel, Generic[T]): """ Mixin class to give VectorIndex indexing abilities """ @@ -262,7 +277,7 @@ class VectorIndexMixin(BaseModel, Generic[T]): return len(self.value) -class DynamicTableRegionMixin(BaseModel): +class DynamicTableRegionMixin(ConfiguredBaseModel): """ Mixin to allow indexing references to regions of dynamictables """ @@ -318,7 +333,7 @@ class DynamicTableRegionMixin(BaseModel): ) # pragma: no cover -class DynamicTableMixin(BaseModel): +class DynamicTableMixin(ConfiguredBaseModel): """ Mixin to make DynamicTable subclasses behave like tables/dataframes @@ -573,13 +588,19 @@ class DynamicTableMixin(BaseModel): model[key] = to_cast(name=key, description="", value=val) except ValidationError as e: # pragma: no cover raise ValidationError.from_exception_data( - title=f"field {key} cannot be cast to VectorData from {val}", + title="cast_extra_columns", line_errors=[ { - "type": "ValueError", - "loc": ("DynamicTableMixin", "cast_extra_columns"), + "type": "value_error", "input": val, - } + "loc": ("DynamicTableMixin", "cast_extra_columns"), + "ctx": { + "error": ValueError( + f"field {key} cannot be cast to {to_cast} from {val}" + ) + }, + }, + *e.errors(), ], ) from e return model @@ -642,18 +663,21 @@ class DynamicTableMixin(BaseModel): # should pass if we're supposed to be a VectorData column # don't want to override intention here by insisting that it is # *actually* a VectorData column in case an NDArray has been specified for now + description = cls.model_fields[info.field_name].description + description = description if description is not None else "" + return handler( annotation( val, name=info.field_name, - description=cls.model_fields[info.field_name].description, + description=description, ) ) except Exception: raise e from None -class AlignedDynamicTableMixin(BaseModel): +class AlignedDynamicTableMixin(ConfiguredBaseModel): """ Mixin to allow indexing multiple tables that are aligned on a common ID @@ -862,7 +886,7 @@ linkml_meta = LinkMLMeta( ) -class VectorData(VectorDataMixin, ConfiguredBaseModel): +class VectorData(VectorDataMixin): """ 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. """ @@ -876,7 +900,7 @@ class VectorData(VectorDataMixin, ConfiguredBaseModel): value: Optional[T] = Field(None) -class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): +class VectorIndex(VectorIndexMixin): """ 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\". """ @@ -900,7 +924,7 @@ class VectorIndex(VectorIndexMixin, ConfiguredBaseModel): ] = Field(None) -class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): +class ElementIdentifiers(ElementIdentifiersMixin, Data): """ A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable. """ @@ -918,7 +942,7 @@ class ElementIdentifiers(ElementIdentifiersMixin, Data, ConfiguredBaseModel): ) -class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseModel): +class DynamicTableRegion(DynamicTableRegionMixin, VectorData): """ DynamicTableRegion provides a link from one table to an index or region of another. The `table` attribute is a link to another `DynamicTable`, indicating which table is referenced, and the data is int(s) indicating the row(s) (0-indexed) of the target array. `DynamicTableRegion`s can be used to associate rows with repeated meta-data without data duplication. They can also be used to create hierarchical relationships between multiple `DynamicTable`s. `DynamicTableRegion` objects may be paired with a `VectorIndex` object to create ragged references, so a single cell of a `DynamicTable` can reference many rows of another `DynamicTable`. """ @@ -944,7 +968,7 @@ class DynamicTableRegion(DynamicTableRegionMixin, VectorData, ConfiguredBaseMode ] = Field(None) -class DynamicTable(DynamicTableMixin, ConfiguredBaseModel): +class DynamicTable(DynamicTableMixin): """ A group containing multiple datasets that are aligned on the first dimension (Currently, this requirement if left up to APIs to check and enforce). These datasets represent different columns in the table. Apart from a column that contains unique identifiers for each row, there are no other required datasets. Users are free to add any number of custom VectorData objects (columns) here. DynamicTable also supports ragged array columns, where each element can be of a different size. To add a ragged array column, use a VectorIndex type to index the corresponding VectorData type. See documentation for VectorData and VectorIndex for more details. Unlike a compound data type, which is analogous to storing an array-of-structs, a DynamicTable can be thought of as a struct-of-arrays. This provides an alternative structure to choose from when optimizing storage for anticipated access patterns. Additionally, this type provides a way of creating a table without having to define a compound type up front. Although this convenience may be attractive, users should think carefully about how data will be accessed. DynamicTable is more appropriate for column-centric access, whereas a dataset with a compound type would be more appropriate for row-centric access. Finally, data size should also be taken into account. For small tables, performance loss may be an acceptable trade-off for the flexibility of a DynamicTable. """ @@ -975,10 +999,14 @@ class AlignedDynamicTable(AlignedDynamicTableMixin, DynamicTable): {"from_schema": "hdmf-common.table", "tree_root": True} ) + name: str = Field(...) + categories: List[str] = Field( + ..., + description="""The names of the categories in this AlignedDynamicTable. Each category is represented by one DynamicTable stored in the parent group. This attribute should be used to specify an order of categories and the category names must match the names of the corresponding DynamicTable in the group.""", + ) value: Optional[Dict[str, DynamicTable]] = Field( None, json_schema_extra={"linkml_meta": {"any_of": [{"range": "DynamicTable"}]}} ) - name: str = Field(...) colnames: List[str] = Field( ..., description="""The names of the columns in this table. This should be used to specify an order to the columns.""", diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/namespace.py index dd09b7f..0e792f9 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_common/v1_8_0/namespace.py @@ -30,7 +30,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -51,7 +51,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -64,6 +64,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -74,7 +86,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_experimental.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_experimental.py index ad617da..e265d0c 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_experimental.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_experimental.py @@ -11,7 +11,7 @@ import numpy as np from numpydantic import NDArray, Shape from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator -from ...hdmf_common.v1_4_0.hdmf_common_table import VectorData +from ...hdmf_common.v1_5_0.hdmf_common_table import VectorData metamodel_version = "None" @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -99,7 +114,7 @@ linkml_meta = LinkMLMeta( }, "default_prefix": "hdmf-experimental.experimental/", "id": "hdmf-experimental.experimental", - "imports": ["../../hdmf_common/v1_4_0/namespace", "hdmf-experimental.nwb.language"], + "imports": ["../../hdmf_common/v1_5_0/namespace", "hdmf-experimental.nwb.language"], "name": "hdmf-experimental.experimental", } ) diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_resources.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_resources.py index cda720e..867c41e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_resources.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/hdmf_experimental_resources.py @@ -11,7 +11,7 @@ import numpy as np from numpydantic import NDArray, Shape from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator -from ...hdmf_common.v1_4_0.hdmf_common_base import Container, Data +from ...hdmf_common.v1_5_0.hdmf_common_base import Container, Data metamodel_version = "None" @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass @@ -99,7 +114,7 @@ linkml_meta = LinkMLMeta( }, "default_prefix": "hdmf-experimental.resources/", "id": "hdmf-experimental.resources", - "imports": ["../../hdmf_common/v1_4_0/namespace", "hdmf-experimental.nwb.language"], + "imports": ["../../hdmf_common/v1_5_0/namespace", "hdmf-experimental.nwb.language"], "name": "hdmf-experimental.resources", } ) diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/namespace.py index 3429a1e..d133165 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_1_0/namespace.py @@ -10,9 +10,10 @@ from typing import Any, ClassVar, Dict, List, Literal, Optional, Union import numpy as np from pydantic import BaseModel, ConfigDict, Field, RootModel, field_validator -from ...hdmf_common.v1_4_0.hdmf_common_base import Container, Data, SimpleMultiContainer -from ...hdmf_common.v1_4_0.hdmf_common_sparse import CSRMatrix -from ...hdmf_common.v1_4_0.hdmf_common_table import ( +from ...hdmf_common.v1_5_0.hdmf_common_base import Container, Data, SimpleMultiContainer +from ...hdmf_common.v1_5_0.hdmf_common_sparse import CSRMatrix +from ...hdmf_common.v1_5_0.hdmf_common_table import ( + AlignedDynamicTable, DynamicTable, DynamicTableRegion, ElementIdentifiers, @@ -38,7 +39,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -59,7 +60,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,6 +73,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -82,7 +95,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_experimental.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_experimental.py index 1a88edc..c48bb0b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_experimental.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_experimental.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_resources.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_resources.py index 8d5af36..0ef8026 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_resources.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/hdmf_experimental_resources.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/namespace.py index c697f83..7be5bf0 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_2_0/namespace.py @@ -39,7 +39,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -60,7 +60,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -71,7 +71,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_experimental.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_experimental.py index cbd0ad9..894b2ab 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_experimental.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_experimental.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_resources.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_resources.py index 9f337fa..81be11e 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_resources.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/hdmf_experimental_resources.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/namespace.py index e1a12ca..fcc1422 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_3_0/namespace.py @@ -39,7 +39,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -60,7 +60,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -71,7 +71,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_experimental.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_experimental.py index 0551cfd..6c9d22b 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_experimental.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_experimental.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_resources.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_resources.py index 09e6f05..8f68ec9 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_resources.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/hdmf_experimental_resources.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -54,7 +54,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/namespace.py index c904202..c79550d 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_4_0/namespace.py @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -61,7 +61,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -72,7 +72,29 @@ class ConfiguredBaseModel(BaseModel): try: return handler(v["value"]) except (IndexError, KeyError, TypeError): - raise e1 + raise ValueError( + f"coerce_value: Could not use the value field of {type(v)} " + f"to construct {cls.__name__}.{info.field_name}, " + f"expected type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 + + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception as e2: + raise ValueError( + f"cast_with_value: Could not cast {type(v)} as value field for " + f"{cls.__name__}.{info.field_name}," + f" expected_type: {cls.model_fields[info.field_name].annotation}\n" + f"inner error: {str(e1)}" + ) from e1 @field_validator("*", mode="before") @classmethod diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_experimental.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_experimental.py index 714ae52..368d037 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_experimental.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_experimental.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_resources.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_resources.py index d3132cd..8402336 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_resources.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/hdmf_experimental_resources.py @@ -22,7 +22,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -43,7 +43,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -56,6 +56,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -66,7 +78,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/namespace.py b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/namespace.py index 281e5b2..de810ad 100644 --- a/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/namespace.py +++ b/nwb_models/src/nwb_models/models/pydantic/hdmf_experimental/v0_5_0/namespace.py @@ -40,7 +40,7 @@ class ConfiguredBaseModel(BaseModel): model_config = ConfigDict( validate_assignment=True, validate_default=True, - extra="allow", + extra="forbid", arbitrary_types_allowed=True, use_enum_values=True, strict=False, @@ -61,7 +61,7 @@ class ConfiguredBaseModel(BaseModel): @field_validator("*", mode="wrap") @classmethod - def coerce_value(cls, v: Any, handler) -> Any: + def coerce_value(cls, v: Any, handler, info) -> Any: """Try to rescue instantiation by using the value field""" try: return handler(v) @@ -74,6 +74,18 @@ class ConfiguredBaseModel(BaseModel): except (IndexError, KeyError, TypeError): raise e1 + @field_validator("*", mode="wrap") + @classmethod + def cast_with_value(cls, v: Any, handler, info) -> Any: + """Try to rescue instantiation by casting into the model's value fiel""" + try: + return handler(v) + except Exception as e1: + try: + return handler({"value": v}) + except Exception: + raise e1 + @field_validator("*", mode="before") @classmethod def coerce_subclass(cls, v: Any, info) -> Any: @@ -84,7 +96,10 @@ class ConfiguredBaseModel(BaseModel): annotation = annotation.__args__[0] try: if issubclass(annotation, type(v)) and annotation is not type(v): - v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + if v.__pydantic_extra__: + v = annotation(**{**v.__dict__, **v.__pydantic_extra__}) + else: + v = annotation(**v.__dict__) except TypeError: # fine, annotation is a non-class type like a TypeVar pass diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.base.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.base.yaml index 04aec2d..1771272 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.base.yaml @@ -304,13 +304,24 @@ classes: description: A collection of processed data. is_a: NWBContainer attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: NWBDataInterface - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + description: + name: description + description: Description of this collection of processed data. + range: text + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: NWBDataInterface + - range: DynamicTable tree_root: true Images: name: Images diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.behavior.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.behavior.yaml index 27f87f4..4b3440f 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.behavior.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.behavior.yaml @@ -127,12 +127,19 @@ classes: events. BehavioralTimeSeries is for continuous data. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: IntervalSeries + name: + name: name + ifabsent: string(BehavioralEpochs) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: IntervalSeries tree_root: true BehavioralEvents: name: BehavioralEvents @@ -140,12 +147,19 @@ classes: for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralEvents) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true BehavioralTimeSeries: name: BehavioralTimeSeries @@ -153,36 +167,57 @@ classes: of BehavioralEpochs for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralTimeSeries) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true PupilTracking: name: PupilTracking description: Eye-tracking data, representing pupil size. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(PupilTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true EyeTracking: name: EyeTracking description: Eye-tracking data, representing direction of gaze. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(EyeTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true CompassDirection: name: CompassDirection @@ -193,22 +228,36 @@ classes: be radians or degrees. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(CompassDirection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true Position: name: Position description: Position data, whether along the x, x/y or x/y/z axis. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(Position) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ecephys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ecephys.yaml index 8ce3b23..9b4593c 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ecephys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ecephys.yaml @@ -367,12 +367,19 @@ classes: during experiment acquisition. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpikeEventSeries + name: + name: name + ifabsent: string(EventWaveform) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpikeEventSeries tree_root: true FilteredEphys: name: FilteredEphys @@ -389,12 +396,19 @@ classes: the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(FilteredEphys) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true LFP: name: LFP @@ -403,12 +417,19 @@ classes: properties should be noted in the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(LFP) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true ElectrodeGroup: name: ElectrodeGroup diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.language.yaml index e42c742..a921651 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ophys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ophys.yaml index 5041d82..aa4dcd3 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ophys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_3_0/core.nwb.ophys.yaml @@ -169,12 +169,19 @@ classes: for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(DfOverF) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true Fluorescence: name: Fluorescence @@ -183,12 +190,19 @@ classes: for ROIs and for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(Fluorescence) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true ImageSegmentation: name: ImageSegmentation @@ -201,12 +215,19 @@ classes: is required and ROI names should remain consistent between them. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: PlaneSegmentation + name: + name: name + ifabsent: string(ImageSegmentation) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: PlaneSegmentation tree_root: true PlaneSegmentation: name: PlaneSegmentation @@ -602,12 +623,19 @@ classes: frame at each point in time is assumed to be 2-D (has only x & y dimensions).' is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: CorrectedImageStack + name: + name: name + ifabsent: string(MotionCorrection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: CorrectedImageStack tree_root: true CorrectedImageStack: name: CorrectedImageStack diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.base.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.base.yaml index 68f456b..077ab82 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.base.yaml @@ -343,13 +343,24 @@ classes: description: A collection of processed data. is_a: NWBContainer attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: NWBDataInterface - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + description: + name: description + description: Description of this collection of processed data. + range: text + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: NWBDataInterface + - range: DynamicTable tree_root: true Images: name: Images diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.behavior.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.behavior.yaml index 477072b..c16feb9 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.behavior.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.behavior.yaml @@ -127,12 +127,19 @@ classes: events. BehavioralTimeSeries is for continuous data. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: IntervalSeries + name: + name: name + ifabsent: string(BehavioralEpochs) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: IntervalSeries tree_root: true BehavioralEvents: name: BehavioralEvents @@ -140,12 +147,19 @@ classes: for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralEvents) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true BehavioralTimeSeries: name: BehavioralTimeSeries @@ -153,36 +167,57 @@ classes: of BehavioralEpochs for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralTimeSeries) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true PupilTracking: name: PupilTracking description: Eye-tracking data, representing pupil size. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(PupilTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true EyeTracking: name: EyeTracking description: Eye-tracking data, representing direction of gaze. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(EyeTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true CompassDirection: name: CompassDirection @@ -193,22 +228,36 @@ classes: be radians or degrees. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(CompassDirection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true Position: name: Position description: Position data, whether along the x, x/y or x/y/z axis. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(Position) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ecephys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ecephys.yaml index 47187f0..e28b420 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ecephys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ecephys.yaml @@ -367,12 +367,19 @@ classes: during experiment acquisition. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpikeEventSeries + name: + name: name + ifabsent: string(EventWaveform) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpikeEventSeries tree_root: true FilteredEphys: name: FilteredEphys @@ -389,12 +396,19 @@ classes: the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(FilteredEphys) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true LFP: name: LFP @@ -403,12 +417,19 @@ classes: properties should be noted in the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(LFP) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true ElectrodeGroup: name: ElectrodeGroup diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.language.yaml index e42c742..a921651 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ophys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ophys.yaml index c87f8be..d63b6ba 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ophys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_4_0/core.nwb.ophys.yaml @@ -169,12 +169,19 @@ classes: for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(DfOverF) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true Fluorescence: name: Fluorescence @@ -183,12 +190,19 @@ classes: for ROIs and for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(Fluorescence) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true ImageSegmentation: name: ImageSegmentation @@ -201,12 +215,19 @@ classes: is required and ROI names should remain consistent between them. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: PlaneSegmentation + name: + name: name + ifabsent: string(ImageSegmentation) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: PlaneSegmentation tree_root: true PlaneSegmentation: name: PlaneSegmentation @@ -602,12 +623,19 @@ classes: frame at each point in time is assumed to be 2-D (has only x & y dimensions).' is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: CorrectedImageStack + name: + name: name + ifabsent: string(MotionCorrection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: CorrectedImageStack tree_root: true CorrectedImageStack: name: CorrectedImageStack diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.base.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.base.yaml index 5809bb5..a92af97 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.base.yaml @@ -375,13 +375,24 @@ classes: description: A collection of processed data. is_a: NWBContainer attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: NWBDataInterface - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + description: + name: description + description: Description of this collection of processed data. + range: text + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: NWBDataInterface + - range: DynamicTable tree_root: true Images: name: Images diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.behavior.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.behavior.yaml index 9db47e3..cdb2a98 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.behavior.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.behavior.yaml @@ -148,12 +148,19 @@ classes: events. BehavioralTimeSeries is for continuous data. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: IntervalSeries + name: + name: name + ifabsent: string(BehavioralEpochs) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: IntervalSeries tree_root: true BehavioralEvents: name: BehavioralEvents @@ -161,12 +168,19 @@ classes: for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralEvents) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true BehavioralTimeSeries: name: BehavioralTimeSeries @@ -174,36 +188,57 @@ classes: of BehavioralEpochs for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralTimeSeries) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true PupilTracking: name: PupilTracking description: Eye-tracking data, representing pupil size. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(PupilTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true EyeTracking: name: EyeTracking description: Eye-tracking data, representing direction of gaze. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(EyeTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true CompassDirection: name: CompassDirection @@ -214,22 +249,36 @@ classes: be radians or degrees. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(CompassDirection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true Position: name: Position description: Position data, whether along the x, x/y or x/y/z axis. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(Position) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ecephys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ecephys.yaml index 6700cc0..8439a6a 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ecephys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ecephys.yaml @@ -385,12 +385,19 @@ classes: during experiment acquisition. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpikeEventSeries + name: + name: name + ifabsent: string(EventWaveform) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpikeEventSeries tree_root: true FilteredEphys: name: FilteredEphys @@ -407,12 +414,19 @@ classes: the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(FilteredEphys) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true LFP: name: LFP @@ -421,12 +435,19 @@ classes: properties should be noted in the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(LFP) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true ElectrodeGroup: name: ElectrodeGroup diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.language.yaml index e42c742..a921651 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ophys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ophys.yaml index 3658597..2147878 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ophys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_5_0/core.nwb.ophys.yaml @@ -178,12 +178,19 @@ classes: for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(DfOverF) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true Fluorescence: name: Fluorescence @@ -192,12 +199,19 @@ classes: for ROIs and for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(Fluorescence) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true ImageSegmentation: name: ImageSegmentation @@ -210,12 +224,19 @@ classes: is required and ROI names should remain consistent between them. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: PlaneSegmentation + name: + name: name + ifabsent: string(ImageSegmentation) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: PlaneSegmentation tree_root: true PlaneSegmentation: name: PlaneSegmentation @@ -611,12 +632,19 @@ classes: frame at each point in time is assumed to be 2-D (has only x & y dimensions).' is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: CorrectedImageStack + name: + name: name + ifabsent: string(MotionCorrection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: CorrectedImageStack tree_root: true CorrectedImageStack: name: CorrectedImageStack diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.base.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.base.yaml index f7f96c9..13fe72d 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.base.yaml @@ -375,13 +375,24 @@ classes: description: A collection of processed data. is_a: NWBContainer attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: NWBDataInterface - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + description: + name: description + description: Description of this collection of processed data. + range: text + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: NWBDataInterface + - range: DynamicTable tree_root: true Images: name: Images diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.behavior.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.behavior.yaml index 47c9e78..123714b 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.behavior.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.behavior.yaml @@ -148,12 +148,19 @@ classes: events. BehavioralTimeSeries is for continuous data. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: IntervalSeries + name: + name: name + ifabsent: string(BehavioralEpochs) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: IntervalSeries tree_root: true BehavioralEvents: name: BehavioralEvents @@ -161,12 +168,19 @@ classes: for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralEvents) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true BehavioralTimeSeries: name: BehavioralTimeSeries @@ -174,36 +188,57 @@ classes: of BehavioralEpochs for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralTimeSeries) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true PupilTracking: name: PupilTracking description: Eye-tracking data, representing pupil size. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(PupilTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true EyeTracking: name: EyeTracking description: Eye-tracking data, representing direction of gaze. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(EyeTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true CompassDirection: name: CompassDirection @@ -214,22 +249,36 @@ classes: be radians or degrees. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(CompassDirection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true Position: name: Position description: Position data, whether along the x, x/y or x/y/z axis. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(Position) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ecephys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ecephys.yaml index 2434030..0deca51 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ecephys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ecephys.yaml @@ -385,12 +385,19 @@ classes: during experiment acquisition. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpikeEventSeries + name: + name: name + ifabsent: string(EventWaveform) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpikeEventSeries tree_root: true FilteredEphys: name: FilteredEphys @@ -407,12 +414,19 @@ classes: the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(FilteredEphys) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true LFP: name: LFP @@ -421,12 +435,19 @@ classes: properties should be noted in the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(LFP) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true ElectrodeGroup: name: ElectrodeGroup diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.language.yaml index e42c742..a921651 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ophys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ophys.yaml index 9226935..d608587 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ophys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_6_0_alpha/core.nwb.ophys.yaml @@ -232,12 +232,19 @@ classes: for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(DfOverF) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true Fluorescence: name: Fluorescence @@ -246,12 +253,19 @@ classes: for ROIs and for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(Fluorescence) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true ImageSegmentation: name: ImageSegmentation @@ -264,12 +278,19 @@ classes: is required and ROI names should remain consistent between them. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: PlaneSegmentation + name: + name: name + ifabsent: string(ImageSegmentation) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: PlaneSegmentation tree_root: true PlaneSegmentation: name: PlaneSegmentation @@ -665,12 +686,19 @@ classes: frame at each point in time is assumed to be 2-D (has only x & y dimensions).' is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: CorrectedImageStack + name: + name: name + ifabsent: string(MotionCorrection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: CorrectedImageStack tree_root: true CorrectedImageStack: name: CorrectedImageStack diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.base.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.base.yaml index ab0ec35..e158341 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.base.yaml @@ -375,13 +375,24 @@ classes: description: A collection of processed data. is_a: NWBContainer attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: NWBDataInterface - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + description: + name: description + description: Description of this collection of processed data. + range: text + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: NWBDataInterface + - range: DynamicTable tree_root: true Images: name: Images diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.behavior.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.behavior.yaml index 5f2dc7d..6a4ec81 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.behavior.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.behavior.yaml @@ -148,12 +148,19 @@ classes: events. BehavioralTimeSeries is for continuous data. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: IntervalSeries + name: + name: name + ifabsent: string(BehavioralEpochs) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: IntervalSeries tree_root: true BehavioralEvents: name: BehavioralEvents @@ -161,12 +168,19 @@ classes: for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralEvents) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true BehavioralTimeSeries: name: BehavioralTimeSeries @@ -174,36 +188,57 @@ classes: of BehavioralEpochs for more details. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(BehavioralTimeSeries) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true PupilTracking: name: PupilTracking description: Eye-tracking data, representing pupil size. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: TimeSeries + name: + name: name + ifabsent: string(PupilTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: TimeSeries tree_root: true EyeTracking: name: EyeTracking description: Eye-tracking data, representing direction of gaze. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(EyeTracking) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true CompassDirection: name: CompassDirection @@ -214,22 +249,36 @@ classes: be radians or degrees. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(CompassDirection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true Position: name: Position description: Position data, whether along the x, x/y or x/y/z axis. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpatialSeries + name: + name: name + ifabsent: string(Position) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpatialSeries tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ecephys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ecephys.yaml index db3213f..42927b6 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ecephys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ecephys.yaml @@ -385,12 +385,19 @@ classes: during experiment acquisition. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: SpikeEventSeries + name: + name: name + ifabsent: string(EventWaveform) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: SpikeEventSeries tree_root: true FilteredEphys: name: FilteredEphys @@ -407,12 +414,19 @@ classes: the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(FilteredEphys) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true LFP: name: LFP @@ -421,12 +435,19 @@ classes: properties should be noted in the ElectricalSeries 'filtering' attribute. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: ElectricalSeries + name: + name: name + ifabsent: string(LFP) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: ElectricalSeries tree_root: true ElectrodeGroup: name: ElectrodeGroup diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.language.yaml index e42c742..a921651 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ophys.yaml b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ophys.yaml index 61cb747..293371a 100644 --- a/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ophys.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/core/v2_7_0/core.nwb.ophys.yaml @@ -232,12 +232,19 @@ classes: for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(DfOverF) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true Fluorescence: name: Fluorescence @@ -246,12 +253,19 @@ classes: for ROIs and for image planes). is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: RoiResponseSeries + name: + name: name + ifabsent: string(Fluorescence) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: RoiResponseSeries tree_root: true ImageSegmentation: name: ImageSegmentation @@ -264,12 +278,19 @@ classes: is required and ROI names should remain consistent between them. is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: PlaneSegmentation + name: + name: name + ifabsent: string(ImageSegmentation) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: PlaneSegmentation tree_root: true PlaneSegmentation: name: PlaneSegmentation @@ -665,12 +686,19 @@ classes: frame at each point in time is assumed to be 2-D (has only x & y dimensions).' is_a: NWBDataInterface attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: CorrectedImageStack + name: + name: name + ifabsent: string(MotionCorrection) + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: CorrectedImageStack tree_root: true CorrectedImageStack: name: CorrectedImageStack diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_4_0/hdmf-common.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_4_0/hdmf-common.nwb.language.yaml index e3d3df3..9b6bc55 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_4_0/hdmf-common.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_4_0/hdmf-common.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.base.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.base.yaml index 91de7c2..7493ece 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.base.yaml @@ -38,10 +38,16 @@ classes: description: A simple Container for holding onto multiple containers. is_a: Container attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: Container + name: + name: name + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: Container tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.nwb.language.yaml index e3d3df3..1842589 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.nwb.language.yaml @@ -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: @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.table.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.table.yaml index b8e1134..a29024b 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.table.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_0/hdmf-common.table.yaml @@ -189,10 +189,26 @@ classes: by a separate DynamicTable stored within the group. is_a: DynamicTable attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + categories: + name: categories + description: The names of the categories in this AlignedDynamicTable. Each + category is represented by one DynamicTable stored in the parent group. + This attribute should be used to specify an order of categories and the + category names must match the names of the corresponding DynamicTable in + the group. + range: text + required: true + multivalued: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: DynamicTable tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_1/hdmf-common.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_1/hdmf-common.nwb.language.yaml index e3d3df3..9b6bc55 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_1/hdmf-common.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_5_1/hdmf-common.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_6_0/hdmf-common.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_6_0/hdmf-common.nwb.language.yaml index e3d3df3..9b6bc55 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_6_0/hdmf-common.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_6_0/hdmf-common.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_7_0/hdmf-common.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_7_0/hdmf-common.nwb.language.yaml index e3d3df3..9b6bc55 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_7_0/hdmf-common.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_7_0/hdmf-common.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.base.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.base.yaml index ea83af3..3a89816 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.base.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.base.yaml @@ -38,10 +38,16 @@ classes: description: A simple Container for holding onto multiple containers. is_a: Container attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: Container + name: + name: name + identifier: true + range: string + required: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: Container tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.nwb.language.yaml index e3d3df3..1842589 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.nwb.language.yaml @@ -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: @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.table.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.table.yaml index c7f3d0d..8b73408 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.table.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_common/v1_8_0/hdmf-common.table.yaml @@ -189,10 +189,26 @@ classes: by a separate DynamicTable stored within the group. is_a: DynamicTable attributes: - - name: value - multivalued: true - inlined: true - inlined_as_list: false - any_of: - - range: DynamicTable + name: + name: name + identifier: true + range: string + required: true + categories: + name: categories + description: The names of the categories in this AlignedDynamicTable. Each + category is represented by one DynamicTable stored in the parent group. + This attribute should be used to specify an order of categories and the + category names must match the names of the corresponding DynamicTable in + the group. + range: text + required: true + multivalued: true + value: + name: value + multivalued: true + inlined: true + inlined_as_list: false + any_of: + - range: DynamicTable tree_root: true diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.experimental.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.experimental.yaml index 2a10ba2..b0b87d5 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.experimental.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.experimental.yaml @@ -9,7 +9,7 @@ annotations: id: hdmf-experimental.experimental version: 0.1.0 imports: -- ../../hdmf_common/v1_4_0/namespace +- ../../hdmf_common/v1_5_0/namespace - hdmf-experimental.nwb.language default_prefix: hdmf-experimental.experimental/ classes: diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.nwb.language.yaml index 0a824ca..650c484 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.nwb.language.yaml @@ -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: @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.resources.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.resources.yaml index a8d955d..9aeb7d0 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.resources.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_1_0/hdmf-experimental.resources.yaml @@ -9,7 +9,7 @@ annotations: id: hdmf-experimental.resources version: 0.1.0 imports: -- ../../hdmf_common/v1_4_0/namespace +- ../../hdmf_common/v1_5_0/namespace - hdmf-experimental.nwb.language default_prefix: hdmf-experimental.resources/ classes: diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_2_0/hdmf-experimental.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_2_0/hdmf-experimental.nwb.language.yaml index 0a824ca..b487163 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_2_0/hdmf-experimental.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_2_0/hdmf-experimental.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_3_0/hdmf-experimental.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_3_0/hdmf-experimental.nwb.language.yaml index 0a824ca..b487163 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_3_0/hdmf-experimental.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_3_0/hdmf-experimental.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_4_0/hdmf-experimental.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_4_0/hdmf-experimental.nwb.language.yaml index 0a824ca..b487163 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_4_0/hdmf-experimental.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_4_0/hdmf-experimental.nwb.language.yaml @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string diff --git a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_5_0/hdmf-experimental.nwb.language.yaml b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_5_0/hdmf-experimental.nwb.language.yaml index 0a824ca..650c484 100644 --- a/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_5_0/hdmf-experimental.nwb.language.yaml +++ b/nwb_models/src/nwb_models/schema/linkml/hdmf_experimental/v0_5_0/hdmf-experimental.nwb.language.yaml @@ -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: @@ -66,6 +66,7 @@ types: numeric: name: numeric typeof: float + repr: float | int text: name: text typeof: string