Skip to content

Commit

Permalink
Fix type checking errors
Browse files Browse the repository at this point in the history
A handful have been ignored where they appear to be from matplotlib not
being typed. The rest were by relaxing requirements for np.float64
instead of np.floating[Any].
  • Loading branch information
tpoliaw committed Jan 24, 2025
1 parent 8775f04 commit dc7e8ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/scanspec/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def __init__(
self._verts3d = xs, ys, zs

# Added here because of https://github.com/matplotlib/matplotlib/issues/21688
def do_3d_projection(self, renderer: Any = None):
def do_3d_projection(self, renderer: Any = None): # type: ignore
xs3d, ys3d, zs3d = self._verts3d
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M) # type: ignore
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) # type: ignore

Check warning on line 50 in src/scanspec/plot.py

View check run for this annotation

Codecov / codecov/patch

src/scanspec/plot.py#L50

Added line #L50 was not covered by tests

return np.min(zs)
return np.min(zs) # type: ignore

Check warning on line 52 in src/scanspec/plot.py

View check run for this annotation

Codecov / codecov/patch

src/scanspec/plot.py#L52

Added line #L52 was not covered by tests

@property
def verts3d(
Expand Down
2 changes: 1 addition & 1 deletion src/scanspec/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _sub_sample(frames: Frames[str], ratio: float) -> Frames[str]:
return frames.extract(indexes, calculate_gap=False)


def _calc_smallest_step(points: list[npt.NDArray[np.float64]]) -> float:
def _calc_smallest_step(points: list[npt.NDArray[np.number[Any]]]) -> float:
# Calc abs diffs of all axes, ignoring any zero values
absolute_diffs = [_abs_diffs(axis_midpoints) for axis_midpoints in points]
# Normalize and remove zeros
Expand Down
16 changes: 9 additions & 7 deletions src/scanspec/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ def calculate( # noqa: D102


def _dimensions_from_indexes(
func: Callable[[npt.NDArray[np.float64]], dict[Axis, npt.NDArray[np.float64]]],
func: Callable[
[npt.NDArray[np.floating[Any]]], dict[Axis, npt.NDArray[np.floating[Any]]]
],
axes: list[Axis],
num: int,
bounds: bool,
Expand Down Expand Up @@ -496,8 +498,8 @@ def axes(self) -> list[Axis]: # noqa: D102
return [self.axis]

def _line_from_indexes(
self, indexes: npt.NDArray[np.float64]
) -> dict[Axis, npt.NDArray[np.float64]]:
self, indexes: npt.NDArray[np.floating[Any]]
) -> dict[Axis, npt.NDArray[np.floating[Any]]]:
if self.num == 1:
# Only one point, stop-start gives length of one point
step = self.stop - self.start
Expand Down Expand Up @@ -586,8 +588,8 @@ def axes(self) -> list[Axis]: # noqa: D102
return [self.axis]

def _repeats_from_indexes(
self, indexes: npt.NDArray[np.float64]
) -> dict[Axis, npt.NDArray[np.float64]]:
self, indexes: npt.NDArray[np.floating[Any]]
) -> dict[Axis, npt.NDArray[np.floating[Any]]]:
return {self.axis: np.full(len(indexes), self.value)}

def calculate( # noqa: D102
Expand Down Expand Up @@ -633,8 +635,8 @@ def axes(self) -> list[Axis]: # noqa: D102
return [self.y_axis, self.x_axis]

def _spiral_from_indexes(
self, indexes: npt.NDArray[np.float64]
) -> dict[Axis, npt.NDArray[np.float64]]:
self, indexes: npt.NDArray[np.floating[Any]]
) -> dict[Axis, npt.NDArray[np.floating[Any]]]:
# simplest spiral equation: r = phi
# we want point spacing across area to be the same as between rings
# so: sqrt(area / num) = ring_spacing
Expand Down

0 comments on commit dc7e8ec

Please sign in to comment.