@@ -69,12 +69,14 @@ def combinations(sequence, n=None, start=0):
6969 yield [thing ] + sub_result
7070
7171
72- class NoFillValue (object ):
73- '''Don't fill last partition with default fill values.'''
72+ class NO_FILL_VALUE (object ):
73+ '''
74+ Sentinel that means: Don't fill last partition with default fill values.
75+ '''
7476
7577
7678def partitions (sequence , partition_size = None , n_partitions = None ,
77- allow_remainder = True , fillvalue = NoFillValue ):
79+ allow_remainder = True , fill_value = NO_FILL_VALUE ):
7880 '''
7981 Partition `sequence` into equal partitions of size `partition_size`, or
8082 determine size automatically given the number of partitions as
@@ -96,14 +98,14 @@ def partitions(sequence, partition_size=None, n_partitions=None,
9698 exception will be raised.
9799
98100 If you want the remainder partition to be of equal size with the other
99- partitions, you can specify `fillvalue ` as the padding for the last
100- partition. A specified value for `fillvalue ` implies `allow_remainder=True`
101+ partitions, you can specify `fill_value ` as the padding for the last
102+ partition. A specified value for `fill_value ` implies `allow_remainder=True`
101103 and will cause an exception to be raised if specified with
102104 `allow_remainder=False`.
103105
104106 Example:
105107
106- >>> partitions([0, 1, 2, 3, 4], 3, fillvalue =None)
108+ >>> partitions([0, 1, 2, 3, 4], 3, fill_value =None)
107109 [[0, 1, 2], [3, 4, None]]
108110 '''
109111
@@ -115,9 +117,9 @@ def partitions(sequence, partition_size=None, n_partitions=None,
115117 raise Exception ('You must specify *either* `partition_size` *or* '
116118 '`n_paritions`.' )
117119
118- if fillvalue != NoFillValue and not allow_remainder :
119- raise ValueError ("fillvalue cannot be specified if allow_remainder "
120- " is False." )
120+ if fill_value != NO_FILL_VALUE and not allow_remainder :
121+ raise ValueError ('`fill_value` cannot be specified if '
122+ '`allow_remainder` is ` False`.' )
121123
122124 remainder_length = sequence_length % (partition_size if partition_size
123125 is not None else n_partitions )
@@ -138,8 +140,9 @@ def partitions(sequence, partition_size=None, n_partitions=None,
138140 blocks = [sequence [i : i + partition_size ] for i in
139141 xrange (0 , enlarged_length , partition_size )]
140142
141- if fillvalue != NoFillValue :
142- filler = itertools .repeat (fillvalue , enlarged_length - sequence_length )
143+ if fill_value != NO_FILL_VALUE and blocks :
144+ filler = itertools .repeat (fill_value ,
145+ enlarged_length - sequence_length )
143146 blocks [- 1 ].extend (filler )
144147
145148 return blocks
0 commit comments