From 8e277d95463e9ba18f00ea7ee28f649598011e7e Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:22:03 +0100 Subject: [PATCH 1/4] typing --- src/parcels/_core/xgrid.py | 2 +- src/parcels/convert.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/parcels/_core/xgrid.py b/src/parcels/_core/xgrid.py index 90cca8ea1..efa69dce9 100644 --- a/src/parcels/_core/xgrid.py +++ b/src/parcels/_core/xgrid.py @@ -394,7 +394,7 @@ def get_xgcm_position_from_dim_name(axes: ptyping.XgcmAxes, dim: str) -> ptyping var_to_position = {var: position for position, var in axis.coords.items()} if dim in var_to_position: - return var_to_position[dim] + return var_to_position[dim] # type: ignore[invalid-return-type] # due to mistyping in xgcm return None diff --git a/src/parcels/convert.py b/src/parcels/convert.py index e8f2b84b9..44ccb6200 100644 --- a/src/parcels/convert.py +++ b/src/parcels/convert.py @@ -13,6 +13,7 @@ from __future__ import annotations import typing +from typing import cast import numpy as np import xarray as xr @@ -565,7 +566,7 @@ def _detect_vertical_coordinates( ValueError If vertical coordinates cannot be detected. """ - ds_dims = set(ds.dims) + ds_dims = cast(set[str], set(ds.dims)) # Strategy 1: Use known mappings if provided and dimensions exist if known_mappings is not None: From 18178e553ef1b4ae9781f836067a7ca86a8a4979 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:25:31 +0100 Subject: [PATCH 2/4] ignore --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index f3ca30d4c..e4eab68dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -161,4 +161,5 @@ known-first-party = ["parcels"] include = ["./src/"] exclude = [ "./src/parcels/interpolators/", # ignore for now + "./src/parcels/kernels/_advection.py", ] From 572224f06373f78f0f9edbd33b34c7f00c66bc32 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:31:52 +0100 Subject: [PATCH 3/4] typing --- src/parcels/_core/basegrid.py | 2 +- src/parcels/_core/index_search.py | 3 +-- src/parcels/_core/utils/time.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/parcels/_core/basegrid.py b/src/parcels/_core/basegrid.py index 05649436d..1a867eadd 100644 --- a/src/parcels/_core/basegrid.py +++ b/src/parcels/_core/basegrid.py @@ -113,7 +113,7 @@ def ravel_index(self, axis_indices: dict[str, np.ndarray]) -> np.ndarray: indices = np.array([axis_indices[axis] for axis in self.axes], dtype=int) return _ravel(dims, indices) - def unravel_index(self, ei: int) -> dict[str, int]: + def unravel_index(self, ei: int) -> dict[str, np.ndarray]: """ Convert a single encoded index (ei) back to a dictionary of axis indices. diff --git a/src/parcels/_core/index_search.py b/src/parcels/_core/index_search.py index 5946e949e..5e2c223d0 100644 --- a/src/parcels/_core/index_search.py +++ b/src/parcels/_core/index_search.py @@ -1,6 +1,5 @@ from __future__ import annotations -from datetime import datetime from typing import TYPE_CHECKING import numpy as np @@ -63,7 +62,7 @@ def _search_1d_array( return np.atleast_1d(index), np.atleast_1d(bcoord) -def _search_time_index(field: Field, time: datetime): +def _search_time_index(field: Field, time: np.ndarray): """Find and return the index and relative coordinate in the time array associated with a given time. Parameters diff --git a/src/parcels/_core/utils/time.py b/src/parcels/_core/utils/time.py index 76a7a54cc..b76473a3f 100644 --- a/src/parcels/_core/utils/time.py +++ b/src/parcels/_core/utils/time.py @@ -58,7 +58,7 @@ def time_length_as_flt(self): def __contains__(self, item: T) -> bool: return self.left <= item <= self.right - def is_all_time_in_interval(self, time: float): + def is_all_time_in_interval(self, time: float | np.ndarray): item = np.atleast_1d(time) return (0 <= item).all() and (item <= self.time_length_as_flt).all() From 4e3b0121d158adc849dd74849cc0ba2ca0624d83 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:34:50 +0100 Subject: [PATCH 4/4] typing --- src/parcels/_datasets/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parcels/_datasets/utils.py b/src/parcels/_datasets/utils.py index 15afeca46..f8af6b7e0 100644 --- a/src/parcels/_datasets/utils.py +++ b/src/parcels/_datasets/utils.py @@ -206,7 +206,7 @@ def from_xarray_dataset_dict(d) -> xr.Dataset: def _fill_with_dummy_data(d: dict[str, dict]): assert isinstance(d, dict) if "dtype" in d: - d["data"] = np.zeros(d["shape"], dtype=d["dtype"]) + d["data"] = np.zeros(d["shape"], dtype=d["dtype"]) # type:ignore[no-matching-overload] # loading from unsanitized data del d["dtype"] del d["shape"]