7
7
You can add cyclers::
8
8
9
9
from cycler import cycler
10
- cc = (cycler(' color', list('rgb')) +
11
- cycler(' linestyle', ['-', '--', '-.']))
10
+ cc = (cycler(color= list('rgb')) +
11
+ cycler(linestyle= ['-', '--', '-.']))
12
12
for d in cc:
13
13
print(d)
14
14
22
22
You can multiply cyclers::
23
23
24
24
from cycler import cycler
25
- cc = (cycler(' color', list('rgb')) *
26
- cycler(' linestyle', ['-', '--', '-.']))
25
+ cc = (cycler(color= list('rgb')) *
26
+ cycler(linestyle= ['-', '--', '-.']))
27
27
for d in cc:
28
28
print(d)
29
29
@@ -164,8 +164,8 @@ def __getitem__(self, key):
164
164
# TODO : maybe add numpy style fancy slicing
165
165
if isinstance (key , slice ):
166
166
trans = self ._transpose ()
167
- return reduce ( add , ( cycler (k , v [key ])
168
- for k , v in six .iteritems (trans )))
167
+ return cycler ( ** dict ( (k , v [key ])
168
+ for k , v in six .iteritems (trans )))
169
169
else :
170
170
raise ValueError ("Can only use slices with Cycler.__getitem__" )
171
171
@@ -203,8 +203,8 @@ def __mul__(self, other):
203
203
return Cycler (self , other , product )
204
204
elif isinstance (other , int ):
205
205
trans = self ._transpose ()
206
- return reduce ( add , ( cycler (k , v * other )
207
- for k , v in six .iteritems (trans )))
206
+ return cycler ( ** dict ( (k , v * other )
207
+ for k , v in six .iteritems (trans )))
208
208
else :
209
209
return NotImplemented
210
210
@@ -268,7 +268,7 @@ def __repr__(self):
268
268
if self ._right is None :
269
269
lab = self .keys .pop ()
270
270
itr = list (v [lab ] for v in self )
271
- return "cycler({lab!r}, {itr!r})" .format (lab = lab , itr = itr )
271
+ return "cycler({lab}= {itr!r})" .format (lab = lab , itr = itr )
272
272
else :
273
273
op = op_map .get (self ._op , '?' )
274
274
msg = "({left!r} {op} {right!r})"
@@ -329,7 +329,7 @@ def simplify(self):
329
329
# I would believe that there is some performance implications
330
330
331
331
trans = self ._transpose ()
332
- return reduce ( add , ( cycler (k , v ) for k , v in six .iteritems (trans )))
332
+ return cycler ( ** dict ( (k , v ) for k , v in six .iteritems (trans )))
333
333
334
334
335
335
def cycler (* args , ** kwargs ):
@@ -338,13 +338,10 @@ def cycler(*args, **kwargs):
338
338
positional arguments or keyword arguments.
339
339
340
340
cycler(arg)
341
- cycler(label1, itr1[, label2, iter2[, ...]])
342
341
cycler(label1=itr1[, label2=iter2[, ...]])
343
342
344
343
Form 1 simply copies a given `Cycler` object.
345
- Form 2 composes a `Cycler` as an outer product of the
346
- pairs of label/iter.
347
- Form 3 composes a `Cycler` as an inner product of the
344
+ Form 2 composes a `Cycler` as an inner product of the
348
345
pairs of keyword arguments.
349
346
350
347
Parameters
@@ -359,31 +356,25 @@ def cycler(*args, **kwargs):
359
356
-------
360
357
cycler : Cycler
361
358
New `Cycler` for the given property
362
- """
363
359
360
+ """
364
361
if args and kwargs :
365
362
raise TypeError ("cyl() can only accept positional OR keyword "
366
363
"arguments -- not both." )
367
- elif not args and not kwargs :
368
- raise TypeError ("cyl() must have positional OR keyword arguments" )
369
364
370
365
if len (args ) == 1 :
371
366
if not isinstance (args [0 ], Cycler ):
372
367
raise TypeError ("If only one positional argument given, it must "
373
368
" be a Cycler instance." )
374
369
return copy .copy (args [0 ])
375
370
elif len (args ) > 1 :
376
- if (len (args ) % 2 ) == 1 :
377
- raise TypeError ("Positional arguments must be in pairs. Odd "
378
- " number of arguments found: %d" % len (args ))
379
- pairs = [(args [i ], args [i + 1 ]) for i in range (0 , len (args ), 2 )]
380
- op = mul
371
+ raise TypeError ("Only a single Cycler can be accepted as the lone "
372
+ "positional argument. Use keyword arguments instead." )
381
373
382
374
if kwargs :
383
- pairs = six .iteritems (kwargs )
384
- op = add
375
+ return reduce (add , (_cycler (k , v ) for k , v in six .iteritems (kwargs )))
385
376
386
- return reduce ( op , ( _cycler ( k , v ) for k , v in pairs ) )
377
+ raise TypeError ( "Must have at least a positional OR keyword arguments" )
387
378
388
379
389
380
def _cycler (label , itr ):
0 commit comments