Source code for fl4health.feature_alignment.tabular_type

from __future__ import annotations

from enum import Enum

from flwr.common.typing import Scalar


[docs] class TabularType(str, Enum): NUMERIC = "numeric" BINARY = "binary" ORDINAL = "ordinal" STRING = "string"
[docs] @staticmethod def get_default_fill_value(tabular_type: TabularType | str) -> Scalar: """ Provided the tabular feature type as either a string or enum, this function returns the default value for imputation to be used. Args: tabular_type (TabularType | str): Type of tabular feature to be imputed Raises: ValueError: If the tabular type is unknown this will be thrown. Returns: Scalar: Default imputation value for the specified ``TabularType`` """ if tabular_type is TabularType.NUMERIC: return 0.0 elif tabular_type is TabularType.BINARY: return 0 elif tabular_type is TabularType.STRING: return "N/A" elif tabular_type is TabularType.ORDINAL: return "UNKNOWN" else: raise ValueError("Invalid Tabular Data Type.")