Skip to content

Commit

Permalink
Add tests for new raster_equal options
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Mar 18, 2024
1 parent 7385f94 commit 27e4287
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion geoutils/raster/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def raster_equal(self, other: RasterType, strict_masked: bool = True, warn_failu
- The raster's transform, crs and nodata values.
:param other: Other raster.
:param strict_masked: Whether to check if masked pixels (in .data.mask) have the same value (in .data.data).
:param strict_masked: Whether to check if masked cells (in .data.mask) have the same value (in .data.data).
:param warn_failure_reason: Whether to warn for the reason of failure if the check does not pass.
"""

Expand Down
15 changes: 15 additions & 0 deletions tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3465,6 +3465,21 @@ def test_raster_equal(self) -> None:
r2.set_nodata(34)
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)

# 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)

# But no warning is raised for an equality
assert r1.raster_equal(r2, strict_masked=False, warn_failure_reason=True)

def test_equal_georeferenced_grid(self) -> None:
"""
Test that equal for shape, crs and transform work as expected
Expand Down

0 comments on commit 27e4287

Please sign in to comment.