Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable read method again with the new add API #1243

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
evetion marked this conversation as resolved.
Show resolved Hide resolved

def add(
self,
from_node: NodeData,
Expand Down
28 changes: 5 additions & 23 deletions python/ribasim/tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import ribasim
import tomli
from numpy.testing import assert_array_equal
from pandas import DataFrame
from pandas.testing import assert_frame_equal
from pydantic import ValidationError
Expand All @@ -17,9 +16,9 @@ def __assert_equal(a: DataFrame, b: DataFrame, is_network=False) -> None:
# We set this on write, needed for GeoPackage.
a.index.name = "fid"
a.index.name = "fid"
else:
a = a.reset_index(drop=True)
b = b.reset_index(drop=True)

a = a.reset_index(drop=True)
b = b.reset_index(drop=True)

# avoid comparing datetime64[ns] with datetime64[ms]
if "time" in a:
Expand All @@ -34,7 +33,6 @@ def __assert_equal(a: DataFrame, b: DataFrame, is_network=False) -> None:
return assert_frame_equal(a, b)


@pytest.mark.xfail(reason="Needs Model read implementation")
def test_basic(basic, tmp_path):
model_orig = basic
toml_path = tmp_path / "basic/ribasim.toml"
Expand All @@ -46,19 +44,10 @@ def test_basic(basic, tmp_path):

assert toml_dict["ribasim_version"] == ribasim.__version__

index_a = model_orig.network.node.df.index.to_numpy(int)
index_b = model_loaded.network.node.df.index.to_numpy(int)
assert_array_equal(index_a, index_b)
__assert_equal(
model_orig.network.node.df, model_loaded.network.node.df, is_network=True
)
__assert_equal(
model_orig.network.edge.df, model_loaded.network.edge.df, is_network=True
)
__assert_equal(model_orig.edge.df, model_loaded.edge.df, is_network=True)
assert model_loaded.basin.time.df is None


@pytest.mark.xfail(reason="Needs Model read implementation")
def test_basic_arrow(basic_arrow, tmp_path):
model_orig = basic_arrow
model_orig.write(tmp_path / "basic_arrow/ribasim.toml")
Expand All @@ -67,18 +56,12 @@ def test_basic_arrow(basic_arrow, tmp_path):
__assert_equal(model_orig.basin.profile.df, model_loaded.basin.profile.df)


@pytest.mark.xfail(reason="Needs Model read implementation")
def test_basic_transient(basic_transient, tmp_path):
model_orig = basic_transient
model_orig.write(tmp_path / "basic_transient/ribasim.toml")
model_loaded = ribasim.Model(filepath=tmp_path / "basic_transient/ribasim.toml")

__assert_equal(
model_orig.network.node.df, model_loaded.network.node.df, is_network=True
)
__assert_equal(
model_orig.network.edge.df, model_loaded.network.edge.df, is_network=True
)
__assert_equal(model_orig.edge.df, model_loaded.edge.df, is_network=True)

time = model_loaded.basin.time
assert model_orig.basin.time.df.time[0] == time.df.time[0]
Expand Down Expand Up @@ -111,7 +94,6 @@ def test_extra_columns(basic_transient):
terminal.Static(meta_id=[-1, -2, -3], extra=[-1, -2, -3])


@pytest.mark.xfail(reason="Needs Model read implementation")
def test_sort(level_setpoint_with_minmax, tmp_path):
model = level_setpoint_with_minmax
table = model.discrete_control.condition
Expand Down
3 changes: 1 addition & 2 deletions python/ribasim/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def test_node_ids_unsequential(basic):
model.validate_model_node_field_ids()


@pytest.mark.xfail(reason="Needs Model read implementation")
def test_tabulated_rating_curve_model(tabulated_rating_curve, tmp_path):
model_orig = tabulated_rating_curve
basin_area = tabulated_rating_curve.basin.area.df
Expand All @@ -155,7 +154,7 @@ def test_write_adds_fid_in_tables(basic, tmp_path):
# for node an explicit index was provided
nrow = len(model_orig.basin.node.df)
assert model_orig.basin.node.df.index.name is None
# assert model_orig.basin.node.df.index.equals(pd.Index(np.full(nrow, 0)))

# for edge no index was provided, but it still needs to write it to file
nrow = len(model_orig.edge.df)
assert model_orig.edge.df.index.name is None
Expand Down
Loading