Skip to content

Commit

Permalink
Merge pull request #171 from jenshnielsen/numpy120
Browse files Browse the repository at this point in the history
fix typecheking with numpy 1.20
  • Loading branch information
jenshnielsen committed Feb 5, 2021
2 parents 91e2d49 + 913b486 commit 7e6a1be
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plottr/data/datadict.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def remove_invalid_entries(self) -> 'DataDict':
rows = self.data_vals(d)
else:
datavals = self.data_vals(d)
rows = datavals.reshape(-1, np.prod(ishp[d]))
rows = datavals.reshape(-1, int(np.prod(ishp[d])))

_idxs = np.array([])

Expand Down
8 changes: 5 additions & 3 deletions plottr/node/dim_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
nodes and widgets for reducing data dimensionality.
"""
from typing import Dict, Any, Tuple, Type, Optional, List, Union, cast
from typing import Dict, Any, Tuple, Type, Optional, List, Union, cast, Callable
from enum import Enum, unique

from typing_extensions import TypedDict
Expand Down Expand Up @@ -56,7 +56,7 @@ class ReductionMethod(Enum):


#: mapping from reduction method Enum to functions
reductionFunc = {
reductionFunc: Dict[ReductionMethod, Callable[..., Any]] = {
ReductionMethod.elementSelection: selectAxisElement,
ReductionMethod.average: np.mean,
}
Expand Down Expand Up @@ -518,10 +518,12 @@ def _applyDimReductions(self, data: DataDictBase) -> Optional[DataDictBase]:

# support for both pre-defined and custom functions
if isinstance(fun, ReductionMethod):
funCall = reductionFunc[fun]
funCall: Optional[Callable[..., Any]] = reductionFunc[fun]
else:
funCall = fun

if funCall is None:
raise RuntimeError("Reduction function is None")
newvals = funCall(data[n]['values'], *arg, **kw)
if newvals.shape != targetShape:
self.logger().error(
Expand Down
8 changes: 4 additions & 4 deletions plottr/plot/mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ def colorplot2d(ax: Axes, x: np.ndarray, y: np.ndarray, z: np.ndarray,
z = z.astype(float)

# first check if we need to fill some masked values in
if np.ma.is_masked(x):
if isinstance(x, np.ma.MaskedArray) and np.ma.is_masked(x):
x = x.filled(np.nan)
if np.ma.is_masked(y):
if isinstance(y, np.ma.MaskedArray) and np.ma.is_masked(y):
y = y.filled(np.nan)
if np.ma.is_masked(z):
if isinstance(z, np.ma.MaskedArray) and np.ma.is_masked(z):
z = z.filled(np.nan)

# next: try some surgery, if possible
Expand Down Expand Up @@ -874,7 +874,7 @@ def _analyzeData(self, data: Optional[DataDictBase]) -> Dict[str, bool]:
dataLimits = {}
for n in data.axes() + data.dependents():
vals = data.data_vals(n)
dataLimits[n] = vals.min(), vals.max()
dataLimits[n] = float(vals.min()), float(vals.max())

result = {
'dataTypeChanged': dataType != self.dataType,
Expand Down
10 changes: 5 additions & 5 deletions plottr/utils/num.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from ..utils.misc import unwrap_optional

INTTYPES = [int, np.int, np.int16, np.int32, np.int64]
FLOATTYPES = [float, np.float, np.float16, np.float32, np.float64,
complex, np.complex, np.complex64, np.complex128]
INTTYPES = [int, np.int16, np.int32, np.int64]
FLOATTYPES = [float, np.float16, np.float32, np.float64,
complex, np.complex64, np.complex128]
NUMTYPES = INTTYPES + FLOATTYPES


Expand Down Expand Up @@ -105,7 +105,7 @@ def arrays_equal(a: np.ndarray, b: np.ndarray,
equal = _are_equal(a, b)
invalid = _are_invalid(a, b)

return np.all(equal | close | invalid)
return bool(np.all(equal | close | invalid))


def array1d_to_meshgrid(arr: Union[List, np.ndarray],
Expand All @@ -132,7 +132,7 @@ def array1d_to_meshgrid(arr: Union[List, np.ndarray],
localarr = localarr.copy()
localarr = localarr.reshape(-1)

newsize = np.prod(target_shape)
newsize = int(np.prod(target_shape))
if newsize < localarr.size:
localarr = localarr[:newsize]
elif newsize > localarr.size:
Expand Down

0 comments on commit 7e6a1be

Please sign in to comment.