Skip to content

FunctionalTableTransformer

Bases: TableTransformer

Wraps a callable so that it conforms to the TableTransformer interface.

Parameters:

Name Type Description Default
transformer Callable[[Table], Table]

A callable that receives a table and returns a table.

required

Methods:

Name Description
fit

Note: For FunctionalTableTransformer this is a no-OP.

fit_and_transform

Note: For the FunctionalTableTransformer this is the same as transform().

transform

Apply the callable to a table.

Attributes:

Name Type Description
is_fitted bool

FunctionalTableTransformer is always considered to be fitted.

Source code in src/safeds/data/tabular/transformation/_functional_table_transformer.py
class FunctionalTableTransformer(TableTransformer):
    """
    Wraps a callable so that it conforms to the TableTransformer interface.

    Parameters
    ----------
    transformer:
        A callable that receives a table and returns a table.
    """

    # ------------------------------------------------------------------------------------------------------------------
    # Dunder methods
    # ------------------------------------------------------------------------------------------------------------------

    def __init__(
        self,
        transformer: Callable[[Table], Table],
    ) -> None:
        super().__init__(None)
        self._transformer = transformer

    def __hash__(self) -> int:
        return _structural_hash(
            super().__hash__(),
            self._transformer,
        )

    # ------------------------------------------------------------------------------------------------------------------
    # Properties
    # ------------------------------------------------------------------------------------------------------------------

    @property
    def is_fitted(self) -> bool:
        """FunctionalTableTransformer is always considered to be fitted."""
        return True

    # ------------------------------------------------------------------------------------------------------------------
    # Learning and transformation
    # ------------------------------------------------------------------------------------------------------------------

    def fit(self, table: Table) -> FunctionalTableTransformer:  # noqa: ARG002
        """
        **Note:** For FunctionalTableTransformer this is a no-OP.

        Parameters
        ----------
        table:
            Required only to be consistent with other transformers.

        Returns
        -------
        fitted_transformer:
            Returns self, because this transformer is always fitted.
        """
        return self

    def transform(self, table: Table) -> Table:
        """
        Apply the callable to a table.

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

        Parameters
        ----------
        table:
            The table on which the callable is executed.

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

        Raises
        ------
        Exception:
            Raised when the wrapped callable encounters an error.
        """
        return self._transformer(table)

    def fit_and_transform(self, table: Table) -> tuple[FunctionalTableTransformer, Table]:
        """
        **Note:** For the FunctionalTableTransformer this is the same as transform().

        Parameters
        ----------
        table:
            The table on which the callable is to be executed.

        Returns
        -------
        fitted_transformer:
            Return self because the transformer is always fitted.
        transformed_table:
            The transformed table.
        """
        fitted_transformer = self
        transformed_table = self.transform(table)
        return fitted_transformer, transformed_table

is_fitted

FunctionalTableTransformer is always considered to be fitted.

fit

Note: For FunctionalTableTransformer this is a no-OP.

Parameters:

Name Type Description Default
table Table

Required only to be consistent with other transformers.

required

Returns:

Name Type Description
fitted_transformer FunctionalTableTransformer

Returns self, because this transformer is always fitted.

Source code in src/safeds/data/tabular/transformation/_functional_table_transformer.py
def fit(self, table: Table) -> FunctionalTableTransformer:  # noqa: ARG002
    """
    **Note:** For FunctionalTableTransformer this is a no-OP.

    Parameters
    ----------
    table:
        Required only to be consistent with other transformers.

    Returns
    -------
    fitted_transformer:
        Returns self, because this transformer is always fitted.
    """
    return self

fit_and_transform

Note: For the FunctionalTableTransformer this is the same as transform().

Parameters:

Name Type Description Default
table Table

The table on which the callable is to be executed.

required

Returns:

Name Type Description
fitted_transformer FunctionalTableTransformer

Return self because the transformer is always fitted.

transformed_table Table

The transformed table.

Source code in src/safeds/data/tabular/transformation/_functional_table_transformer.py
def fit_and_transform(self, table: Table) -> tuple[FunctionalTableTransformer, Table]:
    """
    **Note:** For the FunctionalTableTransformer this is the same as transform().

    Parameters
    ----------
    table:
        The table on which the callable is to be executed.

    Returns
    -------
    fitted_transformer:
        Return self because the transformer is always fitted.
    transformed_table:
        The transformed table.
    """
    fitted_transformer = self
    transformed_table = self.transform(table)
    return fitted_transformer, transformed_table

transform

Apply the callable to a table.

Note: The given table is not modified.

Parameters:

Name Type Description Default
table Table

The table on which the callable is executed.

required

Returns:

Name Type Description
transformed_table Table

The transformed table.

Raises:

Type Description
Exception:

Raised when the wrapped callable encounters an error.

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

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

    Parameters
    ----------
    table:
        The table on which the callable is executed.

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

    Raises
    ------
    Exception:
        Raised when the wrapped callable encounters an error.
    """
    return self._transformer(table)