Skip to content

Add numpy and matplotlib to typing checks #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2023
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ repos:
rev: v1.2.0
hooks:
- id: mypy
additional_dependencies: [numpy, matplotlib]

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
Expand Down
10 changes: 5 additions & 5 deletions src/napari_matplotlib/scatter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List, Optional, Tuple
from typing import Any, List, Optional, Tuple

import matplotlib.colors as mcolor
import napari
import numpy as np
import numpy.typing as npt
from magicgui import magicgui
from magicgui.widgets import ComboBox

Expand Down Expand Up @@ -65,7 +65,7 @@ def draw(self) -> None:
self.axes.set_xlabel(x_axis_name)
self.axes.set_ylabel(y_axis_name)

def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
def _get_data(self) -> Tuple[List[npt.NDArray[Any]], str, str]:
"""Get the plot data.

This must be implemented on the subclass.
Expand Down Expand Up @@ -93,7 +93,7 @@ class ScatterWidget(ScatterBaseWidget):
n_layers_input = Interval(2, 2)
input_layer_types = (napari.layers.Image,)

def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
def _get_data(self) -> Tuple[List[npt.NDArray[Any]], str, str]:
"""
Get the plot data.

Expand Down Expand Up @@ -191,7 +191,7 @@ def _get_valid_axis_keys(
else:
return self.layers[0].features.keys()

def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
def _get_data(self) -> Tuple[List[npt.NDArray[Any]], str, str]:
"""
Get the plot data.

Expand Down
5 changes: 3 additions & 2 deletions src/napari_matplotlib/slice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Dict, Tuple
from typing import Any, Dict, Tuple

import napari
import numpy as np
import numpy.typing as npt
from qtpy.QtWidgets import QComboBox, QHBoxLayout, QLabel, QSpinBox

from .base import NapariMPLWidget
Expand Down Expand Up @@ -87,7 +88,7 @@ def update_slice_selectors(self) -> None:
for i, dim in enumerate(_dims_sel):
self.slice_selectors[dim].setRange(0, self.layer.data.shape[i])

def get_xy(self) -> Tuple[np.ndarray, np.ndarray]:
def get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]:
"""
Get data for plotting.
"""
Expand Down
3 changes: 2 additions & 1 deletion src/napari_matplotlib/tests/test_scatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Tuple

import numpy as np
import numpy.typing as npt

from napari_matplotlib import FeaturesScatterWidget, ScatterWidget

Expand All @@ -22,7 +23,7 @@ def test_features_scatter_widget(make_napari_viewer):


def make_labels_layer_with_features() -> (
Tuple[np.ndarray, Dict[str, Tuple[Any]]]
Tuple[npt.NDArray[np.uint16], Dict[str, Any]]
):
label_image = np.zeros((100, 100), dtype=np.uint16)
for label_value, start_index in enumerate([10, 30, 50], start=1):
Expand Down