Skip to content

Commit

Permalink
Merge pull request #289 from neutrinoceros/typ/fix_dtype_type_hint
Browse files Browse the repository at this point in the history
TYP: fix type annotations for _CoordinateValidatorMixin._get_safe_datatype for compatibility with numpy 2.2
  • Loading branch information
neutrinoceros authored Dec 10, 2024
2 parents 87eadec + d9c9c2a commit 0ff3c7b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/gpgi/_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
if TYPE_CHECKING:
from typing import Any, Self

from numpy.typing import NDArray

from gpgi._typing import FieldMap, HCIArray, Name, RealArray


BoundarySpec = tuple[tuple[str, str, str], ...]


Expand Down Expand Up @@ -227,15 +230,15 @@ def _validate_coordinates(self) -> None:

self.coordinates[axis] = coord.astype(coord_dtype, copy=False)

def _get_safe_datatype(self, reference: np.ndarray | None = None) -> np.dtype:
def _get_safe_datatype(
self, reference: NDArray[np.floating] | None = None
) -> np.dtype[np.floating]:
if reference is None:
reference = self.coordinates[self.axes[0]]
dt = reference.dtype
if dt.kind != "f":
raise ValueError(f"Invalid data type {dt} (expected a float dtype)")
# return type should already be correct but
# this has the benefit of convincing mypy
return np.dtype(dt)
return dt


class Grid(_CoordinateValidatorMixin):
Expand Down

0 comments on commit 0ff3c7b

Please sign in to comment.