Skip to content

Commit f69227a

Browse files
committed
Tighten up python Tile equality test for nodata/masked cells; fix test_matmul
Signed-off-by: Jason T. Brown <[email protected]>
1 parent aa67956 commit f69227a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pyrasterframes/src/main/python/pyrasterframes/rf_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def __init__(self, cells, cell_type=None):
295295

296296
def __eq__(self, other):
297297
if type(other) is type(self):
298-
return self.cell_type == other.cell_type and np.ma.allequal(self.cells, other.cells)
298+
return self.cell_type == other.cell_type and \
299+
np.ma.allequal(self.cells, other.cells, fill_value=True)
299300
else:
300301
return False
301302

pyrasterframes/src/main/python/tests/PyRasterFramesTests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,6 @@ def less_pi(t):
532532

533533
class TileOps(TestEnvironment):
534534

535-
from pyrasterframes.rf_types import Tile
536-
537535
def setUp(self):
538536
# convenience so we can assert around Tile() == Tile()
539537
self.t1 = Tile(np.array([[1, 2],
@@ -589,9 +587,11 @@ def test_matmul(self):
589587
# r1 = self.t1 @ self.t2
590588
r1 = self.t1.__matmul__(self.t2)
591589

592-
nd = r1.cell_type.no_data_value()
593-
e1 = Tile(np.ma.masked_equal(np.array([[nd, 10],
594-
[nd, nd]], dtype=r1.cell_type.to_numpy_dtype()), nd))
590+
# The behavior of np.matmul with masked arrays is not well documented
591+
# it seems to treat the 2nd arg as if not a MaskedArray
592+
e1 = Tile(np.matmul(self.t1.cells, self.t2.cells), r1.cell_type)
593+
594+
self.assertTrue(r1 == e1, "{} was not equal to {}".format(r1, e1))
595595
self.assertEqual(r1, e1)
596596

597597

0 commit comments

Comments
 (0)