diff --git a/geoutils/raster/raster.py b/geoutils/raster/raster.py index 2a46423f..1fbfb83b 100644 --- a/geoutils/raster/raster.py +++ b/geoutils/raster/raster.py @@ -807,9 +807,9 @@ def to_rio_dataset(self) -> rio.io.DatasetReader: driver="GTiff", ) as ds: if self.count == 1: - ds.write(self.data.filled(self.nodata)[np.newaxis, :, :]) + ds.write(self.data[np.newaxis, :, :]) else: - ds.write(self.data.filled(self.nodata)) + ds.write(self.data) # Then open as a DatasetReader return mfh.open() diff --git a/tests/test_raster.py b/tests/test_raster.py index 0b6c0853..643970cc 100644 --- a/tests/test_raster.py +++ b/tests/test_raster.py @@ -3466,19 +3466,20 @@ def test_raster_equal(self) -> None: assert not r1.raster_equal(r2) # Change value of a masked cell - r1.data[0, 0] = np.ma.masked - r1.data.data[0, 0] = 0 r2 = r1.copy() - r2.data.data[0, 0] = 10 - assert not r1.raster_equal(r2) - assert r1.raster_equal(r2, strict_masked=False) + r2.data[0, 0] = np.ma.masked + r2.data.data[0, 0] = 0 + r3 = r2.copy() + r3.data.data[0, 0] = 10 + assert not r2.raster_equal(r3) + assert r2.raster_equal(r3, strict_masked=False) # Check that a warning is raised with useful information without equality with pytest.warns(UserWarning, match="Equality failed for: data.data."): - assert not r1.raster_equal(r2, warn_failure_reason=True) + assert not r2.raster_equal(r3, warn_failure_reason=True) # But no warning is raised for an equality - assert r1.raster_equal(r2, strict_masked=False, warn_failure_reason=True) + assert r2.raster_equal(r3, strict_masked=False, warn_failure_reason=True) def test_equal_georeferenced_grid(self) -> None: """