diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d0609d633..b2d596187 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,7 +16,7 @@ jobs: - name: Set up uv uses: astral-sh/setup-uv@v6 with: - python-version: "3.14" + python-version: "3.13" # Need to use 3.13 for docs build due to pythonnet dependency not yet supporting 3.14 enable-cache: true - name: Set up Quarto diff --git a/src/modelskill/model/adapters/_res1d.py b/src/modelskill/model/adapters/_res1d.py index 8dc0c5ad9..63efdf014 100644 --- a/src/modelskill/model/adapters/_res1d.py +++ b/src/modelskill/model/adapters/_res1d.py @@ -12,16 +12,17 @@ def _simplify_res1d_colnames(node: ResultNode | ResultGridPoint) -> pd.DataFrame: # We remove suffixes and indexes so the columns contain only the quantity names + RES1D_NAME_SEP = ":" df = node.to_dataframe() - quantities = node.quantities renamer_dict = {} - for quantity in quantities: - relevant_columns = [col for col in df.columns if quantity in col] - if len(relevant_columns) != 1: + for quantity in node.quantities: + column_pairs = [(col, quantity) for col in df.columns if quantity in col.split(RES1D_NAME_SEP)] + if len(column_pairs) != 1: raise ValueError( - f"There must be exactly one column per quantity, found {relevant_columns}." + f"There must be exactly one column per quantity, found {column_pairs}." ) - renamer_dict[relevant_columns[0]] = quantity + old_name, new_name = column_pairs[0] + renamer_dict[old_name] = new_name return df.rename(columns=renamer_dict).copy() diff --git a/src/modelskill/network.py b/src/modelskill/network.py index ae3f492e0..184c27ee4 100644 --- a/src/modelskill/network.py +++ b/src/modelskill/network.py @@ -13,6 +13,8 @@ from __future__ import annotations +import sys + from abc import ABC, abstractmethod from pathlib import Path from typing import Any, Sequence, overload, TYPE_CHECKING @@ -357,9 +359,13 @@ def from_res1d(cls, res: str | Path | Res1D) -> Network: >>> network = Network.from_res1d("model.res1d") >>> network = Network.from_res1d(Res1D("model.res1d")) """ + if sys.version_info >= (3, 14): + raise NotImplementedError(f"Current version of 'mikeio1d' requires python < 3.14 and {sys.version} is being used.") + from mikeio1d import Res1D as _Res1D from modelskill.model.adapters._res1d import Res1DReach + if isinstance(res, (str, Path)): path = Path(res) if path.suffix.lower() != ".res1d": diff --git a/tests/notebooks/test_notebooks.py b/tests/notebooks/test_notebooks.py index 5bd369390..e44be8975 100644 --- a/tests/notebooks/test_notebooks.py +++ b/tests/notebooks/test_notebooks.py @@ -7,7 +7,8 @@ _TEST_DIR = os.path.dirname(os.path.abspath(__file__)) PARENT_DIR = os.path.join(_TEST_DIR, "../..") -SKIP_LIST = ["Download", "Metocean_track_comparison_global", "Metrics_widget"] +SKIP_LIST = ["Download", "Metocean_track_comparison_global", "Metrics_widget", "Collection_systems_network"] +# We skip Collection_systems_network.ipynb since it uses Network.from_res1d() which uses pythonnet and, currently, it does not support python 3.14 def _process_notebook(notebook_filename, notebook_path="notebooks"): diff --git a/tests/test_network.py b/tests/test_network.py index 90aec5583..6dc6e215f 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -1,6 +1,7 @@ """Test network models and observations""" # ruff: noqa: E402 +import sys import pytest pytest.importorskip("networkx") @@ -434,3 +435,10 @@ def test_matching_workflow_multiple_nodes(self, sample_network, sample_node_data for comparer in comparer_collection: assert "Network_Model" in comparer.mod_names assert comparer.n_points > 0 + + +@pytest.mark.skipif(sys.version_info >= (3, 14), reason="mikeio1d requires Python < 3.14") +def test_open_res1d(): + path_to_file = "./tests/testdata/network.res1d" + network = Network.from_res1d(path_to_file) + assert network.graph.number_of_nodes() == 259 \ No newline at end of file