Skip to content

Commit 5c98f72

Browse files
authoredJun 15, 2022
Merge pull request #56 from histogrammar/num_bins_fix
Num bins fix
2 parents dcbf220 + 06ba23b commit 5c98f72

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed
 

Diff for: ‎CHANGES.rst

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Release notes
33
=============
44

5+
Version 1.0.29, June 2022
6+
-------------------------
7+
* Fix for machine-level rounding error, which can show up on in num_bins() call of Bin histogram.
8+
59
Version 1.0.28, June 2022
610
-------------------------
711
* Multiple performance updates, to Bin, SparselyBin and Categorize histograms.

Diff for: ‎README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PyCUDA is available, they can also be filled from Numpy arrays by JIT-compiling
2020

2121
This Python implementation of histogrammar been tested to guarantee compatibility with its Scala implementation.
2222

23-
Latest Python release: v1.0.28 (June 2022).
23+
Latest Python release: v1.0.29 (June 2022).
2424

2525
Announcements
2626
=============

Diff for: ‎histogrammar/primitives/bin.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ def num_bins(self, low=None, high=None):
10041004
if np.isclose(high, self.low + self.bin_width() * maxBin):
10051005
maxBin -= 1
10061006
high = self.low + self.bin_width() * (maxBin + 1)
1007-
# number of bins
1008-
num_bins = int((high - low) / self.bin_width())
1007+
# number of bins. use np.round to correct for machine level rounding errors
1008+
num_bins = int(np.round((high - low) / self.bin_width()))
10091009
return num_bins
10101010

10111011
def bin_width(self):
@@ -1096,7 +1096,8 @@ def bin_edges(self, low=None, high=None):
10961096
if np.isclose(high, self.low + self.bin_width() * maxBin):
10971097
maxBin -= 1
10981098
high = self.low + self.bin_width() * (maxBin + 1)
1099-
1099+
# new low and high values reset, so redo num_bins
1100+
num_bins = self.num_bins(low, high)
11001101
edges = np.linspace(low, high, num_bins + 1)
11011102
return edges
11021103

Diff for: ‎histogrammar/primitives/sparselybin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,6 @@ def bin_edges(self, low=None, high=None):
736736
elif low is not None and high is not None:
737737
if low > high:
738738
raise RuntimeError('low {low} greater than high {high}'.format(low=low, high=high))
739-
# number of bins, before low/high adjustments
740-
num_bins = self.num_bins(low, high)
741739
# lowest edge
742740
if low is None:
743741
low = self.low
@@ -752,6 +750,8 @@ def bin_edges(self, low=None, high=None):
752750
if np.isclose(high, self.origin + self.bin_width() * maxBin):
753751
maxBin -= 1
754752
high = self.origin + self.bin_width() * (maxBin + 1)
753+
# number of bins, after low/high adjustments
754+
num_bins = self.num_bins(low, high)
755755
edges = np.linspace(low, high, num_bins + 1)
756756
return edges
757757

Diff for: ‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
MAJOR = 1
2424
REVISION = 0
25-
PATCH = 28
25+
PATCH = 29
2626
DEV = False
2727
# NOTE: also update version at: README.rst
2828

0 commit comments

Comments
 (0)