Prevent duplicate edges in Ribasim Python
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.
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
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.