Skip to content

Commit 7148cad

Browse files
hoechenbergerpeircej
authored andcommitted
BF, TEST: Fix handling of nReversals in data.StairHandler
`StairHandler.nReversals` should never be `None`, but be set to a value equal to or greater than the length of the `stepSizes` parameter. Otherwise, we will finish prematurely during `calculateNextIntensity()`. This closes #1342.
1 parent f753140 commit 7148cad

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

psychopy/data.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,11 +2936,12 @@ def __init__(self,
29362936
self._variableStep = True if len(self.stepSizes) > 1 else False
29372937
self.stepSizeCurrent = self.stepSizes[0]
29382938

2939-
if nReversals is not None and len(self.stepSizes) > nReversals:
2940-
logging.warn(
2941-
"Increasing number of minimum required reversals to "
2942-
"the number of step sizes (%i)." % len(self.stepSizes)
2943-
)
2939+
if nReversals is None:
2940+
self.nReversals = len(self.stepSizes)
2941+
elif len(self.stepSizes) > nReversals:
2942+
msg = ('Increasing number of minimum required reversals to the '
2943+
'number of step sizes, (%i).' % len(self.stepSizes))
2944+
logging.warn(msg)
29442945
self.nReversals = len(self.stepSizes)
29452946
else:
29462947
self.nReversals = nReversals

psychopy/tests/test_data/test_StairHandlers.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def checkSimulationResults(self):
7373
# The first trial can never be a reversal.
7474
assert stairs.nReversals <= len(stairs.data) - 1
7575

76-
assert stairs.nReversals == len(stairs.reversalPoints)
77-
assert stairs.nReversals == len(stairs.reversalIntensities)
76+
assert len(stairs.reversalPoints) >= stairs.nReversals
77+
assert len(stairs.reversalIntensities) >= stairs.nReversals
7878

7979
if stairs.reversalPoints:
8080
assert stairs.reversalIntensities
@@ -307,6 +307,21 @@ def test_StairHandlerLinearScalarStepSizeReveralsNone(self):
307307
self.simulate()
308308
self.checkSimulationResults()
309309

310+
def test_nReversals(self):
311+
start_val = 1
312+
step_sizes = range(5)
313+
314+
staircase = data.StairHandler(startVal=start_val, stepSizes=step_sizes,
315+
nReversals=None)
316+
assert staircase.nReversals == len(step_sizes)
317+
318+
staircase = data.StairHandler(startVal=start_val, stepSizes=step_sizes,
319+
nReversals=1)
320+
assert staircase.nReversals == len(step_sizes)
321+
322+
staircase = data.StairHandler(startVal=start_val, stepSizes=step_sizes,
323+
nReversals=10)
324+
assert staircase.nReversals == 10
310325

311326
class TestQuestHandler(_BaseTestStairHandler):
312327
"""
@@ -330,6 +345,8 @@ def test_QuestHandler(self):
330345
minVal=minVal, maxVal=maxVal
331346
)
332347

348+
self.stairs.nReversals = None
349+
333350
self.responses = makeBasicResponseCycles(
334351
cycles=3, nCorrect=2, nIncorrect=2, length=10
335352
)

0 commit comments

Comments
 (0)