post_processing_utils
Utilities for post-processing.
Module
Functions
create_postprocessor
def create_postprocessor( config: dict[str, Any],) ‑> Optional[PostProcessor]:
Create a postprocessor from a configuration dictionary.
Arguments
config
: Postprocessor configuration with 'type' and other parameters
Returns An instance of the requested postprocessor or None if there is an error when creating it.
create_postprocessors
def create_postprocessors( postprocessor_configs: Optional[list[dict[str, Any]]] = None,) ‑> list[PostProcessor]:
Create a list of postprocessors from configurations.
Arguments
postprocessor_configs
: Configuration for postprocessors, either: - None (returns an empty list) - A list of dicts, each with 'type' and other parameters
Returns List of PostProcessors.
Classes
ColumnRenamerPostProcessor
class ColumnRenamerPostProcessor(column_mapping: dict[str, str]):
Renames columns in a DataFrame.
Initialize the column renamer.
Arguments
column_mapping
: Mapping from old column names to new column names.
Ancestors
Methods
process
def process(self, predictions: Any) ‑> Any:
Process the predictions by renaming columns.
Arguments
predictions
: The model output to process.
Returns Processed predictions with renamed columns.
CompoundPostProcessor
class CompoundPostProcessor( postprocessing_sequence: list[dict[str, Any]], name: Optional[str] = None,):
Applies multiple postprocessors in sequence.
Initialize the compound postprocessor.
Arguments
postprocessing_sequence
: List of postprocessor configurations to apply in a sequencename
: Name as a string for the for this transformation pipeline. Default to None.
Ancestors
Methods
process
def process(self, predictions: Any) ‑> Any:
Apply all postprocessors in sequence.
JSONFieldRestructuringPostProcessor
class JSONFieldRestructuringPostProcessor( column_patterns: list[str], field_mappings: list[dict[str, str]], keep_original: bool = False,):
Restructures JSON data by moving fields between different levels.
This is done for example to move fields from one json
level to another as for example from
{"key1": {"key2": "value", "key3": "val"}}
to
{"key1": {"key2": "value"}, "key3": "val"}
and vice-versa.
Initialize the JSON field restructurer.
Arguments
column_patterns
: List of regex patterns matching columns to processfield_mappings
: List of mappings, each with: - 'source_path': JSON path to extract (using dot notation, e.g., 'key1.key2' or 'key2') - 'target_path': Path to place the value (dot notation, e.g., ''key1.key2' or 'key2'')keep_original
: Whether to keep the original fields
Ancestors
Methods
process
def process(self, predictions: Any) ‑> Any:
Process predictions by restructuring JSON fields.
JSONKeyRenamerPostProcessor
class JSONKeyRenamerPostProcessor( column_patterns: list[str], key_mappings: list[dict[str, str]], recursive: bool = True,):
Renames keys within JSON data stored in columns.
Initialize the JSON key renamer.
Arguments
column_patterns
: List of regex patterns matching columns to processkey_mappings
: List of mappings, each with: - 'source_key': Original key name - 'target_key': New key namerecursive
: Whether to rename keys recursively throughout nested objects
Ancestors
Methods
process
def process(self, predictions: Any) ‑> Any:
Process predictions by renaming JSON keys.
PostProcessor
class PostProcessor():
Base class that all postprocessors inherit from.
Subclasses
Methods
process
def process( self, predictions: Union[PredictReturnType, pd.DataFrame],) ‑> Union[bitfount.types.PredictReturnType, pandas.core.frame.DataFrame, Any]:
Process the model predictions.
PostprocessorType
class PostprocessorType( value, names=None, *, module=None, qualname=None, type=None, start=1,):
Types of built-in postprocessors.
Variables
- static
COMPOUND
- static
JSON_KEY_RENAME
- static
JSON_RESTRUCTURE
- static
RENAME
- static
STRING_TO_JSON
- static
TRANSFORM
StringToJSONPostProcessor
class StringToJSONPostProcessor(column_patterns: list[str]):
Converts string columns containing JSON data to actual JSON/dict objects.
Initialize the string to JSON converter.
Arguments
column_patterns
: List of regex patterns matching column names to process
Ancestors
Methods
process
def process(self, predictions: Any) ‑> Any:
Process predictions by converting string columns to JSON objects.
TransformationApplierPostProcessor
class TransformationApplierPostProcessor(transformations: list[Transformation]):
Applies transformations from the transformations module.
Initialize the transformation applier.
Arguments
transformations
: List of transformations to apply.
Ancestors
Methods
process
def process(self, predictions: Any) ‑> Any:
Process the predictions using the transformations.
Arguments
predictions
: Model output to process
Returns Processed predictions