Skip to content

Commit 982e52e

Browse files
committed
add error messaging for unsuported time units
1 parent af3ec8c commit 982e52e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/virtualship/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from functools import lru_cache
99
from importlib.resources import files
1010
from pathlib import Path
11-
from typing import TYPE_CHECKING, TextIO
11+
from typing import TYPE_CHECKING, Literal, TextIO
1212

1313
import copernicusmarine
1414
import numpy as np
1515
import xarray as xr
16-
from parcels import FieldSet
1716

17+
from parcels import FieldSet
1818
from virtualship.errors import CopernicusCatalogueError
1919

2020
if TYPE_CHECKING:
@@ -187,7 +187,7 @@ def mfp_to_yaml(coordinates_file_path: str, yaml_output_path: str): # noqa: D41
187187

188188

189189
def _validate_numeric_to_timedelta(
190-
value: int | float | timedelta, unit: str
190+
value: int | float | timedelta, unit: Literal["minutes", "days"]
191191
) -> timedelta:
192192
"""Convert to timedelta when reading."""
193193
if isinstance(value, timedelta):
@@ -196,6 +196,10 @@ def _validate_numeric_to_timedelta(
196196
return timedelta(minutes=float(value))
197197
elif unit == "days":
198198
return timedelta(days=float(value))
199+
else:
200+
raise ValueError(
201+
f"Unsupported time unit: {unit}. Supported units are: 'minutes', 'days'."
202+
)
199203

200204

201205
def _get_expedition(expedition_dir: Path) -> Expedition:

0 commit comments

Comments
 (0)