utils

defaultdictwithargs

A defaultdict that will create new values based on the missing value

Parameters

Name Type Description Default
call Callable Factory to be called on missing key required

datapath(path)

Show source code in kinoml/utils.py
23
24
25
26
27
28
29
30
31
32
def datapath(path: str) -> Path:
    """
    Return absolute path to a file contained in this package's `data`.

    Parameters:
        path: Relative path to file in `data`.
    Returns:
        Absolute path
    """
    return PACKAGE_ROOT / "data" / path

Return absolute path to a file contained in this package's data.

Parameters

Name Type Description Default
path str Relative path to file in data. required

Returns

Type Description
Path Absolute path

grouper(iterable, n, fillvalue=None)

Show source code in kinoml/utils.py
35
36
37
38
39
40
41
42
43
44
45
46
47
def grouper(iterable: Iterable, n: int, fillvalue: Any = None) -> Iterable:
    """
    Given an iterable, consume it in n-sized groups,
    filling it with fillvalue if needed.

    Parameters:
        iterable: list, tuple, str or anything that can be grouped
        n: size of the group
        fillvalue: last group will be padded with this object until
            `len(group)==n`
    """
    args = [iter(iterable)] * n
    return zip_longest(*args, fillvalue=fillvalue)

Given an iterable, consume it in n-sized groups, filling it with fillvalue if needed.

Parameters

Name Type Description Default
iterable Iterable list, tuple, str or anything that can be grouped required
n int size of the group required
fillvalue Any last group will be padded with this object until len(group)==n None

Last update: April 24, 2020