Skip to content

Commit 666ced4

Browse files
committed
Use zip
1 parent c5a8ef9 commit 666ced4

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

mikeio/dataset/_dataset.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,18 +1326,19 @@ def _check_all_items_match(self, other: "Dataset") -> None:
13261326
raise ValueError(
13271327
f"Number of items must match ({self.n_items} and {other.n_items})"
13281328
)
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:
13311332
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}"
13331334
)
1334-
if self.items[j].type != other.items[j].type:
1335+
if this.type != that.type:
13351336
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}"
13371338
)
1338-
if self.items[j].unit != other.items[j].unit:
1339+
if this.unit != that.unit:
13391340
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}"
13411342
)
13421343

13431344
# ============ aggregate =============
@@ -1771,24 +1772,13 @@ def _add_dataset(self, other: "Dataset", sign: float = 1.0) -> "Dataset":
17711772
except TypeError:
17721773
raise TypeError("Could not add data in Dataset")
17731774
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
17761777
return newds
17771778

17781779
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+
17921782
if not np.all(self.time == other.time):
17931783
raise ValueError("All timesteps must match")
17941784
if self.shape != other.shape:

0 commit comments

Comments
 (0)