Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ known-first-party = ["parcels"]
include = ["./src/"]
exclude = [
"./src/parcels/interpolators/", # ignore for now
"./src/parcels/kernels/_advection.py",
]
2 changes: 1 addition & 1 deletion src/parcels/_core/basegrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions src/parcels/_core/index_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from datetime import datetime
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -44,7 +43,7 @@
"""
# TODO v4: We probably rework this to deal with 0D arrays before this point (as we already know field dimensionality)
if len(arr) < 2:
return np.zeros(shape=x.shape, dtype=np.int32), np.zeros_like(x)

Check failure on line 46 in src/parcels/_core/index_search.py

View workflow job for this annotation

GitHub Actions / TypeChecking: pixi run typing

ty (invalid-return-type)

src/parcels/_core/index_search.py:46:16: invalid-return-type: Return type does not match returned value: expected `tuple[int, int]`, found `tuple[Unknown, ndarray[tuple[Any, ...], dtype[Any]]]` src/parcels/_core/index_search.py:23:6: Expected `tuple[int, int]` because of return type info: rule `invalid-return-type` is enabled by default
index = np.clip(np.searchsorted(arr, x, side="right") - 1, 0, len(arr) - 2)
# Use broadcasting to avoid repeated array access
arr_index = arr[index]
Expand All @@ -63,7 +62,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion src/parcels/_core/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/parcels/_core/xgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
for dim in dims:
axis = get_axis_from_dim_name(self.xgcm_grid.axes, dim)
if axis in self.axes: # Only include spatial axes (X, Y, Z)
result[cast(ptyping.XgridAxis, axis)] = dim

Check warning on line 379 in src/parcels/_core/xgrid.py

View workflow job for this annotation

GitHub Actions / TypeChecking: pixi run typing

ty (redundant-cast)

src/parcels/_core/xgrid.py:379:24: redundant-cast: Value is already of type `Literal["X", "Y", "Z"]` info: rule `redundant-cast` is enabled by default
return result


Expand All @@ -394,7 +394,7 @@
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


Expand Down
2 changes: 1 addition & 1 deletion src/parcels/_datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
3 changes: 2 additions & 1 deletion src/parcels/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from __future__ import annotations

import typing
from typing import cast

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -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:
Expand Down
Loading