Allow unsafe casting again

Resolves #2179
This commit is contained in:
Sean Gillies 2021-05-20 15:11:20 -06:00
parent df446d4cc8
commit 60d4ed4114
2 changed files with 11 additions and 4 deletions

View File

@ -21,13 +21,13 @@ def copy_first(merged_data, new_data, merged_mask, new_mask, **kwargs):
mask = np.empty_like(merged_mask, dtype="bool")
np.logical_not(new_mask, out=mask)
np.logical_and(merged_mask, mask, out=mask)
np.copyto(merged_data, new_data, where=mask)
np.copyto(merged_data, new_data, where=mask, casting="unsafe")
def copy_last(merged_data, new_data, merged_mask, new_mask, **kwargs):
mask = np.empty_like(merged_mask, dtype="bool")
np.logical_not(new_mask, out=mask)
np.copyto(merged_data, new_data, where=mask)
np.copyto(merged_data, new_data, where=mask, casting="unsafe")
def copy_min(merged_data, new_data, merged_mask, new_mask, **kwargs):
@ -37,7 +37,7 @@ def copy_min(merged_data, new_data, merged_mask, new_mask, **kwargs):
np.minimum(merged_data, new_data, out=merged_data, where=mask)
np.logical_not(new_mask, out=mask)
np.logical_and(merged_mask, mask, out=mask)
np.copyto(merged_data, new_data, where=mask)
np.copyto(merged_data, new_data, where=mask, casting="unsafe")
def copy_max(merged_data, new_data, merged_mask, new_mask, **kwargs):
@ -47,7 +47,7 @@ def copy_max(merged_data, new_data, merged_mask, new_mask, **kwargs):
np.maximum(merged_data, new_data, out=merged_data, where=mask)
np.logical_not(new_mask, out=mask)
np.logical_and(merged_mask, mask, out=mask)
np.copyto(merged_data, new_data, where=mask)
np.copyto(merged_data, new_data, where=mask, casting="unsafe")
MERGE_METHODS = {

View File

@ -59,3 +59,10 @@ def test_issue2163():
data = src.read()
result, transform = merge([src])
assert numpy.allclose(data, result)
def test_unsafe_casting():
"""Demonstrate fix for issue 2179"""
with rasterio.open("tests/data/float_raster_with_nodata.tif") as src:
result, transform = merge([src], dtype="uint8")
assert not result.any() # this is why it's called "unsafe".