Skip to content

Commit

Permalink
Resolve #1846
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Gillies committed Jan 8, 2020
1 parent 0027034 commit 07d47ef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
@@ -1,6 +1,14 @@
Changes
=======

1.1.3 (TBD)
-----------

Bug fixes:

- dataset_mask returned in some cases an array with dtype "int64" (#1846). This
bug was introduced in 1.1.2 and has been fixed.

1.1.2 (2019-12-18)
------------------

Expand Down
2 changes: 1 addition & 1 deletion rasterio/__init__.py
Expand Up @@ -42,7 +42,7 @@ def emit(self, record):


__all__ = ['band', 'open', 'pad', 'Env']
__version__ = "1.1.2"
__version__ = "1.1.3dev"
__gdal_version__ = gdal_version()

# Rasterio attaches NullHandler to the 'rasterio' logger and its
Expand Down
5 changes: 3 additions & 2 deletions rasterio/_io.pyx
Expand Up @@ -797,13 +797,14 @@ cdef class DatasetReaderBase(DatasetBase):
elif out is not None:
kwargs.pop("out", None)
kwargs["out_shape"] = (self.count, out.shape[-2], out.shape[-1])
out = 255 * np.logical_or.reduce(self.read_masks(**kwargs))
out = np.logical_or.reduce(self.read_masks(**kwargs)).astype("uint8")
out *= 255
return out

elif out_shape is not None:
kwargs["out_shape"] = (self.count, out_shape[-2], out_shape[-1])

return 255 * np.logical_or.reduce(self.read_masks(**kwargs))
return 255 * np.logical_or.reduce(self.read_masks(**kwargs)).astype("uint8")


def sample(self, xy, indexes=None, masked=False):
Expand Down
9 changes: 2 additions & 7 deletions tests/test_dataset_mask.py
Expand Up @@ -160,6 +160,8 @@ def test_no_ndv(tiffs):

def test_rgb_ndv(tiffs):
with rasterio.open(str(tiffs.join('rgb_ndv.tif'))) as src:
res = src.dataset_mask()
assert res.dtype.name == "uint8"
assert np.array_equal(src.dataset_mask(), alp)

def test_rgba_no_ndv(tiffs):
Expand Down Expand Up @@ -194,13 +196,6 @@ def test_kwargs(tiffs, kwds, expected):
with rasterio.open(str(tiffs.join('rgb_ndv.tif'))) as src:
result = src.dataset_mask(**kwds)
assert np.array_equal(expected, result)
#
# other = src.dataset_mask(out_shape=(1, 5, 5))
# assert np.array_equal(resampmask, other)
#
# out = np.zeros((1, 5, 5), dtype=np.uint8)
# other = src.dataset_mask(out=out)
# assert np.array_equal(resampmask, other)


def test_indexes_not_supported(tiffs):
Expand Down

0 comments on commit 07d47ef

Please sign in to comment.