diff --git a/histoprint/formatter.py b/histoprint/formatter.py index 8ebd012..1a1848f 100644 --- a/histoprint/formatter.py +++ b/histoprint/formatter.py @@ -411,7 +411,7 @@ def format_histogram(self, counts): ) hist_width = self.columns - axis_width - counts = np.array(counts) + counts = np.nan_to_num(np.array(counts)) while counts.ndim < 2: # Make sure counts is a 2D array counts = counts[np.newaxis, ...] diff --git a/tests/test.py b/tests/test.py index 9752924..af1b234 100644 --- a/tests/test.py +++ b/tests/test.py @@ -47,6 +47,15 @@ def test_hist(): ) +def test_nan(): + """Test dealing with nan values.""" + + data = np.arange(7, dtype=float) + data[5] = np.nan + bins = np.arange(8) + print_hist((data, bins)) + + def test_boost(): """Test boost-histogram if it is available."""