Skip to content

InvertibleTableTransformer

Bases: TableTransformer, ABC

A TableTransformer that can also undo the learned transformation after it has been applied.

Source code in src/safeds/data/tabular/transformation/_invertible_table_transformer.py
class InvertibleTableTransformer(TableTransformer, ABC):
    """A `TableTransformer` that can also undo the learned transformation after it has been applied."""

    @abstractmethod
    def inverse_transform(self, transformed_table: Table) -> Table:
        """
        Undo the learned transformation as well as possible.

        Column order and types may differ from the original table. Likewise, some values might not be restored.

        **Note:** The given table is not modified.

        Parameters
        ----------
        transformed_table:
            The table to be transformed back to the original version.

        Returns
        -------
        original_table:
            The original table.

        Raises
        ------
        TransformerNotFittedError
            If the transformer has not been fitted yet.
        """

is_fitted: bool

Whether the transformer is fitted.

fit

Learn a transformation for a set of columns in a table.

Note: This transformer is not modified.

Parameters:

Name Type Description Default
table Table

The table used to fit the transformer.

required

Returns:

Name Type Description
fitted_transformer Self

The fitted transformer.

Source code in src/safeds/data/tabular/transformation/_table_transformer.py
@abstractmethod
def fit(self, table: Table) -> Self:
    """
    Learn a transformation for a set of columns in a table.

    **Note:** This transformer is not modified.

    Parameters
    ----------
    table:
        The table used to fit the transformer.

    Returns
    -------
    fitted_transformer:
        The fitted transformer.
    """

fit_and_transform

Learn a transformation for a set of columns in a table and apply the learned transformation to the same table.

Note: Neither this transformer nor the given table are modified.

Parameters:

Name Type Description Default
table Table

The table used to fit the transformer. The transformer is then applied to this table.

required

Returns:

Name Type Description
fitted_transformer Self

The fitted transformer.

transformed_table Table

The transformed table.

Source code in src/safeds/data/tabular/transformation/_table_transformer.py
def fit_and_transform(self, table: Table) -> tuple[Self, Table]:
    """
    Learn a transformation for a set of columns in a table and apply the learned transformation to the same table.

    **Note:** Neither this transformer nor the given table are modified.

    Parameters
    ----------
    table:
        The table used to fit the transformer. The transformer is then applied to this table.

    Returns
    -------
    fitted_transformer:
        The fitted transformer.
    transformed_table:
        The transformed table.
    """
    fitted_transformer = self.fit(table)
    transformed_table = fitted_transformer.transform(table)
    return fitted_transformer, transformed_table

inverse_transform

Undo the learned transformation as well as possible.

Column order and types may differ from the original table. Likewise, some values might not be restored.

Note: The given table is not modified.

Parameters:

Name Type Description Default
transformed_table Table

The table to be transformed back to the original version.

required

Returns:

Name Type Description
original_table Table

The original table.

Raises:

Type Description
TransformerNotFittedError

If the transformer has not been fitted yet.

Source code in src/safeds/data/tabular/transformation/_invertible_table_transformer.py
@abstractmethod
def inverse_transform(self, transformed_table: Table) -> Table:
    """
    Undo the learned transformation as well as possible.

    Column order and types may differ from the original table. Likewise, some values might not be restored.

    **Note:** The given table is not modified.

    Parameters
    ----------
    transformed_table:
        The table to be transformed back to the original version.

    Returns
    -------
    original_table:
        The original table.

    Raises
    ------
    TransformerNotFittedError
        If the transformer has not been fitted yet.
    """

transform

Apply the learned transformation to a table.

Note: The given table is not modified.

Parameters:

Name Type Description Default
table Table

The table to which the learned transformation is applied.

required

Returns:

Name Type Description
transformed_table Table

The transformed table.

Raises:

Type Description
TransformerNotFittedError

If the transformer has not been fitted yet.

Source code in src/safeds/data/tabular/transformation/_table_transformer.py
@abstractmethod
def transform(self, table: Table) -> Table:
    """
    Apply the learned transformation to a table.

    **Note:** The given table is not modified.

    Parameters
    ----------
    table:
        The table to which the learned transformation is applied.

    Returns
    -------
    transformed_table:
        The transformed table.

    Raises
    ------
    TransformerNotFittedError
        If the transformer has not been fitted yet.
    """