Skip to content

Commit

Permalink
Fix model plotting while still ensuring that Edge tables are written
Browse files Browse the repository at this point in the history
Fixes #1236
  • Loading branch information
Hofer-Julian committed Mar 13, 2024
1 parent 5e9231f commit ed02392
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 1 addition & 5 deletions python/ribasim/ribasim/geometry/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from geopandas import GeoDataFrame
from matplotlib.axes import Axes
from numpy.typing import NDArray
from pandera.typing import DataFrame, Series
from pandera.typing import Series
from pandera.typing.geopandas import GeoSeries
from shapely.geometry import LineString, MultiLineString, Point

Expand Down Expand Up @@ -42,10 +42,6 @@ class Config:
class EdgeTable(SpatialTableModel[EdgeSchema]):
"""Defines the connections between nodes."""

def __init__(self, **kwargs):
kwargs.setdefault("df", DataFrame[EdgeSchema]())
super().__init__(**kwargs)

def add(
self,
from_node: NodeData,
Expand Down
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/geometry/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class NodeSchema(pa.SchemaModel):
node_id: Series[int]
node_id: Series[int] = pa.Field(nullable=False, default=0)
name: Series[str] = pa.Field(default="")
node_type: Series[str] = pa.Field(default="")
subnetwork_id: Series[pd.Int64Dtype] = pa.Field(
Expand Down
6 changes: 3 additions & 3 deletions python/ribasim/ribasim/input_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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)

Expand Down Expand Up @@ -358,8 +358,8 @@ def _write_table(self, path: FilePath) -> None:
----------
path : FilePath
"""

gdf = gpd.GeoDataFrame(data=self.df)
df = DataFrame[self.tableschema()]() if self.df is None else self.df # type:ignore
gdf = gpd.GeoDataFrame(data=df)
gdf = gdf.set_geometry("geometry")
gdf.to_file(path, layer=self.tablename(), driver="GPKG", mode="a")

Expand Down

0 comments on commit ed02392

Please sign in to comment.