Transforms

A Transform provides the ability to transform the tables supplied by a Source. Given a pandas DataFrame it applies some transformation and returns another DataFrame.

class lumen.transforms.Transform(**params)

A Transform provides the ability to transform a table supplied by a Source.

apply(table)

Given a table transform it in some way and return it.

Parameters

table (DataFrame) – The queried table as a DataFrame.

Returns

A DataFrame containing the transformed data.

Return type

DataFrame

classmethod from_spec(spec)

Resolves a Transform specification.

Parameters

spec (dict) – Specification declared as a dictionary of parameter values.

Returns

Return type

The resolved Transform object.

Transform types

class lumen.transforms.Aggregate(**params)

Aggregate one or more columns or indexes, see pandas.DataFrame.groupby.

df.groupby(<by>)[<columns>].<method>()[.reset_index()]

by = param.ClassSelector(readonly=False)

Columns or indexes to group by.

columns = param.List(readonly=False)

Columns to aggregate.

with_index = param.Boolean(readonly=False)

Whether to make the groupby columns indexes.

method = param.String(readonly=False)

Name of aggregation method.

kwargs = param.Dict(readonly=False)

Keyword arguments to the aggregation method.

class lumen.transforms.Columns(**params)

Selects a subset of columns.

df[<columns>]

columns = param.List(readonly=False)

The subset of columns to select.

class lumen.transforms.HistoryTransform(**params)

The HistoryTransform accumulates a history of the queried data in a buffer up to the supplied length and (optionally) adds a date_column to the data.

date_column = param.String(readonly=False)

If defined adds a date column with the supplied name.

length = param.Integer(readonly=False)

Accumulates a history of data.

class lumen.transforms.Query(**params)

Applies the pandas.DataFrame.query method.

df.query(<query>)

query = param.String(readonly=False)

The query to apply to the table.

class lumen.transforms.Sort(**params)

Sort on one or more columns, see pandas.DataFrame.sort_values.

df.sort_values(<by>, ascending=<ascending>)

by = param.ClassSelector(readonly=False)

Columns or indexes to sort by.

ascending = param.ClassSelector(readonly=False)

Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by.

class lumen.transforms.Stack(**params)

Stacks the declared level, see pandas.DataFrame.stack.

df.stack(<level>)

level = param.ClassSelector(readonly=False)

The indexes to stack.

class lumen.transforms.Unstack(**params)

Unstacks the declared level(s), see pandas.DataFrame.stack.

df.unstack(<level>)

level = param.ClassSelector(readonly=False)

The indexes to unstack.