@@ -94,15 +94,17 @@ def named_tuple_sequence_stack(values: Sequence[NamedTuple]) -> NamedTuple:
94
94
class Deque :
95
95
"""Double ended queue with a maximum length and initial values."""
96
96
97
- def __init__ (self , max_length : int , initial_values = None ):
97
+ def __init__ (
98
+ self , max_length : int , initial_values : Optional [Iterable [Any ]] = None
99
+ ):
98
100
self ._deque = collections .deque (maxlen = max_length )
99
101
self ._initial_values = initial_values or []
100
102
101
103
def reset (self ) -> None :
102
104
self ._deque .clear ()
103
105
self ._deque .extend (self ._initial_values )
104
106
105
- def __call__ (self , value : Any ) -> collections .deque :
107
+ def __call__ (self , value : Any ) -> collections .deque [ Any ] :
106
108
self ._deque .append (value )
107
109
return self ._deque
108
110
@@ -297,19 +299,20 @@ def reduce_step_type(
297
299
"""Outputs a representative step type from an array of step types."""
298
300
# Zero padding will appear to be FIRST. Padding should only be seen before the
299
301
# FIRST (e.g. 000F) or after LAST (e.g. ML00).
300
- if debug :
301
- np_step_types = np .array (step_types )
302
+
302
303
output_step_type = StepType .MID
303
304
for i , step_type in enumerate (step_types ):
304
305
if step_type == 0 : # step_type not actually FIRST, but we do expect 000F.
305
- if debug and not (np_step_types == 0 ).all ():
306
- raise ValueError ('Expected zero padding followed by FIRST.' )
306
+ if debug :
307
+ if not (np .array (step_types ) == 0 ).all ():
308
+ raise ValueError ('Expected zero padding followed by FIRST.' )
307
309
output_step_type = StepType .FIRST
308
310
break
309
311
elif step_type == StepType .LAST :
310
312
output_step_type = StepType .LAST
311
- if debug and not (np_step_types [i + 1 :] == 0 ).all ():
312
- raise ValueError ('Expected LAST to be followed by zero padding.' )
313
+ if debug :
314
+ if not (np .array (step_types )[i + 1 :] == 0 ).all ():
315
+ raise ValueError ('Expected LAST to be followed by zero padding.' )
313
316
break
314
317
else :
315
318
if step_type != StepType .MID :
@@ -343,8 +346,12 @@ def aggregate_discounts(
343
346
raise ValueError (
344
347
'All discounts should be 0 or 1, got: %s.' % np_discounts
345
348
)
349
+ else :
350
+ np_discounts = None
351
+
346
352
if None in discounts :
347
353
if debug :
354
+ assert isinstance (np_discounts , np .ndarray )
348
355
if not (np_discounts [- 1 ] is None and (np_discounts [:- 1 ] == 0 ).all ()):
349
356
# Should have [0, 0, 0, None] due to zero padding.
350
357
raise ValueError ('Should only have a None discount for FIRST.' )
0 commit comments