IndexableCycler
- class PlasmaCalcs.plotting.xarray_timelines.IndexableCycler(left: Cycler[K, V] | Iterable[dict[K, V]] | None, right: Cycler[K, V] | None = None, op: Any = None)
Bases:
CyclerCycler which can be indexed by integers.
Uses infinite indexing, i.e. result will be the same as the i’th value from itertools.cycle().[EFF] uses i % len(self), so the indexing time complexity doesn’t scale with i.Methods
__getitem__(i)return the ith element of the cycler, if i is an int.
by_key()Values by key.
change_key(old, new)Change a key in this cycler to a new name.
concat(right)Concatenate
Cyclers, as if chained usingitertools.chain.simplify()Simplify the cycler into a sum (but no products) of cyclers.
Attributes
The keys this Cycler knows about.
- __getitem__(i)
return the ith element of the cycler, if i is an int.
Otherwise use super().__getitem__.
- by_key() dict[K, list[V]]
Values by key.
This returns the transposed values of the cycler. Iterating
over aCycleryields dicts with a single value for each key,this method returns adictoflistwhich are the valuesfor the given key.The returned value can be used to create an equivalentCyclerusing only+.Returns——-- transposedict
- dict of lists of the values for each key.
- change_key(old: K, new: K) None
Change a key in this cycler to a new name.
Modification is performed in-place.Does nothing if the old key is the same as the new key.Raises a ValueError if the new key is already a key.Raises a KeyError if the old key isn’t a key.
- concat(right: Cycler[K, U]) Cycler[K, V | U]
Concatenate
Cyclers, as if chained usingitertools.chain.The keys must match exactly.
Examples
——–>>> num = cycler(‘a’, range(3))>>> let = cycler(‘a’, ‘abc’)>>> num.concat(let)cycler(‘a’, [0, 1, 2, ‘a’, ‘b’, ‘c’])Returns——-CyclerThe concatenated cycler.
- simplify() Cycler[K, V]
Simplify the cycler into a sum (but no products) of cyclers.
Returns
——-simple : Cycler