Skip to content

Commit

Permalink
disallow non-finite Box coords
Browse files Browse the repository at this point in the history
  • Loading branch information
AdeelH committed Oct 10, 2024
1 parent 10a9c98 commit 1ca6357
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rastervision_core/rastervision/core/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def __init__(self, ymin: int, xmin: int, ymax: int, xmax: int):
ymax: maximum y value
xmax: maximum x value
"""
if not all(math.isfinite(v) for v in (ymin, xmin, ymax, xmax)):
raise ValueError(
f'Invalid Box coordinates: {(ymin, xmin, ymax, xmax)}.')

self.ymin = ymin
self.xmin = xmin
self.ymax = ymax
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ def test_in(self):
with self.assertRaises(NotImplementedError):
_ = '' in Box(0, 0, 1, 1)

def test_error_on_nonfinite_inputs(self):
self.assertRaises(ValueError, lambda: Box(np.inf, 0, 0, 0))
self.assertRaises(ValueError, lambda: Box(-np.inf, 0, 0, 0))
self.assertRaises(ValueError, lambda: Box(np.nan, 0, 0, 0))


if __name__ == '__main__':
unittest.main()

0 comments on commit 1ca6357

Please sign in to comment.