Skip to content

Commit a6512d3

Browse files
committed
Test: ensure rebinning does not mutate input groups list in-place
1 parent cf6ed32 commit a6512d3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_histogram_indexing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,19 @@ def test_setting_histogram_mismatch():
554554
h[:len, 0] = bh.Histogram(
555555
bh.axis.Regular(10, 0, 10, underflow=False, overflow=False)
556556
)
557+
558+
559+
def test_rebin_groups_no_inplace_modification():
560+
"""
561+
Test that rebinning with a groups list does not mutate the input list in-place.
562+
This ensures consecutive rebin operations with the same list do not fail.
563+
"""
564+
h1 = bh.Histogram(bh.axis.Regular(60, 0, 600))
565+
h2 = bh.Histogram(bh.axis.Regular(60, 0, 600))
566+
rebinner = [5] * 12
567+
h3 = h1[bh.rebin(groups=rebinner)]
568+
# The original list should remain unchanged
569+
assert rebinner == [5] * 12, "rebinner list was mutated in-place"
570+
# Second rebin should not raise
571+
h4 = h2[bh.rebin(groups=rebinner)]
572+
assert h3 == h4

0 commit comments

Comments
 (0)