Skip to content

Commit

Permalink
Fix numpy bool deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgleith authored and Kirill888 committed Aug 17, 2021
1 parent 63a1244 commit 1650ce1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions datacube/utils/masking.py
Expand Up @@ -11,7 +11,6 @@
import collections

import pandas
import numpy
import xarray
from xarray import DataArray, Dataset

Expand Down Expand Up @@ -124,7 +123,7 @@ def valid_data_mask(data):

return xarray.apply_ufunc(valid_mask, data, nodata,
dask='parallelized',
output_dtypes=[numpy.bool])
output_dtypes=[bool])


def mask_invalid_data(data, keep_attrs=True):
Expand Down
8 changes: 4 additions & 4 deletions datacube/utils/math.py
Expand Up @@ -110,11 +110,11 @@ def snap_scale(s, tol=1e-6):
return s

# Check for simple fractions
s_inv = 1/s
s_inv = 1 / s
s_inv_snapped = maybe_int(s_inv, tol)
if s_inv_snapped is s_inv:
return s
return 1/s_inv_snapped
return 1 / s_inv_snapped


def clamp(x, lo, up):
Expand Down Expand Up @@ -152,7 +152,7 @@ def valid_mask(xx, nodata):
return ~numpy.isnan(xx) & (xx != nodata)

if nodata is None:
return numpy.full_like(xx, True, dtype=numpy.bool)
return numpy.full_like(xx, True, dtype=bool)
return xx != nodata


Expand All @@ -166,7 +166,7 @@ def invalid_mask(xx, nodata):
return numpy.isnan(xx) | (xx == nodata)

if nodata is None:
return numpy.full_like(xx, False, dtype=numpy.bool)
return numpy.full_like(xx, False, dtype=bool)
return xx == nodata


Expand Down
6 changes: 3 additions & 3 deletions datacube/virtual/transformations.py
Expand Up @@ -126,7 +126,7 @@ def compute(self, data):
mask = ~xarray.apply_ufunc(binary_erosion,
~mask,
kernel.reshape((1, ) + kernel.shape),
output_dtypes=[numpy.bool],
output_dtypes=[bool],
dask='parallelized',
keep_attrs=True)

Expand All @@ -136,7 +136,7 @@ def compute(self, data):
mask = ~xarray.apply_ufunc(binary_dilation,
~mask,
kernel.reshape((1, ) + kernel.shape),
output_dtypes=[numpy.bool],
output_dtypes=[bool],
dask='parallelized',
keep_attrs=True)

Expand Down Expand Up @@ -330,7 +330,7 @@ def result(output_var, output_desc):
dtype = result.dtype
mask = evaluate_nodata_mask(formula, data, parser, MaskEvaluator)

if numpy.dtype(dtype) == numpy.bool:
if numpy.dtype(dtype) == bool:
# any operation on nodata should evaluate to False
# omission of attrs['nodata'] is deliberate
result = result.where(~mask, False)
Expand Down

0 comments on commit 1650ce1

Please sign in to comment.