@@ -1326,18 +1326,19 @@ def _check_all_items_match(self, other: "Dataset") -> None:
1326
1326
raise ValueError (
1327
1327
f"Number of items must match ({ self .n_items } and { other .n_items } )"
1328
1328
)
1329
- for j in range (self .n_items ):
1330
- if self .items [j ].name != other .items [j ].name :
1329
+
1330
+ for this , that in zip (self .items , other .items ):
1331
+ if this .name != that .name :
1331
1332
raise ValueError (
1332
- f"Item names must match. Item { j } : { self . items [ j ]. name } != { other . items [ j ] .name } "
1333
+ f"Item names must match. Item: { this . name } != { that .name } "
1333
1334
)
1334
- if self . items [ j ]. type != other . items [ j ] .type :
1335
+ if this . type != that .type :
1335
1336
raise ValueError (
1336
- f"Item types must match. Item { j } : { self . items [ j ]. type } != { other . items [ j ] .type } "
1337
+ f"Item types must match. Item: { this . type } != { that .type } "
1337
1338
)
1338
- if self . items [ j ]. unit != other . items [ j ] .unit :
1339
+ if this . unit != that .unit :
1339
1340
raise ValueError (
1340
- f"Item units must match. Item { j } : { self . items [ j ]. unit } != { other . items [ j ] .unit } "
1341
+ f"Item units must match. Item: { this . unit } != { that .unit } "
1341
1342
)
1342
1343
1343
1344
# ============ aggregate =============
@@ -1771,24 +1772,13 @@ def _add_dataset(self, other: "Dataset", sign: float = 1.0) -> "Dataset":
1771
1772
except TypeError :
1772
1773
raise TypeError ("Could not add data in Dataset" )
1773
1774
newds = self .copy ()
1774
- for j in range ( len ( self ) ):
1775
- newds [ j ] .values = data [ j ] # type: ignore
1775
+ for new , old in zip ( newds , data ):
1776
+ new .values = old
1776
1777
return newds
1777
1778
1778
1779
def _check_datasets_match (self , other : "Dataset" ) -> None :
1779
- if self .n_items != other .n_items :
1780
- raise ValueError (
1781
- f"Number of items must match ({ self .n_items } and { other .n_items } )"
1782
- )
1783
- for j in range (self .n_items ):
1784
- if self .items [j ].type != other .items [j ].type :
1785
- raise ValueError (
1786
- f"Item types must match. Item { j } : { self .items [j ].type } != { other .items [j ].type } "
1787
- )
1788
- if self .items [j ].unit != other .items [j ].unit :
1789
- raise ValueError (
1790
- f"Item units must match. Item { j } : { self .items [j ].unit } != { other .items [j ].unit } "
1791
- )
1780
+ self ._check_all_items_match (other )
1781
+
1792
1782
if not np .all (self .time == other .time ):
1793
1783
raise ValueError ("All timesteps must match" )
1794
1784
if self .shape != other .shape :
0 commit comments