From 02e5c48c482580e2c7b258bb1a9ef63887d4feb5 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Fri, 8 Mar 2024 17:12:57 +0100 Subject: [PATCH] Try supporting no edges but failing Co-authored-by: Hofer-Julian --- python/ribasim/ribasim/geometry/edge.py | 5 ++++- python/ribasim/ribasim/input_base.py | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/python/ribasim/ribasim/geometry/edge.py b/python/ribasim/ribasim/geometry/edge.py index ed9b674f1..08454b4dd 100644 --- a/python/ribasim/ribasim/geometry/edge.py +++ b/python/ribasim/ribasim/geometry/edge.py @@ -8,7 +8,7 @@ from geopandas import GeoDataFrame from matplotlib.axes import Axes from numpy.typing import NDArray -from pandera.typing import Series +from pandera.typing import DataFrame, Series from pandera.typing.geopandas import GeoSeries from shapely.geometry import LineString, MultiLineString, Point @@ -49,6 +49,9 @@ class Edge(SpatialTableModel[EdgeSchema]): Table describing the flow connections. """ + def __init__(self): + super().__init__(df=DataFrame[EdgeSchema]()) + def add( self, from_node: NodeData, diff --git a/python/ribasim/ribasim/input_base.py b/python/ribasim/ribasim/input_base.py index 53ac49690..e173cb30d 100644 --- a/python/ribasim/ribasim/input_base.py +++ b/python/ribasim/ribasim/input_base.py @@ -233,7 +233,7 @@ def _save( if self.df is not None and self.filepath is not None: self.sort() self._write_arrow(self.filepath, directory, input_dir) - elif self.df is not None and db_path is not None: + elif db_path is not None: self.sort() self._write_table(db_path) @@ -247,7 +247,8 @@ def _write_table(self, temp_path: Path) -> None: SQLite connection to the database. """ table = self.tablename() - assert self.df is not None + if self.df is None: + return # Add `fid` to all tables as primary key # Enables editing values manually in QGIS @@ -361,7 +362,8 @@ def _write_table(self, path: FilePath) -> None: gdf.to_file(path, layer=self.tablename(), driver="GPKG", mode="a") def sort(self): - self.df.sort_index(inplace=True) + if self.df is not None: + self.df.sort_index(inplace=True) class ChildModel(BaseModel):