Skip to content

base

ColumnTransformer

Bases: ABC

A generic column transformer class to prototype all of the transformers applied via the MetaTransformer.

Source code in src/nhssynth/modules/dataloader/transformers/base.py
class ColumnTransformer(ABC):
    """A generic column transformer class to prototype all of the transformers applied via the [`MetaTransformer`][nhssynth.modules.dataloader.metatransformer.MetaTransformer]."""

    def __init__(self) -> None:
        super().__init__()

    @abstractmethod
    def apply(self, data: pd.DataFrame, missingness_column: Optional[pd.Series]) -> None:
        """Apply the transformer to the data."""
        pass

    @abstractmethod
    def revert(self, data: pd.DataFrame) -> None:
        """Revert data to pre-transformer state."""
        pass

apply(data, missingness_column) abstractmethod

Apply the transformer to the data.

Source code in src/nhssynth/modules/dataloader/transformers/base.py
@abstractmethod
def apply(self, data: pd.DataFrame, missingness_column: Optional[pd.Series]) -> None:
    """Apply the transformer to the data."""
    pass

revert(data) abstractmethod

Revert data to pre-transformer state.

Source code in src/nhssynth/modules/dataloader/transformers/base.py
@abstractmethod
def revert(self, data: pd.DataFrame) -> None:
    """Revert data to pre-transformer state."""
    pass

TransformerWrapper

Bases: ABC

A class to facilitate nesting of ColumnTransformers.

Parameters:

Name Type Description Default
wrapped_transformer ColumnTransformer

The ColumnTransformer to wrap.

required
Source code in src/nhssynth/modules/dataloader/transformers/base.py
class TransformerWrapper(ABC):
    """
    A class to facilitate nesting of [`ColumnTransformer`][nhssynth.modules.dataloader.transformers.base.ColumnTransformer]s.

    Args:
        wrapped_transformer: The [`ColumnTransformer`][nhssynth.modules.dataloader.transformers.base.ColumnTransformer] to wrap.
    """

    def __init__(self, wrapped_transformer: ColumnTransformer) -> None:
        super().__init__()
        self._wrapped_transformer: ColumnTransformer = wrapped_transformer

    def apply(self, data: pd.Series, missingness_column: Optional[pd.Series], **kwargs) -> pd.DataFrame:
        """Method for applying the wrapped transformer to the data."""
        return self._wrapped_transformer.apply(data, missingness_column, **kwargs)

    def revert(self, data: pd.Series, **kwargs) -> pd.DataFrame:
        """Method for reverting the passed data via the wrapped transformer."""
        return self._wrapped_transformer.revert(data, **kwargs)

apply(data, missingness_column, **kwargs)

Method for applying the wrapped transformer to the data.

Source code in src/nhssynth/modules/dataloader/transformers/base.py
def apply(self, data: pd.Series, missingness_column: Optional[pd.Series], **kwargs) -> pd.DataFrame:
    """Method for applying the wrapped transformer to the data."""
    return self._wrapped_transformer.apply(data, missingness_column, **kwargs)

revert(data, **kwargs)

Method for reverting the passed data via the wrapped transformer.

Source code in src/nhssynth/modules/dataloader/transformers/base.py
def revert(self, data: pd.Series, **kwargs) -> pd.DataFrame:
    """Method for reverting the passed data via the wrapped transformer."""
    return self._wrapped_transformer.revert(data, **kwargs)