Skip to content

Commit 0429ea2

Browse files
committed
Minor doc cleanups.
Punctuation. Use "cycler" instead of "Cycler" or "cycle" in sentences slightly more consistently. Remove parameter descriptions that add no information ("the second Cycler"). Remove unnecessary whitespace.
1 parent 3fa066d commit 0429ea2

File tree

1 file changed

+28
-52
lines changed

1 file changed

+28
-52
lines changed

cycler.py

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,17 @@
5757

5858
def _process_keys(left, right):
5959
"""
60-
Helper function to compose cycler keys
60+
Helper function to compose cycler keys.
6161
6262
Parameters
6363
----------
6464
left, right : iterable of dictionaries or None
65-
The cyclers to be composed
65+
The cyclers to be composed.
66+
6667
Returns
6768
-------
6869
keys : set
69-
The keys in the composition of the two cyclers
70+
The keys in the composition of the two cyclers.
7071
"""
7172
l_peek = next(iter(left)) if left is not None else {}
7273
r_peek = next(iter(right)) if right is not None else {}
@@ -78,28 +79,22 @@ def _process_keys(left, right):
7879

7980

8081
def concat(left, right):
81-
"""
82-
Concatenate two cyclers, as if chained using `itertools.chain`.
82+
r"""
83+
Concatenate `Cycler`\s, as if chained using `itertools.chain`.
8384
8485
The keys must match exactly.
8586
8687
Examples
8788
--------
88-
8989
>>> num = cycler('a', range(3))
9090
>>> let = cycler('a', 'abc')
9191
>>> num.concat(let)
9292
cycler('a', [0, 1, 2, 'a', 'b', 'c'])
9393
94-
Parameters
95-
----------
96-
left, right : `Cycler`
97-
The two `Cycler` instances to concatenate
98-
9994
Returns
10095
-------
101-
ret : `Cycler`
102-
The concatenated `Cycler`
96+
`Cycler`
97+
The concatenated cycler.
10398
"""
10499
if left.keys != right.keys:
105100
raise ValueError("Keys do not match:\n"
@@ -114,7 +109,7 @@ def concat(left, right):
114109

115110
class Cycler(object):
116111
"""
117-
Composable cycles
112+
Composable cycles.
118113
119114
This class has compositions methods:
120115
@@ -130,25 +125,22 @@ class Cycler(object):
130125
``*=``
131126
in-place ``*``
132127
133-
and supports basic slicing via ``[]``
128+
and supports basic slicing via ``[]``.
134129
135130
Parameters
136131
----------
137-
left : Cycler or None
138-
The 'left' cycler
139-
140-
right : Cycler or None
141-
The 'right' cycler
142-
132+
left, right : Cycler or None
133+
The 'left' and 'right' cyclers.
143134
op : func or None
144135
Function which composes the 'left' and 'right' cyclers.
145-
146136
"""
137+
147138
def __call__(self):
148139
return cycle(self)
149140

150141
def __init__(self, left, right=None, op=None):
151-
"""Semi-private init
142+
"""
143+
Semi-private init.
152144
153145
Do not use this directly, use `cycler` function instead.
154146
"""
@@ -178,9 +170,7 @@ def __contains__(self, k):
178170

179171
@property
180172
def keys(self):
181-
"""
182-
The keys this Cycler knows about
183-
"""
173+
"""The keys this Cycler knows about."""
184174
return set(self._keys)
185175

186176
def change_key(self, old, new):
@@ -191,7 +181,6 @@ def change_key(self, old, new):
191181
Does nothing if the old key is the same as the new key.
192182
Raises a ValueError if the new key is already a key.
193183
Raises a KeyError if the old key isn't a key.
194-
195184
"""
196185
if old == new:
197186
return
@@ -235,8 +224,8 @@ def _from_iter(cls, label, itr):
235224
236225
Returns
237226
-------
238-
cycler : Cycler
239-
New 'base' `Cycler`
227+
`Cycler`
228+
New 'base' cycler.
240229
"""
241230
ret = cls(None)
242231
ret._left = list({label: v} for v in itr)
@@ -264,12 +253,11 @@ def __iter__(self):
264253

265254
def __add__(self, other):
266255
"""
267-
Pair-wise combine two equal length cycles (zip)
256+
Pair-wise combine two equal length cyclers (zip).
268257
269258
Parameters
270259
----------
271260
other : Cycler
272-
The second Cycler
273261
"""
274262
if len(self) != len(other):
275263
raise ValueError("Can only add equal length cycles, "
@@ -278,13 +266,12 @@ def __add__(self, other):
278266

279267
def __mul__(self, other):
280268
"""
281-
Outer product of two cycles (`itertools.product`) or integer
269+
Outer product of two cyclers (`itertools.product`) or integer
282270
multiplication.
283271
284272
Parameters
285273
----------
286274
other : Cycler or int
287-
The second Cycler or integer
288275
"""
289276
if isinstance(other, Cycler):
290277
return Cycler(self, other, product)
@@ -307,12 +294,11 @@ def __len__(self):
307294

308295
def __iadd__(self, other):
309296
"""
310-
In-place pair-wise combine two equal length cycles (zip)
297+
In-place pair-wise combine two equal length cyclers (zip).
311298
312299
Parameters
313300
----------
314301
other : Cycler
315-
The second Cycler
316302
"""
317303
if not isinstance(other, Cycler):
318304
raise TypeError("Cannot += with a non-Cycler object")
@@ -326,12 +312,11 @@ def __iadd__(self, other):
326312

327313
def __imul__(self, other):
328314
"""
329-
In-place outer product of two cycles (`itertools.product`)
315+
In-place outer product of two cyclers (`itertools.product`).
330316
331317
Parameters
332318
----------
333319
other : Cycler
334-
The second Cycler
335320
"""
336321
if not isinstance(other, Cycler):
337322
raise TypeError("Cannot *= with a non-Cycler object")
@@ -344,14 +329,10 @@ def __imul__(self, other):
344329
return self
345330

346331
def __eq__(self, other):
347-
"""
348-
Check equality
349-
"""
350332
if len(self) != len(other):
351333
return False
352334
if self.keys ^ other.keys:
353335
return False
354-
355336
return all(a == b for a, b in zip(self, other))
356337

357338
def __ne__(self, other):
@@ -385,7 +366,8 @@ def _repr_html_(self):
385366
return output
386367

387368
def by_key(self):
388-
"""Values by key
369+
"""
370+
Values by key.
389371
390372
This returns the transposed values of the cycler. Iterating
391373
over a `Cycler` yields dicts with a single value for each key,
@@ -416,20 +398,18 @@ def by_key(self):
416398
_transpose = by_key
417399

418400
def simplify(self):
419-
"""Simplify the Cycler
420-
421-
Returned as a composition using only sums (no multiplications)
401+
"""
402+
Simplify the cycler into a sum (but no products) of cyclers.
422403
423404
Returns
424405
-------
425406
simple : Cycler
426-
An equivalent cycler using only summation"""
407+
"""
427408
# TODO: sort out if it is worth the effort to make sure this is
428409
# balanced. Currently it is is
429410
# (((a + b) + c) + d) vs
430411
# ((a + b) + (c + d))
431412
# I would believe that there is some performance implications
432-
433413
trans = self.by_key()
434414
return reduce(add, (_cycler(k, v) for k, v in trans.items()))
435415

@@ -459,12 +439,10 @@ def cycler(*args, **kwargs):
459439
----------
460440
arg : Cycler
461441
Copy constructor for Cycler (does a shallow copy of iterables).
462-
463442
label : name
464443
The property key. In the 2-arg form of the function,
465444
the label can be any hashable object. In the keyword argument
466445
form of the function, it must be a valid python identifier.
467-
468446
itr : iterable
469447
Finite length iterable of the property values.
470448
Can be a single-property `Cycler` that would
@@ -499,14 +477,12 @@ def cycler(*args, **kwargs):
499477

500478
def _cycler(label, itr):
501479
"""
502-
Create a new `Cycler` object from a property name and
503-
iterable of values.
480+
Create a new `Cycler` object from a property name and iterable of values.
504481
505482
Parameters
506483
----------
507484
label : hashable
508485
The property key.
509-
510486
itr : iterable
511487
Finite length iterable of the property values.
512488

0 commit comments

Comments
 (0)