Skip to content

Commit

Permalink
Please mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Apr 30, 2024
1 parent f7a88c9 commit 4f2a7fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def _save(self, directory: DirectoryPath, input_dir: DirectoryPath):
self.edge._save(directory, input_dir)

node = self.node_table()
assert node.df is not None
# Temporarily require unique node_id for #1262
# and copy them to the fid for #1306.
if not node.df["node_id"].is_unique:
Expand Down Expand Up @@ -203,10 +204,11 @@ def _apply_crs_function(self, function_name: str, crs: str) -> None:

def node_table(self) -> NodeTable:
"""Compute the full NodeTable from all node types."""
df_chunks = [node.node.df.set_crs(self.crs) for node in self._nodes()]
df_chunks = [node.node.df.set_crs(self.crs) for node in self._nodes()] # type: ignore
df = pd.concat(df_chunks, ignore_index=True)
node_table = NodeTable(df=df)
node_table.sort()
assert node_table.df is not None
node_table.df.index.name = "fid"
return node_table

Expand Down Expand Up @@ -403,13 +405,15 @@ def to_xugrid(self, add_results: bool = True):
if the optional dependency `xugrid` isn't installed.
"""
node_df = self.node_table().df
assert node_df is not None

# This will need to be adopted for locally unique node IDs,
# otherwise the `node_lookup` with `argsort` is not correct.
if not node_df.node_id.is_unique:
raise ValueError("node_id must be unique")
node_df.sort_values("node_id", inplace=True)

assert self.edge.df is not None
edge_df = self.edge.df.copy()
# We assume only the flow network is of interest.
edge_df = edge_df[edge_df.edge_type == "flow"]
Expand Down

0 comments on commit 4f2a7fd

Please sign in to comment.