Skip to content

Commit b43c9b5

Browse files
committed
fixing mypy errors
1 parent 8c01bf0 commit b43c9b5

5 files changed

Lines changed: 12 additions & 14 deletions

File tree

parcels/_core/utils/time.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import cftime
77
import numpy as np
88

9-
T = TypeVar("T", datetime, cftime.datetime)
10-
119
if TYPE_CHECKING:
12-
from parcels._typing import DatetimeLike
10+
from parcels._typing import TimeLike
11+
12+
T = TypeVar("T", bound="TimeLike")
1313

1414

1515
class TimeInterval:
@@ -92,7 +92,7 @@ def is_compatible(
9292

9393

9494
def get_datetime_type_calendar(
95-
example_datetime: DatetimeLike,
95+
example_datetime: TimeLike,
9696
) -> tuple[type, str | None]:
9797
"""Get the type and calendar of a datetime object.
9898

parcels/_core/utils/unstructured.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
from collections.abc import Hashable
2-
31
DIM_TO_VERTICAL_LOCATION_MAP = {
42
"nz1": "center",
53
"nz": "face",
64
}
75

86

9-
def get_vertical_location_from_dims(dims: tuple[Hashable, ...]):
7+
def get_vertical_location_from_dims(dims: tuple[str, ...]):
108
"""
119
Determine the vertical location of the field based on the uxarray.UxDataArray object variables.
1210

parcels/_index_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _search_indices_curvilinear_2d(
356356

357357

358358
## TODO : Still need to implement the search_indices_curvilinear
359-
def _search_indices_curvilinear(field: Field, time, z, y, x, ti, particle=None, search2D=False):
359+
def _search_indices_curvilinear(field, time, z, y, x, ti, particle=None, search2D=False):
360360
if particle:
361361
zi, yi, xi = field.unravel_index(particle.ei)
362362
else:

parcels/_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
VectorType = Literal["3D", "3DSigma", "2D"] | None # corresponds with `vector_type`
3535
GridIndexingType = Literal["pop", "mom5", "mitgcm", "nemo", "croco"] # corresponds with `gridindexingtype`
3636
NetcdfEngine = Literal["netcdf4", "xarray", "scipy"]
37-
DatetimeLike = datetime | cftime_datetime | np.datetime64
37+
TimeLike = datetime | cftime_datetime | np.datetime64
3838

3939
KernelFunction = Callable[..., None]
4040

parcels/fieldset.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from parcels.xgrid import XGrid
1616

1717
if TYPE_CHECKING:
18-
from parcels._typing import DatetimeLike
18+
from parcels._typing import TimeLike
1919
from parcels.basegrid import BaseGrid
2020
__all__ = ["FieldSet"]
2121

@@ -57,7 +57,7 @@ def __init__(self, fields: list[Field | VectorField]):
5757
assert_compatible_calendars(fields)
5858

5959
self.fields = {f.name: f for f in fields}
60-
self.constants = {}
60+
self.constants: dict[str, float] = {}
6161

6262
def __getattr__(self, name):
6363
"""Get the field by name. If the field is not found, check if it's a constant."""
@@ -236,7 +236,7 @@ class CalendarError(Exception): # TODO: Move to a parcels errors module
236236
"""Exception raised when the calendar of a field is not compatible with the rest of the Fields. The user should ensure that they only add fields to a FieldSet that have compatible CFtime calendars."""
237237

238238

239-
def assert_compatible_calendars(fields: Iterable[Field]):
239+
def assert_compatible_calendars(fields: Iterable[Field | VectorField]):
240240
time_intervals = [f.time_interval for f in fields if f.time_interval is not None]
241241

242242
if len(time_intervals) == 0: # All time intervals are none
@@ -253,13 +253,13 @@ def assert_compatible_calendars(fields: Iterable[Field]):
253253
raise CalendarError(msg)
254254

255255

256-
def _datetime_to_msg(example_datetime: DatetimeLike) -> str:
256+
def _datetime_to_msg(example_datetime: TimeLike) -> str:
257257
datetime_type, calendar = get_datetime_type_calendar(example_datetime)
258258
msg = str(datetime_type)
259259
if calendar is not None:
260260
msg += f" with cftime calendar {calendar}'"
261261
return msg
262262

263263

264-
def _format_calendar_error_message(field: Field, reference_datetime: DatetimeLike) -> str:
264+
def _format_calendar_error_message(field: Field, reference_datetime: TimeLike) -> str:
265265
return f"Expected field {field.name!r} to have calendar compatible with datetime object {_datetime_to_msg(reference_datetime)}. Got field with calendar {_datetime_to_msg(field.time_interval.left)}. Have you considered using xarray to update the time dimension of the dataset to have a compatible calendar?"

0 commit comments

Comments
 (0)