diff --git a/modelskill/comparison/_comparison.py b/modelskill/comparison/_comparison.py index 29f37864..1545f033 100644 --- a/modelskill/comparison/_comparison.py +++ b/modelskill/comparison/_comparison.py @@ -410,7 +410,7 @@ def _matched_data_to_xarray( if z is not None: ds.coords["z"] = z - if np.isscalar(ds.coords["x"]): + if ds.coords["x"].size == 1: ds.attrs["gtype"] = str(GeometryType.POINT) else: ds.attrs["gtype"] = str(GeometryType.TRACK) diff --git a/pyproject.toml b/pyproject.toml index 7cb2370a..f7150955 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ test = [ "dask", "mypy", "types-PyYAML", + "geopandas", ] notebooks = [ diff --git a/tests/test_comparer.py b/tests/test_comparer.py index 4bdc2d17..70fee2eb 100644 --- a/tests/test_comparer.py +++ b/tests/test_comparer.py @@ -86,6 +86,7 @@ def tc() -> Comparer: def test_matched_df(pt_df): cmp = Comparer.from_matched_data(data=pt_df) + assert cmp.gtype == "point" assert "m2" in cmp.mod_names assert "m1" in cmp.mod_names assert len(cmp.mod_names) == 2 @@ -95,6 +96,14 @@ def test_matched_df(pt_df): assert cmp.score()["m2"] == pytest.approx(0.15811388300841905) +def test_matched_skill_geodataframe(pt_df): + cmp = Comparer.from_matched_data(data=pt_df, x=10.0, y=55.0) + sk = cmp.skill() + gdf = sk.to_geodataframe() + assert gdf.iloc[0].geometry.coords[0][0] == 10.0 + assert gdf.iloc[0].geometry.coords[0][1] == 55.0 + + def test_df_score(): df = pd.DataFrame( {"obs": [1.0, 2.0], "not_so_good": [0.9, 2.1], "perfect": [1.0, 2.0]}