Skip to content

Commit

Permalink
Deal with NaNs in the histograms.
Browse files Browse the repository at this point in the history
  • Loading branch information
ast0815 committed Mar 21, 2021
1 parent 44f3530 commit a67c6b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion histoprint/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...]
Expand Down
9 changes: 9 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit a67c6b3

Please sign in to comment.