Skip to content

Commit

Permalink
Fix test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Mar 18, 2024
1 parent fa88235 commit 56ff1ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions geoutils/raster/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 8 additions & 7 deletions tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 56ff1ea

Please sign in to comment.