Operator Examples

This section provides examples of some common operators and parameters to build extensions.

Using ENUMS

class Scaler(Enum):
    """Supported normalization methods."""
    MAX_ABSOLUTE = MaxAbsScaler
    MIN_MAX = MinMaxScaler
    STANDARD = StandardScaler

def check_enum(input1: Scaler) -> DataFrame:
    """This Operator checks if the the given value is an enum

    Args:
        input1 (Scaler): any enum value from the user

    Returns:
        DataFrame: input to studio O/P - dataframe with true if enum is presented as the input
    """
    return DataFrame([isinstance(input1, Scaler)])

Multiple Datatable Input

def multiple_input(input1: DataFrame, input2: DataFrame, input3: DataFrame) -> DataFrame:
    """This operator accepts multiple inputs and combines them into one dataframe

    Returns:
        DataFrame: combined dataframe
    """
    return pd.concat([input1, input2, input3], axis=1)

Multiple Outputs

def multiple_output(data: DataFrame) -> tuple[DataFrame, DataFrame]:
    """This Operator splits the given input into multiple outputs by splitting its rows randomly

    Args:
        data (DataFrame): Dataframe to be split

    Returns:
        tuple[DataFrame,DataFrame]: splits the given data rows randomly
    """
    len = data.shape[0]
    output1 = data.iloc[:, :len]
    output2 = data.iloc[:, len:]
    return (output1, output2)

Output Collection

def collection_output(data: DataFrame, n_parts: int = 2) -> list[DataFrame]:
    """This Operator splits the given input into multiple outputs by splitting its rows

    Args:
        data (DataFrame): Dataframe to be split
        n_parts (int): number of parts to split the data into

    Returns:
        list[DataFrame]: splits the given data rows
    """
    len = data.shape[0]
    parts = []
    for i in range(n_parts):
        parts.append(data.iloc[i * len // n_parts : (i + 1) * len // n_parts, :])
    return parts

Logging

Logging in Python Extensions is managed by Python's standard logging interface. The default configuration is sufficient for optimal operation. Additional configuration changes are neither necessary nor advised, as they may lead to unintended consequences.

import logging

def logger_operator(message: str) -> None:
    logging.info(message)