LightcurveDB Utility Module¶
- lightcurvedb.util.iter.chunkify(iterable, chunksize, fillvalue=None)¶
Chunkify an iterable into equal sized partitions. The last chunk yielded might contain leftovers and have a length less than specified. If a
fillvalue
is specified then this value will be padded in the last chunk until it meets the chunksize requirement.- Parameters:
iterable (iterable) – Some iterable to chunkify into partitions
chunksize (integer) – The size of the returned partitions. Must be greater than 0 otherwise a
ValueError
is raised.fillvalue (any, optional) – If the last partition
length < chunksize
then right pad the partition with the fillvalue` until the wanted partition size is reached.
- Yields:
list – A partitioned list of length <= chunksize
- Raises:
ValueError – For chunksize < 1.
- lightcurvedb.util.iter.enumerate_chunkify(iterable, chunksize, offset=0, fillvalue=None)¶
Chunkify’s an iterable and provides the nth iteration to each chunk element. This can be offset by the
offset
value.
- lightcurvedb.util.iter.eq_partitions(iterable, n)¶
Create
n
partitions and distribute the iterable as equally as possible between the partitions.- Parameters:
iterable (iterable) – Some iterable to partition into
n
listsn (int) – The number of partitions to create. Cannot be less than 1. If this number is greater than the number of items within the given iterable, then it is guaranteed that some lists will be empty.
- Raises:
ValueError – Raised if
n
is less than 1.- Returns:
Returns a tuple of lists. The tuple is length of
n
. The lists contained within will be variant in length.- Return type:
tuple
- lightcurvedb.util.iter.keyword_zip(**keywords)¶
Perform the same operation as
zip
but instead of returning Tuples this function returns dictionaries.- Parameters:
**keywords – Abitrary keyword parameters. These parameters should be equal length iterables.
- Yields:
dict – A dictionary containing an equivalently indexed slice across all keyword parameters.
- lightcurvedb.util.iter.yield_ordered_result(items, attr, ordering)¶
Returns items in order specified. This ordering is pulled from the specified
attr
. If values in theordering
do not exist within theitems
thenNone
is yielded before moving onto the next ordering.- Parameters:
items (iterable of objects) – A list of objects to be ordered.
attr (str) – The attribute of the item to be interpreted for ordering.
ordering (list of keys) – A list of keys to be used as an ordering for yielding items.
- Yields:
object or None – Returns the item found or None if no value within the ordering could be found in the items list.