Ejemplo n.º 1
0
"""Collection of signatures used throughout the package."""

from .converters import Column, Columns, to_dataframe, init_cols
from autosig import Signature, param
from functools import partial

recipe = Signature(
    data=param(
        default=None,
        converter=to_dataframe,
        position=0,
        docstring="""`altair.Data` or `pandas.DataFrame` or csv or json file URL
    The data from which the statistical graphics is being generated""",
    ),
    height=param(
        default=600,
        converter=int,
        position=-2,
        docstring="""`int`
    The height of the chart""",
    ),
    width=param(
        default=800,
        converter=int,
        position=-1,
        docstring="""`int`
    The width of the chart""",
    ),
).set_late_init(init_cols)

column = partial(param, converter=Column)
Ejemplo n.º 2
0
"""Smoother graph."""
from .signatures import bivariate_recipe
import altair as alt
from autosig import autosig, param, Signature


@autosig(bivariate_recipe + Signature(
    window=param(
        default=None,
        position=3,
        docstring="""int
The size of the smoothing window""",
    ),
    interquartile_area=param(
        default=True,
        position=4,
        docstring="""interquartile_area: bool
Whether to plot the IRQ as an area""",
    ),
))
def smoother(data,
             x=0,
             y=1,
             window=None,
             interquartile_area=True,
             height=300,
             width=400):
    """Generate a smooth line plot with optional IRQ shading area."""
    window = data.shape[0] // 4 if window is None else int(window)
    _data = data.sort_values(by=x)
    _data["x"] = _data["x"].rolling(window).median()
Ejemplo n.º 3
0
"""Autocorrelation plot."""
from .signatures import univariate_recipe
import altair as alt
from autosig import autosig, Signature, param
import numpy as np
import pandas as pd


@autosig(univariate_recipe + Signature(max_lag=param(
    default=None,
    position=2,
    docstring="""int
    Maximum lag to show in the plot, defaults to number of rows in data""",
)))
def autocorrelation(data, column=0, max_lag=None, height=300, width=400):
    """Generate an autocorrelation plot."""
    max_lag = data.shape[0] - 1 if max_lag is None else int(max_lag)
    lags = np.arange(0, max_lag + 1)
    _data = pd.DataFrame(
        dict(Lag=lags,
             Autocorrelation=[data[column].autocorr(lag=lag) for lag in lags]))
    return (alt.Chart(_data, height=height, width=width).mark_bar().encode(
        x="Lag:O", y="Autocorrelation" + ":Q"))
Ejemplo n.º 4
0
 def fun(a=param(validator=int)):
     pass
Ejemplo n.º 5
0
 class C:
     @Signature(a=param(converter=int))
     def method(self, a):
         return a
Ejemplo n.º 6
0
from functools import partial, wraps
from loguru import logger
from os import fork, wait, _exit, getpid
from sys import stderr, settrace, setprofile, gettrace, getprofile

try:
    logger.remove(0)
except ValueError:
    logger.warning("can't clean up logger handlers", logger)
    pass
logger.add(stderr, level="DEBUG")
top_level = True

checkpoint_sig = Signature(retries=param(
    default=1,
    converter=int,
    docstring="""int
Max # of times checkpoint can be reused""",
))

times = partial(
    param,
    converter=int,
    validator=int,
    docstring="Number of checkpoints to rewind back to, up to 254.",
)
rewind_sig = Signature(times=times(default=1))

checkpoint_code_to_name = bidict()


@logger.catch
Ejemplo n.º 7
0
"""Scatterplots."""
from .common import choose_kwargs, hue_scale_dark, hue_scale_light
from .signatures import bivariate_recipe, multivariate_recipe, color, tooltip
import altair as alt
from autosig import autosig, Signature, param
from numbers import Number

scatterplot_sig = Signature(
    color=color(default=None, position=3),
    opacity=param(
        default=1,
        position=4,
        converter=float,
        docstring="""`float`
A constant value for the opacity of the mark""",
    ),
    tooltip=tooltip(default=None, position=5),
)


@autosig(bivariate_recipe + scatterplot_sig)
def scatterplot(data=None,
                x=0,
                y=1,
                color=None,
                opacity=1,
                tooltip=None,
                height=600,
                width=800):
    """Generate a scatterplot."""
    if color is not None:
Ejemplo n.º 8
0
    """

    auto = None  # no, must not pass anything
    true = True
    false = False
    normalize = "normalize"


@autosig(
    bivariate_recipe
    + Signature(
        color=color(default=None, position=3),
        stack=param(
            default=StackType.auto,
            position=4,
            converter=StackType,
            docstring="""StackType
            One of `StackType.auto` (automatic selection), `StackType.true` (force), `StackType.false` (no stacking) and `StackType.normalize` (for normalized stacked)""",
        ),
    )
)
def areaplot(
    data=None, x=0, y=1, color=None, stack=StackType.auto, height=600, width=800
):
    """Generate an areaplot."""
    warn_not_distinct(data, x, color)
    if stack is not StackType.auto:
        y = alt.Y(y, stack=stack.value)
    opt_args = choose_kwargs(locals(), ["color"])
    return (
        alt.Chart(data=data, height=height, width=width)
Ejemplo n.º 9
0
"""Collection of signatures used throughout the package."""

from .common import to_dataframe, to_column, to_columns
from autosig import Signature, param
from functools import partial

recipe = Signature(
    data=param(
        converter=to_dataframe,
        position=0,
        docstring="""`altair.Data` or `pandas.DataFrame` or csv or json file URL
    The data from which the statistical graphics is being generated""",
    ),
    height=param(
        default=300,
        converter=int,
        position=-2,
        docstring="""`int`
    The height of the chart""",
    ),
    width=param(
        default=400,
        converter=int,
        position=-1,
        docstring="""`int`
    The height of the chart""",
    ),
)

column = partial(param, validator=to_column)
Ejemplo n.º 10
0
    return data, n * 4 // 3, n * 3 // 4


@autosig(bivariate_recipe + Signature(
    color=color(default=2, position=3),
    opacity=column(
        default=None,
        position=4,
        docstring="""`str`
The column containing the data that determines opacity of the mark""",
    ),
    aggregate=param(
        default="average",
        converter=str,
        position=5,
        docstring="""`str`
    The aggregation function to set the color of each mark, see https://altair-viz.github.io/user_guide/encoding.html#encoding-aggregates for available options""",
    ),
))
def heatmap(
    data=None,
    x=0,
    y=1,
    color=2,
    opacity=None,
    aggregate="average",
    height=600,
    width=800,
):
    """Generate a heatmap."""