From 059a8647a606497adb3251fa420bbe97729d2bb0 Mon Sep 17 00:00:00 2001 From: Pietro Berkes Date: Sun, 20 Jul 2025 12:47:16 +0200 Subject: [PATCH 1/2] Add test to reproduce issue #243, and fix --- psignifit/tools.py | 6 ++++-- tests/test_pooling.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/psignifit/tools.py b/psignifit/tools.py index 41745ef..5fd45be 100644 --- a/psignifit/tools.py +++ b/psignifit/tools.py @@ -34,9 +34,11 @@ def pool_blocks(data: np.ndarray, max_tol=0, max_gap=np.inf, max_length=np.inf): block = [] gap = 0 for j in range(i, ndata): - if (cum_ntrials[j + 1] - - cum_ntrials[i]) > max_length or gap > max_gap: + # j > i condition: make sure there is at least one data point per block + if ((cum_ntrials[j + 1] - cum_ntrials[i]) > max_length + or gap > max_gap) and j > i: break + level, ncorrect, ntrials = data[j, :] if abs(level - current) <= max_tol and not seen[j]: seen[j] = True diff --git a/tests/test_pooling.py b/tests/test_pooling.py index f62ee73..adcced6 100644 --- a/tests/test_pooling.py +++ b/tests/test_pooling.py @@ -112,6 +112,25 @@ def test_pooling_big_max_gap(): assert np.allclose(exp, act, rtol=0, atol=1e-04) +def test_pooling_243(): + # Reproduces issue #243 + + data = np.array([ + [100, 50, 50], + [101, 51, 51], + [200, 60, 60], + [201, 61, 61], + [300, 70, 70], + [301, 71, 71], + [400, 80, 80] + ]) + + # Crashes with: + # TypeError: cannot unpack non-iterable numpy.float64 object + pooled = pool_blocks(data, max_tol=50, max_gap=50, max_length=10) + assert np.allclose(pooled, data) + + data = np.array([ [1.3262, 1, 1], [0.8534, 1, 1], From 7ea666794892618fa302f439568051876c6edfbf Mon Sep 17 00:00:00 2001 From: Pietro Berkes Date: Sun, 20 Jul 2025 12:51:19 +0200 Subject: [PATCH 2/2] Remove unnecessary comment in test --- tests/test_pooling.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_pooling.py b/tests/test_pooling.py index adcced6..92d164e 100644 --- a/tests/test_pooling.py +++ b/tests/test_pooling.py @@ -125,8 +125,6 @@ def test_pooling_243(): [400, 80, 80] ]) - # Crashes with: - # TypeError: cannot unpack non-iterable numpy.float64 object pooled = pool_blocks(data, max_tol=50, max_gap=50, max_length=10) assert np.allclose(pooled, data)