yggdrasil.communication.transforms package¶
Submodules¶
yggdrasil.communication.transforms.ArrayTransform module¶
- class yggdrasil.communication.transforms.ArrayTransform.ArrayTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for consolidating values into an array.
- classmethod check_array_items(items, order=None, items_as_columns=None)[source]¶
Check that items are valid types for array columns.
- Parameters
items (list) – Type definitions for elements.
order (list, optional) – Order that properties should be compared in for object schemas. Defaults to None and will be set based on the order of the keys in the first element (non-deterministic for Python 2.7).
items_as_columns (bool, optional) – If True, the items will be parsed under the assumption that each item contains the schema describing a column, possible as an array of elements. If None and the initial check fails when assuming items are rows, columns will be tried. Defaults to None.
- Raises
AssertionError – If the items are not valid.
- classmethod check_element(items, subtype=False)[source]¶
Check that all elements in set of elements (e.g. row or column) are consistent.
- Parameters
- Raises
AssertionError – If any elements are not consistent.
- classmethod check_summary(a, aidx, b, bidx)[source]¶
Determine if two summary structures are equivalent, printing differences in the error if they are not.
- Parameters
- Raises
AssertionError – If a and b are not equivalent.
- classmethod get_summary(x, subtype=False)[source]¶
Get subset of information summarizing an array element that can be used for comparison with other elements in the same row/column.
- Parameters
- Returns
Information about the array element.
- Return type
- Raises
AssertionError – If x is not a valid type defintion for an array element.
- classmethod get_testing_options()[source]¶
Get testing options for the transform class.
- Returns
- Multiple dictionaries of keywords and messages before/after
pairs that will result from the transform created by the provided keywords.
- Return type
- classmethod transform_array_items(items, order=None)[source]¶
Transform elements in an array.
- Parameters
items (list) – Set of type definitions for array rows or columns that should be transformed into type definitions for a set of array columns.
order (list, optional) – Order in which properties should be added as columns for object type defintions. Defaults to None if not provided and the first object element will be used to get the order (non-deterministic on Python 2.7).
- Returns
Transformed array column type definitions.
- Return type
- transform_datatype(datatype)[source]¶
Determine the datatype that will result from applying the transform to the supplied datatype.
- validate_datatype(datatype)[source]¶
Assert that the provided datatype is valid for this transformation.
- Parameters
datatype (dict) – Datatype to validate.
- Raises
AssertionError – If the datatype is not valid.
yggdrasil.communication.transforms.DirectTransform module¶
- class yggdrasil.communication.transforms.DirectTransform.DirectTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Base class for message transforms.
yggdrasil.communication.transforms.FilterTransform module¶
- class yggdrasil.communication.transforms.FilterTransform.FilterTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for applying a filter.
yggdrasil.communication.transforms.FunctionTransform module¶
- class yggdrasil.communication.transforms.FunctionTransform.FunctionTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for transforming messages based on a provided Python function.
- Parameters
function (func) – The handle for a callable Python object (e.g. function) that should be used to transform messages or a string of the form “<function file>:<function name>” identifying a function where “<function file>” is the module or Python file containing the function and “<function name>” is the name of the function. The function should take the message as input and return the transformed message.
yggdrasil.communication.transforms.IterateTransform module¶
- class yggdrasil.communication.transforms.IterateTransform.IterateTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for iterating over message elements.
- classmethod get_testing_options()[source]¶
Get testing options for the transform class.
- Returns
- Multiple dictionaries of keywords and messages before/after
pairs that will result from the transform created by the provided keywords.
- Return type
- transform_datatype(datatype)[source]¶
Determine the datatype that will result from applying the transform to the supplied datatype.
- validate_datatype(datatype)[source]¶
Assert that the provided datatype is valid for this transformation.
- Parameters
datatype (dict) – Datatype to validate.
- Raises
AssertionError – If the datatype is not valid.
yggdrasil.communication.transforms.MapFieldsTransform module¶
- class yggdrasil.communication.transforms.MapFieldsTransform.MapFieldsTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for mapping a subset of the original fields in an object to a different set of fields. Fields that don’t exist in the map are preserved unchanged.
- Parameters
map (dict) – A mapping from original field name to new field names.
yggdrasil.communication.transforms.PandasTransform module¶
- class yggdrasil.communication.transforms.PandasTransform.PandasTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.ArrayTransform.ArrayTransform
Class for consolidating values into a Pandas data frame.
yggdrasil.communication.transforms.SelectFieldsTransform module¶
- class yggdrasil.communication.transforms.SelectFieldsTransform.SelectFieldsTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for selecting a subset of the original fields in an object.
- Parameters
selected (list) – A list of fields that should be selected.
original_order (list, optional) – The original order of fields that should be used for selecting from lists/tuples.
single_as_scalar (bool, optional) – If True and only a single field is selected, the transformed messages will be scalars rather than arrays with single elements. Defaults to False.
- classmethod get_testing_options()[source]¶
Get testing options for the transform class.
- Returns
- Multiple dictionaries of keywords and messages before/after
pairs that will result from the transform created by the provided keywords.
- Return type
- transform_datatype(datatype)[source]¶
Determine the datatype that will result from applying the transform to the supplied datatype.
- validate_datatype(datatype)[source]¶
Assert that the provided datatype is valid for this transformation.
- Parameters
datatype (dict) – Datatype to validate.
- Raises
AssertionError – If the datatype is not valid.
yggdrasil.communication.transforms.StatementTransform module¶
- class yggdrasil.communication.transforms.StatementTransform.StatementTransform(*args, **kwargs)[source]¶
Bases:
yggdrasil.communication.transforms.TransformBase.TransformBase
Class for transforming messages based on a provided statement using Python syntax.
- Parameters
statement (str) – Python statement in terms of the message as represented by the string “%x%” that should evaluate to the transformed message. The statement should only use a limited set of builtins and the math library (See yggdrasil.tools.safe_eval). If more complex relationships are required, use the FunctionTransform class.
yggdrasil.communication.transforms.TransformBase module¶
- class yggdrasil.communication.transforms.TransformBase.TransformBase(*args, **kwargs)[source]¶
Bases:
yggdrasil.components.ComponentBase
Base class for message transforms.
- Parameters
original_datatype (dict, optional) – Datatype associated with expected messages. Defaults to None.
- __call__(x, no_copy=False, no_init=False)[source]¶
Call transform on the provided message.
- Parameters
- Returns
The transformed message.
- Return type
- transform_datatype(datatype)[source]¶
Determine the datatype that will result from applying the transform to the supplied datatype.
- validate_datatype(datatype)[source]¶
Assert that the provided datatype is valid for this transformation.
- Parameters
datatype (dict) – Datatype to validate.
- Raises
AssertionError – If the datatype is not valid.