Skip to content

Commit

Permalink
histogram: Allow for a bit more error
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Apr 20, 2023
1 parent 91450e6 commit abffd88
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions enstat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def from_data(
integer: bool = False,
bin_edges: ArrayLike = None,
bound_error: str = "raise",
roundoff_error: float = 3.0 * np.finfo(np.float64).eps,
):
r"""
Construct a histogram from data.
Expand Down Expand Up @@ -542,6 +543,8 @@ def from_data(
- ``"ignore"``: ignore the data that are out of range
- ``"norm"``: change the normalisation of the density
:param roundoff_error: Extend the first and last bin with this margin.
:return: The :py:class:`Histogram` object.
"""

Expand All @@ -561,8 +564,8 @@ def from_data(
bin_edges = detail.histogram_bin_edges_integer(bin_edges)

bin_edges = np.array(bin_edges)
bin_edges[0] -= np.finfo(bin_edges.dtype).eps
bin_edges[-1] += np.finfo(bin_edges.dtype).eps
bin_edges[0] -= roundoff_error
bin_edges[-1] += roundoff_error
return cls(bin_edges, right=True, bound_error=bound_error).add_sample(data)

def strip(self, min_count: int = 0):
Expand Down Expand Up @@ -703,7 +706,7 @@ def add_sample(self, data: ArrayLike):
You can also use the ``+`` operator.
"""

bin = np.digitize(data, self.bin_edges, self.right) - 1
bin = np.digitize(data, self.bin_edges, right=self.right) - 1

left = bin < 0
right = bin >= self.count.size
Expand Down

0 comments on commit abffd88

Please sign in to comment.