fl4health.feature_alignment.handle_types module¶
Largely taken from https://github.com/VectorInstitute/cyclops.
- convertible_to_type(series, type, unique=None, raise_error=False)[source]¶
Check whether a feature can be converted to some type.
- Parameters:
series (pd.Series) – Feature data.
type (FeatureType) – Feature type name to check for conversion.
unique (np.ndarray | None, optional) – _description_. Defaults to None.
raise_error (bool, optional) – Unique values which can be optionally specified. Defaults to False.
- Raises:
ValueError – Supported type has no corresponding datatype
ValueError – Cannot convert series to the provided type and
raise_erroris true.
- Returns:
Whether the feature can be converted.
- Return type:
- get_unique(values, unique=None)[source]¶
Get the unique values of pandas series.
The utility of this function comes from checking whether the unique values have already been calculated. This function assumes that if the unique values are passed, they are correct.
- Parameters:
values (np.ndarray | pd.Series) – Values for which to get the unique values.
unique (np.ndarray | None, optional) – Unique values which can be optionally specified. Defaults to None.
- Returns:
The unique values.
- Return type:
np.ndarray
- infer_types(data, features)[source]¶
Infer intended feature types and perform the relevant conversions.
- to_dtype(series, type)[source]¶
Set the series datatype according to the feature type.
- Parameters:
series (pd.Series) – Feature data.
type (FeatureType) – Feature type name.
- Returns:
The feature with the corresponding datatype.
- Return type:
pd.Series
- valid_feature_type(type, raise_error=True)[source]¶
Check whether a feature type name is valid.
- Parameters:
type (FeatureType) – Feature type name.
raise_error (bool, optional) – Whether to raise an error is the type is invalid. Defaults to True.
- Raises:
ValueError – Raise when the type is invalid and
raise_erroris True- Returns:
Whether the type is valid.
- Return type: