Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate edges #1719

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/ribasim/ribasim/geometry/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def add(
self.df = GeoDataFrame[EdgeSchema](
pd.concat([self.df, table_to_append], ignore_index=True)
)
if self.df.duplicated(subset=["from_node_id", "to_node_id"]).any():
raise ValueError(
f"Edges have to be unique, but edge ({from_node.node_id}, {to_node.node_id}) already exists."
)
self.df.index.name = "fid"

def _get_where_edge_type(self, edge_type: str) -> NDArray[np.bool_]:
Expand Down
13 changes: 13 additions & 0 deletions python/ribasim/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ def test_edge_table(basic):
assert df.crs == CRS.from_epsg(28992)


def test_duplicate_edge(trivial):
model = trivial
with pytest.raises(
ValueError,
match=re.escape("Edges have to be unique, but edge (6, 0) already exists."),
):
model.edge.add(
model.basin[6],
model.tabulated_rating_curve[0],
name="duplicate",
)


def test_indexing(basic):
model = basic

Expand Down