diff --git a/tests/api_test.py b/tests/api_test.py index 6cfb945..188fea9 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -46,7 +46,7 @@ def test_main_api(): @pytest.mark.parametrize("variable", [None, "zeta"]) def test_create_trimesh(timestamp, variable): ds = api.open_dataset(ADCIRC_NC) - if timestamp == timestamp: + if timestamp == "timestamp": timestamp = ds.time[0] trimesh = api.create_trimesh(ds, variable=variable, timestamp=timestamp) diff --git a/thalassa/api.py b/thalassa/api.py index 699fb78..ba8ce2b 100644 --- a/thalassa/api.py +++ b/thalassa/api.py @@ -106,13 +106,15 @@ def create_trimesh( columns.append(variable) if layer is not None: ds = ds.isel(layer=layer) - if timestamp == "max": - points_df = ds[columns].max("time").to_dataframe() - elif timestamp == "min": - points_df = ds[columns].min("time").to_dataframe() - elif timestamp: - points_df = ds.sel({"time": timestamp})[columns].to_dataframe().drop(columns="time") + if variable and timestamp: + if timestamp == "max": + points_df = ds[columns].max("time").to_dataframe() + elif timestamp == "min": + points_df = ds[columns].min("time").to_dataframe() + else: + points_df = ds.sel({"time": timestamp})[columns].to_dataframe().drop(columns="time") else: + # Maybe throw an warning if user passed a timestamp but no variable? points_df = ds[columns].to_dataframe() points_df = points_df.reset_index(drop=True) if variable: