File tree Expand file tree Collapse file tree
src/modelskill/comparison Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -341,10 +341,12 @@ def _matched_data_to_xarray(
341341 f"Model data: { m } is of type { df [m ].dtype } , it must be numeric"
342342 )
343343
344- df = df [items .all ]
345- df .index .name = "time"
346- df = df .rename (columns = {items .obs : "Observation" })
347- ds = df .to_xarray ()
344+ ds = (
345+ df .loc [:, items .all ]
346+ .rename_axis ("time" )
347+ .rename (columns = {items .obs : "Observation" })
348+ .to_xarray ()
349+ )
348350 assert isinstance (ds , xr .Dataset )
349351
350352 ds .attrs ["name" ] = name if name is not None else items .obs
Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ def tc() -> Comparer:
9494
9595
9696def test_matched_df (pt_df ):
97+ # modelskill doesn't care about the name of the index, but it should be preserved
98+ pt_df .index .name = "dato_tid"
9799 cmp = Comparer .from_matched_data (data = pt_df )
98100 assert cmp .gtype == "point"
99101 assert "m2" in cmp .mod_names
@@ -104,6 +106,14 @@ def test_matched_df(pt_df):
104106 assert cmp .score ()["m1" ] == pytest .approx (0.5916079783099617 )
105107 assert cmp .score ()["m2" ] == pytest .approx (0.15811388300841905 )
106108
109+ # from_matched doesn't modify the original dataframe,. including the name of the index
110+ assert pt_df .index .name == "dato_tid"
111+ assert list (pt_df .columns ) == ["Observation" , "m1" , "m2" ]
112+
113+ # but to_dataframe always returns a dataframe with index named "time"
114+ df2 = cmp .to_dataframe ()
115+ assert df2 .index .name == "time"
116+
107117
108118def test_matched_skill_geodataframe (pt_df ):
109119 cmp = Comparer .from_matched_data (data = pt_df , x = 10.0 , y = 55.0 )
You can’t perform that action at this time.
0 commit comments