Skip to content

Commit

Permalink
Set the Node fid back to the node_id
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Mar 25, 2024
1 parent fe57d38 commit 4571319
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Any

import geopandas as gpd
import pandas as pd
import tomli
import tomli_w
Expand Down Expand Up @@ -138,6 +139,16 @@ def _save(self, directory: DirectoryPath, input_dir: DirectoryPath):
for sub in self._nodes():
sub._save(directory, input_dir)

# Temporarily require unique node_id for #1262
# and copy them to the fid for #1306.
df = gpd.read_file(db_path, layer="Node")
if not df["node_id"].is_unique:
raise ValueError("node_id must be unique")

Check warning on line 146 in python/ribasim/ribasim/model.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/model.py#L146

Added line #L146 was not covered by tests
df.set_index("node_id", drop=False, inplace=True)
df.sort_index(inplace=True)
df.index.name = "fid"
df.to_file(db_path, layer="Node", driver="GPKG", index=True)

def node_table(self) -> NodeTable:
"""Compute the full NodeTable from all node types."""
df_chunks = [node.node.df for node in self._nodes()]
Expand Down

0 comments on commit 4571319

Please sign in to comment.