@@ -216,7 +216,7 @@ def _from_iter(cls, label, itr):
216
216
def __getitem__ (self , key ):
217
217
# TODO : maybe add numpy style fancy slicing
218
218
if isinstance (key , slice ):
219
- trans = self ._transpose ()
219
+ trans = self .by_key ()
220
220
return reduce (add , (_cycler (k , v [key ])
221
221
for k , v in six .iteritems (trans )))
222
222
else :
@@ -255,7 +255,7 @@ def __mul__(self, other):
255
255
if isinstance (other , Cycler ):
256
256
return Cycler (self , other , product )
257
257
elif isinstance (other , int ):
258
- trans = self ._transpose ()
258
+ trans = self .by_key ()
259
259
return reduce (add , (_cycler (k , v * other )
260
260
for k , v in six .iteritems (trans )))
261
261
else :
@@ -346,17 +346,21 @@ def _repr_html_(self):
346
346
output += "</table>"
347
347
return output
348
348
349
- def _transpose (self ):
350
- """
351
- Internal helper function which iterates through the
352
- styles and returns a dict of lists instead of a list of
353
- dicts. This is needed for multiplying by integers and
354
- for __getitem__
349
+ def by_key (self ):
350
+ """Values by key
351
+
352
+ This returns the transposed values of the cycler. Iterating
353
+ over a `Cycler` yields dicts with a single value for each key,
354
+ this method returns a `dict` of `list` which are the values
355
+ for the given key.
356
+
357
+ The returned value can be used to create an equivalent `Cycler`
358
+ using only `+`.
355
359
356
360
Returns
357
361
-------
358
- trans : dict
359
- dict of lists for the styles
362
+ transpose : dict
363
+ dict of lists of the values for each key.
360
364
"""
361
365
362
366
# TODO : sort out if this is a bottle neck, if there is a better way
@@ -386,7 +390,7 @@ def simplify(self):
386
390
# ((a + b) + (c + d))
387
391
# I would believe that there is some performance implications
388
392
389
- trans = self ._transpose ()
393
+ trans = self .by_key ()
390
394
return reduce (add , (_cycler (k , v ) for k , v in six .iteritems (trans )))
391
395
392
396
def concat (self , other ):
@@ -453,8 +457,8 @@ def concat(left, right):
453
457
454
458
raise ValueError (msg )
455
459
456
- _l = left ._transpose ()
457
- _r = right ._transpose ()
460
+ _l = left .by_key ()
461
+ _r = right .by_key ()
458
462
return reduce (add , (_cycler (k , _l [k ] + _r [k ]) for k in left .keys ))
459
463
460
464
0 commit comments