You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
hist and bin produce zero-width bins for a constant coord #3935
hist(x=N) and bin(x=N) derive the edges from the coord range. For a constant coord that range is empty, and the result is N bins of which N-1 have zero width:
importscippasscda=sc.DataArray(
sc.ones(dims=['row'], shape=[5], unit='counts'),
coords={'x': sc.array(dims=['row'], values=[3.0] *5, unit='K')},
)
h=da.hist(x=4)
h.coords['x'].values# array([3., 3., 3., 3.]) -- top edge raised by one ULPh.values# array([0., 5., 0., 0.])
_upper_bound raises the top edge by np.nextafter (by one for integer and datetime coords), which keeps the range technically non-empty, and linspace then spreads N+1 edges over it. All the counts land in bin index 1, whatever N. bin behaves the same way.
Integer coords show it a little differently — edges [7, 7, 7, 7, 8] for x=4 — where the whole unit of the bump lands in the last bin.
scipp 26.3.1, numpy 2.4.6.
Expected
Some defined behaviour for an empty coord range. Raising seems defensible, since "N bins spanning this range" is unsatisfiable; widening the range to something representable, or returning a single bin, would work too. The case worth avoiding is the current one, where the result looks well-formed and sum() is correct, so nothing surfaces the problem until you inspect the edges or try to draw them.
changed the title [-]hist and bin produce zero-width bins for a constant coord[/-][+]`hist` and `bin` produce zero-width bins for a constant coord[/+]on Jul 28, 2026
Activity
[-]hist and bin produce zero-width bins for a constant coord[/-][+]`hist` and `bin` produce zero-width bins for a constant coord[/+]