Skip to content

Commit 059a864

Browse files
committed
Add test to reproduce issue #243, and fix
1 parent eb069cf commit 059a864

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

psignifit/tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def pool_blocks(data: np.ndarray, max_tol=0, max_gap=np.inf, max_length=np.inf):
3434
block = []
3535
gap = 0
3636
for j in range(i, ndata):
37-
if (cum_ntrials[j + 1] -
38-
cum_ntrials[i]) > max_length or gap > max_gap:
37+
# j > i condition: make sure there is at least one data point per block
38+
if ((cum_ntrials[j + 1] - cum_ntrials[i]) > max_length
39+
or gap > max_gap) and j > i:
3940
break
41+
4042
level, ncorrect, ntrials = data[j, :]
4143
if abs(level - current) <= max_tol and not seen[j]:
4244
seen[j] = True

tests/test_pooling.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ def test_pooling_big_max_gap():
112112
assert np.allclose(exp, act, rtol=0, atol=1e-04)
113113

114114

115+
def test_pooling_243():
116+
# Reproduces issue #243
117+
118+
data = np.array([
119+
[100, 50, 50],
120+
[101, 51, 51],
121+
[200, 60, 60],
122+
[201, 61, 61],
123+
[300, 70, 70],
124+
[301, 71, 71],
125+
[400, 80, 80]
126+
])
127+
128+
# Crashes with:
129+
# TypeError: cannot unpack non-iterable numpy.float64 object
130+
pooled = pool_blocks(data, max_tol=50, max_gap=50, max_length=10)
131+
assert np.allclose(pooled, data)
132+
133+
115134
data = np.array([
116135
[1.3262, 1, 1],
117136
[0.8534, 1, 1],

0 commit comments

Comments
 (0)