Skip to content

Commit 1484818

Browse files
Fix typechecking errors (#2554)
* typing * ignore * typing * typing
1 parent c6f11dc commit 1484818

7 files changed

Lines changed: 8 additions & 7 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,5 @@ known-first-party = ["parcels"]
161161
include = ["./src/"]
162162
exclude = [
163163
"./src/parcels/interpolators/", # ignore for now
164+
"./src/parcels/kernels/_advection.py",
164165
]

src/parcels/_core/basegrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def ravel_index(self, axis_indices: dict[str, np.ndarray]) -> np.ndarray:
113113
indices = np.array([axis_indices[axis] for axis in self.axes], dtype=int)
114114
return _ravel(dims, indices)
115115

116-
def unravel_index(self, ei: int) -> dict[str, int]:
116+
def unravel_index(self, ei: int) -> dict[str, np.ndarray]:
117117
"""
118118
Convert a single encoded index (ei) back to a dictionary of axis indices.
119119

src/parcels/_core/index_search.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from datetime import datetime
43
from typing import TYPE_CHECKING
54

65
import numpy as np
@@ -63,7 +62,7 @@ def _search_1d_array(
6362
return np.atleast_1d(index), np.atleast_1d(bcoord)
6463

6564

66-
def _search_time_index(field: Field, time: datetime):
65+
def _search_time_index(field: Field, time: np.ndarray):
6766
"""Find and return the index and relative coordinate in the time array associated with a given time.
6867
6968
Parameters

src/parcels/_core/utils/time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def time_length_as_flt(self):
5858
def __contains__(self, item: T) -> bool:
5959
return self.left <= item <= self.right
6060

61-
def is_all_time_in_interval(self, time: float):
61+
def is_all_time_in_interval(self, time: float | np.ndarray):
6262
item = np.atleast_1d(time)
6363
return (0 <= item).all() and (item <= self.time_length_as_flt).all()
6464

src/parcels/_core/xgrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def get_xgcm_position_from_dim_name(axes: ptyping.XgcmAxes, dim: str) -> ptyping
394394
var_to_position = {var: position for position, var in axis.coords.items()}
395395

396396
if dim in var_to_position:
397-
return var_to_position[dim]
397+
return var_to_position[dim] # type: ignore[invalid-return-type] # due to mistyping in xgcm
398398
return None
399399

400400

src/parcels/_datasets/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def from_xarray_dataset_dict(d) -> xr.Dataset:
206206
def _fill_with_dummy_data(d: dict[str, dict]):
207207
assert isinstance(d, dict)
208208
if "dtype" in d:
209-
d["data"] = np.zeros(d["shape"], dtype=d["dtype"])
209+
d["data"] = np.zeros(d["shape"], dtype=d["dtype"]) # type:ignore[no-matching-overload] # loading from unsanitized data
210210
del d["dtype"]
211211
del d["shape"]
212212

src/parcels/convert.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from __future__ import annotations
1414

1515
import typing
16+
from typing import cast
1617

1718
import numpy as np
1819
import xarray as xr
@@ -565,7 +566,7 @@ def _detect_vertical_coordinates(
565566
ValueError
566567
If vertical coordinates cannot be detected.
567568
"""
568-
ds_dims = set(ds.dims)
569+
ds_dims = cast(set[str], set(ds.dims))
569570

570571
# Strategy 1: Use known mappings if provided and dimensions exist
571572
if known_mappings is not None:

0 commit comments

Comments
 (0)