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

Prevent duplicate edges in Ribasim Python #1255

Closed
visr opened this issue Mar 13, 2024 · 2 comments · Fixed by #1719
Closed

Prevent duplicate edges in Ribasim Python #1255

visr opened this issue Mar 13, 2024 · 2 comments · Fixed by #1719
Assignees
Labels
enhancement New feature or request python Relates to one of the Ribasim python packages

Comments

@visr
Copy link
Member

visr commented Mar 13, 2024

Currently adding the same edge twice:

model.edge.add(model.basin[1], model.manning_resistance[2], "flow", name="a")
model.edge.add(model.basin[1], model.manning_resistance[2], "flow", name="b")

will add a duplicate row to the Edge table.

Not sure how to best implement it. Probably it would be nicest to have the second edge overwrite the first one, because then we can update names or geometries. Though if that is hard, a no-op on the second line would also be an improvement.

@Huite
Copy link
Contributor

Huite commented Mar 14, 2024

combine_first might be useful here, or merge. I think they might be bit difficult to control though.

I think the most straightforward option is this, in the add method:

            self.df = GeoDataFrame[EdgeSchema](pd.concat([self.df, table_to_append]))
            self.df = self.df.drop_duplicates(subset=("from_node_type", "from_node_id", "to_node_type", "edge_type"), keep="last")

Not sure about the ignore_index argument: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop_duplicates.html

@visr visr added enhancement New feature or request python Relates to one of the Ribasim python packages labels Mar 14, 2024
@visr
Copy link
Member Author

visr commented Aug 13, 2024

Let's throw an error on edge.add. Check for duplicates in a similar way to how #1717 checks for duplicate node ID adds; keep a set with the unique (from_node_id, to_node_id) keys. Best done after #1717 is merged since otherwise we also need from_node_type, to_node_type.

@Jingru923 Jingru923 linked a pull request Aug 13, 2024 that will close this issue
visr added a commit that referenced this issue Aug 13, 2024
Fixes #1255
It gives an error if a duplicated edge is added. Unit test is added as
well

---------

Co-authored-by: Martijn Visser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Relates to one of the Ribasim python packages
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants