Skip to content

Reject bin-edge outer coords in combine_bins fast path - #3956

Merged
SimonHeybrock merged 2 commits into
mainfrom
3955-reject-bin-edge-outer-coords
Aug 25, 2026
Merged

SimonHeybrock merged 2 commits into
mainfrom
3955-reject-bin-edge-outer-coords

Conversation

@SimonHeybrock

Copy link
Copy Markdown
Member

bin and group have accepted a bin-edge outer coord ever since the combine_bins fast path was introduced, while the C++ implementation rejects such input with BinEdgeError. Which semantics applied therefore depended on whether the fast path happened to be taken, and the fast path itself was inconsistent: flattening a single dim silently used the coord's first values, one per input bin, whereas flattening more than one dim dropped the coord and failed later with a confusing KeyError: "Expected 'y' in <scipp.Dict.keys {}>.".

Reject such coords in _can_operate_on_bins so that binning falls through to the C++ implementation, which explains the problem and how to fix it.

Breaking change. Code that binned or grouped by a bin-edge outer coord and relied on the fast path now raises BinEdgeError. The fix is to pass a non-edge coord, choosing explicitly which value represents each bin. Our own filtering docs relied on this, and are updated accordingly; the numbers in that notebook are unchanged.

Stacked on #3949, which marks these cases as xfail. Review/merge that one first.

Fixes #3955

Test plan

@SimonHeybrock
SimonHeybrock force-pushed the 3955-reject-bin-edge-outer-coords branch from c84fbc5 to 60947b7 Compare August 25, 2026 09:17
Base automatically changed from 3948-hist-argument-order-oom to main August 25, 2026 09:50
SimonHeybrock and others added 2 commits August 25, 2026 11:50
Since combine_bins was introduced, bin and group have accepted a bin-edge outer
coord, which the C++ implementation rejects with BinEdgeError. Which semantics
applied depended on whether the fast path happened to be taken, and the fast
path itself was inconsistent: flattening a single dim silently used the coord's
first values, one per input bin, while flattening more than one dim dropped the
coord and failed with a confusing KeyError.

Reject such coords so that binning falls through to the C++ implementation,
which reports the problem and how to fix it.

The filtering docs relied on the silent behavior. Pass the leading values
explicitly, which labels each time interval by the strain at its start, as
before, and matches the interpolation used earlier in that notebook.

Fixes #3955

Co-Authored-By: Claude Opus 5 <[email protected]>
Labelling each time interval by the strain at its start is not an arbitrary
choice: it matches the mode='previous' interpolation that assigns a strain to
each event, so that numerator and denominator of the normalization agree.

Co-Authored-By: Claude Opus 5 <[email protected]>
@SimonHeybrock
SimonHeybrock force-pushed the 3955-reject-bin-edge-outer-coords branch from 60947b7 to e2827d8 Compare August 25, 2026 09:50
@SimonHeybrock
SimonHeybrock merged commit 08cb238 into main Aug 25, 2026
4 checks passed
@SimonHeybrock
SimonHeybrock deleted the 3955-reject-bin-edge-outer-coords branch August 25, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

combine_bins fast path accepts bin-edge outer coords rejected by the C++ implementation

2 participants