Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Ensure consistency between numpy.histogram and numpy.digitize
Related to #219. Ensure numpy.histogram and numpy.digitize yield comparable results. The difference is caused by the fact that numpy.histogram treats the rightmost bin as a closed interval (i.e. values equal to the rightmost edge are included in the last bin). On the other hand, numpy.digitize treats all bins as half open (including the rightmost). In this latter case, values equal to the rightmost bin edge are given value `len(bins) + 1`. Ensure consistent behaviour (with half open bins for all bins) by adding an extra bin edge when using fixed bin width (i.e. the rightmost edge is > max(targetValues)). When using a fixed bin count, correct behaviour was already ensured by adding +1 to the last bin (which is guaranteed to be equal to max(targetValues). In this case, the +1 ensures nummpy.digitize considers these maximum values as part of the last bin, seeing as the edges are arranged such, that a specific number of bins is obtained). On relation to #219: In that PR, the +1 to the rightmost bin was removed to allow 'switching off' binning by specifying bin-width 1. However, this changed did return the inconsistency between numpy.histogram and numpy.digitize, which is now corrected by this commit (by ensuring numpy.histogram is consistent with numpy.digitize, instead of the other way around).
- Loading branch information