packflow.utils.normalize package
Submodules
packflow.utils.normalize.base module
- class packflow.utils.normalize.base.TypeConversionHandler[source]
Bases:
ABC- abstract convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- abstract is_type(obj)[source]
Check if the object is the proper type for the converter
- Return type:
bool
- abstract property package_name: str
The name of the required package to attempt to import
packflow.utils.normalize.handlers module
- class packflow.utils.normalize.handlers.NumpyTypeHandler[source]
Bases:
TypeConversionHandler- convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- property package_name: str
The name of the required package to attempt to import
- class packflow.utils.normalize.handlers.PandasDataFrameHandler[source]
Bases:
TypeConversionHandler- convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- property package_name: str
The name of the required package to attempt to import
- class packflow.utils.normalize.handlers.PandasSeriesHandler[source]
Bases:
TypeConversionHandler- convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- property package_name: str
The name of the required package to attempt to import
- class packflow.utils.normalize.handlers.PillowImageHandler[source]
Bases:
TypeConversionHandler- convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- property package_name: str
The name of the required package to attempt to import
- class packflow.utils.normalize.handlers.TorchScalarHandler[source]
Bases:
TypeConversionHandler- convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- property package_name: str
The name of the required package to attempt to import
- class packflow.utils.normalize.handlers.TorchTensorHandler[source]
Bases:
TypeConversionHandler- convert(obj)[source]
Logic to convert the type to a native, json-serializable Python type.
- Parameters:
obj (Any) – The object to convert
- Returns:
Any python native type that is JSON serializable
- Return type:
object
- property package_name: str
The name of the required package to attempt to import
packflow.utils.normalize.normalize module
- packflow.utils.normalize.normalize.ensure_native_types(obj)[source]
Converts any non-native data types to ensure JSON serialization is possible.
- Parameters:
obj (Any) – the object to convert to a native data type
- Return type:
A scalar or object with all-native Python data types
- packflow.utils.normalize.normalize.ensure_valid_output(output, parent_key='output')[source]
Coerces outputs to native Python types and correct formats.
- Parameters:
output (Iterable[Any]) – Model outputs to be cleaned
parent_key (str) – Default ‘output’. Used when the output is not a dictionary type. Ex: Output of [0, 1] would be wrapped to {f’{parent_key}’: [0, 1]}
- Return type:
List[Dict[str, Any]]