Skip to content

Commit

Permalink
api: Stop throwing exception if you pass a timestamp without a variab…
Browse files Browse the repository at this point in the history
…le in create_trimesh()
  • Loading branch information
pmav99 committed Jun 1, 2023
1 parent be09d73 commit 8df9bdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions thalassa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8df9bdb

Please sign in to comment.