From b3f875746d20eec0e158e35e6d2f615bf394ea59 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 23 Nov 2020 11:59:18 +0100 Subject: [PATCH 1/4] use numpy stups with mypy --- test_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test_requirements.txt b/test_requirements.txt index ce7657ec..138113c3 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -3,3 +3,4 @@ pytest pytest-qt mypy PyQt5-stubs +git+https://github.com/numpy/numpy-stubs.git \ No newline at end of file From d45e0ce337b5da33301615726c7a3abfbac8e370 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 23 Nov 2020 12:08:13 +0100 Subject: [PATCH 2/4] fix type check --- plottr/data/datadict_storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plottr/data/datadict_storage.py b/plottr/data/datadict_storage.py index 9f5ae32c..98a1eacc 100644 --- a/plottr/data/datadict_storage.py +++ b/plottr/data/datadict_storage.py @@ -17,7 +17,7 @@ import os import time from enum import Enum -from typing import Any, Union, Optional, Dict, Type +from typing import Any, Union, Optional, Dict, Type, Collection from types import TracebackType import numpy as np @@ -334,7 +334,7 @@ def datadict_from_hdf5(basepath: str, for k in keys: ds = grp[k] - entry = dict(values=np.array([]), ) + entry: Dict[str, Union[Collection[Any], np.ndarray]] = dict(values=np.array([]), ) if 'axes' in ds.attrs: entry['axes'] = deh5ify(ds.attrs['axes']).tolist() From 670ed0bca339ccb412bf8af604656c22cfda7822 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 23 Nov 2020 12:56:03 +0100 Subject: [PATCH 3/4] fix typechecking issues with numpy on linux --- plottr/utils/num.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plottr/utils/num.py b/plottr/utils/num.py index bfda0f00..52f9ebda 100644 --- a/plottr/utils/num.py +++ b/plottr/utils/num.py @@ -46,7 +46,7 @@ def largest_numtype(arr: np.ndarray, include_integers: bool = True) \ return None -def _are_close(a: np.ndarray, b: np.ndarray, rtol: float = 1e-8) -> np.ndarray: +def _are_close(a: np.ndarray, b: np.ndarray, rtol: float = 1e-8) -> Union[np.ndarray, bool]: return np.isclose(a, b, rtol=rtol) @@ -98,7 +98,7 @@ def arrays_equal(a: np.ndarray, b: np.ndarray, else: return False - close = np.zeros(a.shape, dtype=bool) + close: Union[np.ndarray, bool] = np.zeros(a.shape, dtype=bool) if a.dtype in FLOATTYPES and b.dtype in FLOATTYPES: close = _are_close(a, b, rtol=rtol) @@ -178,7 +178,7 @@ def _find_switches(arr: np.ndarray, def find_direction_period(vals: np.ndarray, ignore_last: bool = False) \ - -> Union[None, int]: + -> Optional[float]: """ Find the period with which the values in an array change direction. @@ -234,7 +234,7 @@ def guess_grid_from_sweep_direction(**axes: np.ndarray) \ :raises: `ValueError` for incorrect input """ periods_list = [] - sorting = [] + sorting: List[float] = [] names_list = [] size: Optional[int] = None From 9c3e0949fc5d252fcd8d0322981f164cb4b80d5a Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 23 Nov 2020 13:05:17 +0100 Subject: [PATCH 4/4] use numpy bool --- plottr/utils/num.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plottr/utils/num.py b/plottr/utils/num.py index 52f9ebda..86f0b8a0 100644 --- a/plottr/utils/num.py +++ b/plottr/utils/num.py @@ -46,7 +46,7 @@ def largest_numtype(arr: np.ndarray, include_integers: bool = True) \ return None -def _are_close(a: np.ndarray, b: np.ndarray, rtol: float = 1e-8) -> Union[np.ndarray, bool]: +def _are_close(a: np.ndarray, b: np.ndarray, rtol: float = 1e-8) -> Union[np.ndarray, np.bool_]: return np.isclose(a, b, rtol=rtol) @@ -98,7 +98,7 @@ def arrays_equal(a: np.ndarray, b: np.ndarray, else: return False - close: Union[np.ndarray, bool] = np.zeros(a.shape, dtype=bool) + close: Union[np.ndarray, np.bool_] = np.zeros(a.shape, dtype=bool) if a.dtype in FLOATTYPES and b.dtype in FLOATTYPES: close = _are_close(a, b, rtol=rtol)