From f5a41734948c0ff2de4fb3585290d77d3b792f13 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Thu, 15 Aug 2024 01:47:55 -0700 Subject: [PATCH] update models --- .../pydantic/core/v2_4_0/core_nwb_base.py | 39 ++++++++++++------- .../pydantic/core/v2_5_0/core_nwb_base.py | 39 ++++++++++++------- .../core/v2_6_0_alpha/core_nwb_base.py | 39 ++++++++++++------- .../pydantic/core/v2_7_0/core_nwb_base.py | 39 ++++++++++++------- 4 files changed, 96 insertions(+), 60 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_4_0/core_nwb_base.py b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_4_0/core_nwb_base.py index 2328c2c..9ec8413 100644 --- a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_4_0/core_nwb_base.py +++ b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_4_0/core_nwb_base.py @@ -134,9 +134,9 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): for index, span, and timeseries """ - idx_start: NDArray[Any, int] - count: NDArray[Any, int] - timeseries: NDArray[Any, BaseModel] + idx_start: NDArray[Shape["*"], int] + count: NDArray[Shape["*"], int] + timeseries: NDArray @model_validator(mode="after") def ensure_equal_length(self) -> "TimeSeriesReferenceVectorDataMixin": @@ -175,11 +175,11 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): ) if isinstance(item, (int, np.integer)): - return self.timeseries[self._slice_helper(item)] - elif isinstance(item, slice): - return [self.timeseries[subitem] for subitem in self._slice_helper(item)] - elif isinstance(item, Iterable): - return [self.timeseries[self._slice_helper(subitem)] for subitem in item] + return self.timeseries[item][self._slice_helper(item)] + elif isinstance(item, (slice, Iterable)): + if isinstance(item, slice): + item = range(*item.indices(len(self.idx_start))) + return [self.timeseries[subitem][self._slice_helper(subitem)] for subitem in item] else: raise ValueError( f"Dont know how to index with {item}, must be an int, slice, or iterable" @@ -192,13 +192,22 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): " never done in the core schema." ) if isinstance(key, (int, np.integer)): - self.timeseries[self._slice_helper(key)] = value - elif isinstance(key, slice): - for subitem in self._slice_helper(key): - self.timeseries[subitem] = value - elif isinstance(key, Iterable): - for subitem in key: - self.timeseries[self._slice_helper(subitem)] = value + self.timeseries[key][self._slice_helper(key)] = value + elif isinstance(key, (slice, Iterable)): + if isinstance(key, slice): + key = range(*key.indices(len(self.idx_start))) + + if isinstance(value, Iterable): + if len(key) != len(value): + raise ValueError( + "Can only assign equal-length iterable to a slice, manually index the" + " target Timeseries object if you need more control" + ) + for subitem, subvalue in zip(key, value): + self.timeseries[subitem][self._slice_helper(subitem)] = subvalue + else: + for subitem in key: + self.timeseries[subitem][self._slice_helper(subitem)] = value else: raise ValueError( f"Dont know how to index with {key}, must be an int, slice, or iterable" diff --git a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_5_0/core_nwb_base.py b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_5_0/core_nwb_base.py index d080acf..aefea7a 100644 --- a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_5_0/core_nwb_base.py +++ b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_5_0/core_nwb_base.py @@ -145,9 +145,9 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): for index, span, and timeseries """ - idx_start: NDArray[Any, int] - count: NDArray[Any, int] - timeseries: NDArray[Any, BaseModel] + idx_start: NDArray[Shape["*"], int] + count: NDArray[Shape["*"], int] + timeseries: NDArray @model_validator(mode="after") def ensure_equal_length(self) -> "TimeSeriesReferenceVectorDataMixin": @@ -186,11 +186,11 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): ) if isinstance(item, (int, np.integer)): - return self.timeseries[self._slice_helper(item)] - elif isinstance(item, slice): - return [self.timeseries[subitem] for subitem in self._slice_helper(item)] - elif isinstance(item, Iterable): - return [self.timeseries[self._slice_helper(subitem)] for subitem in item] + return self.timeseries[item][self._slice_helper(item)] + elif isinstance(item, (slice, Iterable)): + if isinstance(item, slice): + item = range(*item.indices(len(self.idx_start))) + return [self.timeseries[subitem][self._slice_helper(subitem)] for subitem in item] else: raise ValueError( f"Dont know how to index with {item}, must be an int, slice, or iterable" @@ -203,13 +203,22 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): " never done in the core schema." ) if isinstance(key, (int, np.integer)): - self.timeseries[self._slice_helper(key)] = value - elif isinstance(key, slice): - for subitem in self._slice_helper(key): - self.timeseries[subitem] = value - elif isinstance(key, Iterable): - for subitem in key: - self.timeseries[self._slice_helper(subitem)] = value + self.timeseries[key][self._slice_helper(key)] = value + elif isinstance(key, (slice, Iterable)): + if isinstance(key, slice): + key = range(*key.indices(len(self.idx_start))) + + if isinstance(value, Iterable): + if len(key) != len(value): + raise ValueError( + "Can only assign equal-length iterable to a slice, manually index the" + " target Timeseries object if you need more control" + ) + for subitem, subvalue in zip(key, value): + self.timeseries[subitem][self._slice_helper(subitem)] = subvalue + else: + for subitem in key: + self.timeseries[subitem][self._slice_helper(subitem)] = value else: raise ValueError( f"Dont know how to index with {key}, must be an int, slice, or iterable" diff --git a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py index 26677a0..624853e 100644 --- a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py +++ b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_6_0_alpha/core_nwb_base.py @@ -145,9 +145,9 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): for index, span, and timeseries """ - idx_start: NDArray[Any, int] - count: NDArray[Any, int] - timeseries: NDArray[Any, BaseModel] + idx_start: NDArray[Shape["*"], int] + count: NDArray[Shape["*"], int] + timeseries: NDArray @model_validator(mode="after") def ensure_equal_length(self) -> "TimeSeriesReferenceVectorDataMixin": @@ -186,11 +186,11 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): ) if isinstance(item, (int, np.integer)): - return self.timeseries[self._slice_helper(item)] - elif isinstance(item, slice): - return [self.timeseries[subitem] for subitem in self._slice_helper(item)] - elif isinstance(item, Iterable): - return [self.timeseries[self._slice_helper(subitem)] for subitem in item] + return self.timeseries[item][self._slice_helper(item)] + elif isinstance(item, (slice, Iterable)): + if isinstance(item, slice): + item = range(*item.indices(len(self.idx_start))) + return [self.timeseries[subitem][self._slice_helper(subitem)] for subitem in item] else: raise ValueError( f"Dont know how to index with {item}, must be an int, slice, or iterable" @@ -203,13 +203,22 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): " never done in the core schema." ) if isinstance(key, (int, np.integer)): - self.timeseries[self._slice_helper(key)] = value - elif isinstance(key, slice): - for subitem in self._slice_helper(key): - self.timeseries[subitem] = value - elif isinstance(key, Iterable): - for subitem in key: - self.timeseries[self._slice_helper(subitem)] = value + self.timeseries[key][self._slice_helper(key)] = value + elif isinstance(key, (slice, Iterable)): + if isinstance(key, slice): + key = range(*key.indices(len(self.idx_start))) + + if isinstance(value, Iterable): + if len(key) != len(value): + raise ValueError( + "Can only assign equal-length iterable to a slice, manually index the" + " target Timeseries object if you need more control" + ) + for subitem, subvalue in zip(key, value): + self.timeseries[subitem][self._slice_helper(subitem)] = subvalue + else: + for subitem in key: + self.timeseries[subitem][self._slice_helper(subitem)] = value else: raise ValueError( f"Dont know how to index with {key}, must be an int, slice, or iterable" diff --git a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_7_0/core_nwb_base.py b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_7_0/core_nwb_base.py index 096733f..09a6f8b 100644 --- a/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_7_0/core_nwb_base.py +++ b/nwb_linkml/src/nwb_linkml/models/pydantic/core/v2_7_0/core_nwb_base.py @@ -145,9 +145,9 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): for index, span, and timeseries """ - idx_start: NDArray[Any, int] - count: NDArray[Any, int] - timeseries: NDArray[Any, BaseModel] + idx_start: NDArray[Shape["*"], int] + count: NDArray[Shape["*"], int] + timeseries: NDArray @model_validator(mode="after") def ensure_equal_length(self) -> "TimeSeriesReferenceVectorDataMixin": @@ -186,11 +186,11 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): ) if isinstance(item, (int, np.integer)): - return self.timeseries[self._slice_helper(item)] - elif isinstance(item, slice): - return [self.timeseries[subitem] for subitem in self._slice_helper(item)] - elif isinstance(item, Iterable): - return [self.timeseries[self._slice_helper(subitem)] for subitem in item] + return self.timeseries[item][self._slice_helper(item)] + elif isinstance(item, (slice, Iterable)): + if isinstance(item, slice): + item = range(*item.indices(len(self.idx_start))) + return [self.timeseries[subitem][self._slice_helper(subitem)] for subitem in item] else: raise ValueError( f"Dont know how to index with {item}, must be an int, slice, or iterable" @@ -203,13 +203,22 @@ class TimeSeriesReferenceVectorDataMixin(VectorDataMixin): " never done in the core schema." ) if isinstance(key, (int, np.integer)): - self.timeseries[self._slice_helper(key)] = value - elif isinstance(key, slice): - for subitem in self._slice_helper(key): - self.timeseries[subitem] = value - elif isinstance(key, Iterable): - for subitem in key: - self.timeseries[self._slice_helper(subitem)] = value + self.timeseries[key][self._slice_helper(key)] = value + elif isinstance(key, (slice, Iterable)): + if isinstance(key, slice): + key = range(*key.indices(len(self.idx_start))) + + if isinstance(value, Iterable): + if len(key) != len(value): + raise ValueError( + "Can only assign equal-length iterable to a slice, manually index the" + " target Timeseries object if you need more control" + ) + for subitem, subvalue in zip(key, value): + self.timeseries[subitem][self._slice_helper(subitem)] = subvalue + else: + for subitem in key: + self.timeseries[subitem][self._slice_helper(subitem)] = value else: raise ValueError( f"Dont know how to index with {key}, must be an int, slice, or iterable"