Skip to content

Commit

Permalink
Merge pull request #154 from dfm/infinite-loop
Browse files Browse the repository at this point in the history
Fixing infinite loop
  • Loading branch information
dfm committed Mar 17, 2021
2 parents c0c6264 + 4651d95 commit 6dcfb7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/corner/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ def hist2d(
"have no dynamic range. You could try using the "
"'range' argument."
)
if H.sum() == 0:
raise ValueError(
"It looks like the provided 'range' is not valid "
"or the sample is empty."
)

if smooth is not None:
if gaussian_filter is None:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hist2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ def test_lowNfilled():
)
def test_lowNnofill():
_run_hist2d("lowNnofill", N=20, no_fill_contours=True)


def test_infinite_loop():
x, y = np.random.rand(2, 1000)
with pytest.raises(ValueError):
corner.hist2d(x, y, 20, range=[(0, 1), (2, 3)])

0 comments on commit 6dcfb7f

Please sign in to comment.