watchful.enricher module

This script provides the abstract Enricher class interface to be inherited in your custom enricher class, where you can then implement your custom data enrichment functions and models within enrich_fn(). Refer to https://github.com/Watchfulio/watchful-py/blob/main/examples/enrichment_intro.ipynb for a tutorial on how to implement your custom enricher class.

class watchful.enricher.Enricher[source]

Bases: object

This is the abstract class that customized enricher classes should inherit, and then implement the abstract methods __init__() and enrich_row().

abstract enrich_fn(row_or_col: Dict[str | None, str | None] | Tuple[str | None, List[str] | None]) List[List[Tuple[List[Tuple[int]] | Dict[str, List[str]] | str | None]]][source]

In this method, we use our variables from self.enrichment_args initialized in __init__() to enrich our data, row by row or column by column. The return value is our enriched row or column. This enrich_fn() method needs to be implemented in your enricher class, and annotated with the attributes.set_enrich_fn_order() to indicate enrichment by your choice of either “row” or “col”.

Parameters:

row_or_col – If this function enriches rows, a dictionary containing string keys as the column names and string values as the cell values, one for each cell of the row; the rows are read using csv.reader on a csv file representing the dataset. If this function enriches columns, a dictionary containing a string key as the column name and a list of string values as the column values.

Returns:

A list of EnrichedCell containing the attributes for each cell, for the entire row or column.

Return type:

List[EnrichedCell]

classmethod is_enricher(possibly_an_enricher: Generic[T]) bool[source]

This is a convenience method used for checking if possibly_an_enricher is indeed of the Enricher class.

Parameters:

possibly_an_enricher (Class) – A class that is possibly of the Enricher class.

Returns:

A boolean indicating if possibly_an_enricher is indeed of the Enricher class.

Return type:

bool

classmethod is_fully_formed_enricher(possibly_an_enricher: Generic[T]) bool[source]

This is a convenience method used for checking if possibly_an_enricher has defined its enrichment order that can be one of ENRICHMENT_ORDERS.

Parameters:

possibly_an_enricher (Class) – A class that is possibly of the Enricher class.

Returns:

A boolean indicating if possibly_an_enricher has defined its enrichment order that can be one of ENRICHMENT_ORDERS.

Return type:

bool

watchful.enricher.set_enrich_fn_order(enrich_fn: Callable | None = None, order: Literal['row', 'col'] = 'row') Callable[source]

This function annotates a data enrichment function with an attribute that indicates the order of the data enrichment. Currently, the allowed orders are “row” and “col”.

Parameters:
  • enrich_fn (Callable) – The data enrichment function, defaults to None.

  • order (str) – The data enrichment order; currently the allowed orders are “row” and “col”, defaults to “row”.

Returns:

The list of enriched cell values in the row.

Return type:

Callable