visions.utils.coercion.test_utils

A selection of testing utilities for visions.

visions.utils.coercion.test_utils.coercion_equality_test(method)[source]

A coercion equality test generator

Creates a coercion test based on a provided coercion method which also enforces equality constraints on the output. This is useful when you want to change the data type of a series without necessarily changing the data, for example, when converting an integer to a float.

Parameters

method (Callable) – A method coercing a Series to another type.

Return type

Callable

Returns

Whether the coercion failed or was successful.

visions.utils.coercion.test_utils.coercion_map(mapping)[source]

Maps a series given a mapping

Parameters

mapping (Union[List[Dict], Dict]) – a dict to map, or a list of dicts.

Return type

Callable

Returns

A callable that maps the series.

visions.utils.coercion.test_utils.coercion_map_test(mapping)[source]

Create a testing function for a single mapping or a list of mappings.

Parameters

mapping (Union[List[Dict], Dict]) – A dict with a mapping or a list of dicts

Return type

Callable

Returns

Callable that checks if a series consists of the mappable values

Examples

>>> coercion_map_test({"Yes": True, "No": False})
>>> coercion_map_test(
>>>     [
>>>         {"Yes": True, "No": False},
>>>         {"Y": True, "N": False},
>>>     ]
>>> )
visions.utils.coercion.test_utils.coercion_test(method, extra_errors=None)[source]

A coercion test generator

Creates a coercion test based on a provided coercion method.

Parameters

method (Callable) – A method coercing a Series to another type.

Return type

Callable

Returns

Whether the coercion failed or was successful.

visions.utils.coercion.test_utils.option_coercion_evaluator(method, extra_errors=None)[source]

A coercion test evaluator

Evaluates a coercion method and optionally returns the coerced series.

Parameters

method (Callable) – A method coercing a Series to another Series.

Return type

Callable

Returns

The coerced series if the coercion succeeds otherwise None.