From ac574547633db77836d3a982c83e1b5cf901730d Mon Sep 17 00:00:00 2001 From: jan Date: Sat, 13 Feb 2021 16:48:53 -0800 Subject: [PATCH] type fixes and ignores --- adze/boundary.py | 10 +++++----- adze/moments.py | 2 +- adze/shapes.py | 4 ++-- adze/test/test_benchmarks.py | 4 ++-- adze/test/test_split.py | 6 +++--- adze/test/test_voxel.py | 10 +++++----- adze/test/utils.py | 4 ++-- adze/transform.py | 5 +++-- adze/util.py | 6 +++--- adze/voxel.py | 2 +- 10 files changed, 27 insertions(+), 26 deletions(-) diff --git a/adze/boundary.py b/adze/boundary.py index 4199868..427f984 100644 --- a/adze/boundary.py +++ b/adze/boundary.py @@ -1,6 +1,6 @@ -from typing import List, Dict -import numpy -from numpy.linalg import norm +from typing import List, Dict, Any +import numpy # type: ignore +from numpy.linalg import norm # type: ignore from . import poly_t, plane_t from .util import _get_maps, find_components, find_faces @@ -255,7 +255,7 @@ def build_polyhedron(vertices: numpy.ndarray, faces: numpy.ndarray) -> poly_t: return {'vertices': final_vertices, 'neighbors': neighbors} -def boundary_from_poly(poly: poly_t) -> Dict: +def boundary_from_poly(poly: poly_t) -> List[Dict[str, Any]]: ''' Generate a boundary represeentation corresponding to the provided 3-vertex-connected Schlegel diagram. @@ -275,7 +275,7 @@ def boundary_from_poly(poly: poly_t) -> Dict: faces = find_faces(neighbors) num_components = owning_component.max() + 1 - components = [[] for _ in range(num_components)] + components: List[List[numpy.ndarray]] = [[] for _ in range(num_components)] for face in faces: component_ind = owning_component[face[0]] components[component_ind].append(face) diff --git a/adze/moments.py b/adze/moments.py index 93b79d3..2c2aafd 100644 --- a/adze/moments.py +++ b/adze/moments.py @@ -1,5 +1,5 @@ from typing import Dict, Tuple -import numpy +import numpy # type: ignore from . import poly_t, plane_t from .util import find_faces diff --git a/adze/shapes.py b/adze/shapes.py index 20f422e..c9215c7 100644 --- a/adze/shapes.py +++ b/adze/shapes.py @@ -1,6 +1,6 @@ from typing import List -import numpy -from numpy.linalg import norm +import numpy # type: ignore +from numpy.linalg import norm # type: ignore from . import poly_t, plane_t diff --git a/adze/test/test_benchmarks.py b/adze/test/test_benchmarks.py index f899353..dfeca5d 100644 --- a/adze/test/test_benchmarks.py +++ b/adze/test/test_benchmarks.py @@ -8,9 +8,9 @@ from time import perf_counter import random import logging -import numpy +import numpy # type: ignore from numpy import sin, cos, pi -from numpy.linalg import norm +from numpy.linalg import norm # type: ignore import adze import adze.util diff --git a/adze/test/test_split.py b/adze/test/test_split.py index 3e8b197..0671fe0 100644 --- a/adze/test/test_split.py +++ b/adze/test/test_split.py @@ -1,9 +1,9 @@ import logging import pytest from pytest import approx -import numpy -from numpy.linalg import norm -from numpy.testing import assert_allclose, assert_array_equal +import numpy # type: ignore +from numpy.linalg import norm # type: ignore +from numpy.testing import assert_allclose, assert_array_equal # type: ignore import adze import adze.util diff --git a/adze/test/test_voxel.py b/adze/test/test_voxel.py index c537e59..4dabdeb 100644 --- a/adze/test/test_voxel.py +++ b/adze/test/test_voxel.py @@ -1,9 +1,9 @@ import logging import pytest from pytest import approx -import numpy -from numpy.linalg import norm -from numpy.testing import assert_allclose, assert_array_equal +import numpy # type: ignore +from numpy.linalg import norm # type: ignore +from numpy.testing import assert_allclose, assert_array_equal # type: ignore from time import perf_counter import adze @@ -55,8 +55,8 @@ def visualize_isosurface(grid, show_edges: Whether to draw triangle edges. Default True finalize: Whether to call pyplot.show() after constructing the plot. Default True """ - from matplotlib import pyplot - import skimage.measure + from matplotlib import pyplot # type: ignore + import skimage.measure # type: ignore # Claims to be unused, but needed for subplot(projection='3d') from mpl_toolkits.mplot3d import Axes3D diff --git a/adze/test/utils.py b/adze/test/utils.py index f99c9f0..0613fa2 100644 --- a/adze/test/utils.py +++ b/adze/test/utils.py @@ -1,6 +1,6 @@ -import numpy +import numpy # type: ignore from numpy import pi, cos, sin -from numpy.linalg import norm +from numpy.linalg import norm # type: ignore import random import adze diff --git a/adze/transform.py b/adze/transform.py index 56e6faa..df83cd5 100644 --- a/adze/transform.py +++ b/adze/transform.py @@ -1,4 +1,5 @@ -import numpy +from typing import Union +import numpy # type: ignore from numpy import sin, cos from . import poly_t, plane_t @@ -41,7 +42,7 @@ def translate(poly: poly_t, shift: numpy.ndarray) -> poly_t: return poly -def scale(poly: poly_t, factor: numpy.ndarray or float) -> poly_t: +def scale(poly: poly_t, factor: Union[numpy.ndarray, float]) -> poly_t: ''' Scale the polyhedron. Can scale by a single value, or scale each axis individually diff --git a/adze/util.py b/adze/util.py index 4942379..6a2c6df 100644 --- a/adze/util.py +++ b/adze/util.py @@ -1,5 +1,5 @@ from typing import Dict, Tuple, List -import numpy +import numpy # type: ignore plane_t = Tuple[numpy.ndarray, float] @@ -92,11 +92,11 @@ def find_faces(neighbors: numpy.ndarray) -> List[numpy.ndarray]: # Alternative approach, less memory-intensive but slower faces = [[v] for v in v_current] - def add_edges(edge_id, v_nxt, _k): + def add_edges(edge_id, v_nxt, k): for i, vn in zip(edge_id, v_nxt): faces[i].append(vn) - def cleaned_faces(remove, _k): + def cleaned_faces(remove, k): faces_set = [] for i in numpy.where(~remove)[0]: faces_set.append(faces[i]) diff --git a/adze/voxel.py b/adze/voxel.py index 78e7096..6b35808 100644 --- a/adze/voxel.py +++ b/adze/voxel.py @@ -1,5 +1,5 @@ from typing import Tuple, List -import numpy +import numpy # type: ignore from . import poly_t, plane_t from .split import split, clip