Skip to content

Base Classes

Abstract base classes and core data structures.

BaseTest

BaseTest

Bases: AbobaBase

Base class for AB-tests, providing a structure for fitting and testing data.

Source code in aboba/base/base_test.py
class BaseTest(AbobaBase):
    """
    Base class for AB-tests, providing a structure for fitting and testing data.
    """

    def __init__(self,):
        super().__init__()

    def fit(self, data: DataSource):
        pass

    def test(self, groups: List[pd.DataFrame], artefacts: Optional[Dict] = None) -> TestResult:
        """
        Perform statistical test on the provided groups.

        Args:
            groups (List[pd.DataFrame]): List of DataFrames representing different groups.
            artefacts (Optional[Dict]): Artifacts from preprocessing pipeline. 
                Can contain metadata needed for test calculation (e.g., CUPED original means).

        Returns:
            TestResult: Object containing test results (p-value, effect, etc.)
        """
        raise NotImplemented("test method should be defined by derived AB-tests")

test

test(groups: List[DataFrame], artefacts: Optional[Dict] = None) -> TestResult

Perform statistical test on the provided groups.

PARAMETER DESCRIPTION
groups

List of DataFrames representing different groups.

TYPE: List[DataFrame]

artefacts

Artifacts from preprocessing pipeline. Can contain metadata needed for test calculation (e.g., CUPED original means).

TYPE: Optional[Dict] DEFAULT: None

RETURNS DESCRIPTION
TestResult

Object containing test results (p-value, effect, etc.)

TYPE: TestResult

Source code in aboba/base/base_test.py
def test(self, groups: List[pd.DataFrame], artefacts: Optional[Dict] = None) -> TestResult:
    """
    Perform statistical test on the provided groups.

    Args:
        groups (List[pd.DataFrame]): List of DataFrames representing different groups.
        artefacts (Optional[Dict]): Artifacts from preprocessing pipeline. 
            Can contain metadata needed for test calculation (e.g., CUPED original means).

    Returns:
        TestResult: Object containing test results (p-value, effect, etc.)
    """
    raise NotImplemented("test method should be defined by derived AB-tests")

TestResult

TestResult dataclass

Represents the result of a statistical test, including p-value, effect, effect type, and optional effect interval.

Source code in aboba/base/base_test.py
@dataclasses.dataclass
class TestResult:
    """
    Represents the result of a statistical test, including p-value, effect, effect type,
    and optional effect interval.
    """

    pvalue: float
    effect: Optional[float] = None
    effect_type: Literal["absolute", "relative_test", "relative_control"] = "absolute"
    effect_interval: Optional[Tuple[float, float]] = None    
    extra: dict = dataclasses.field(default_factory=dict)

BaseDataProcessor

BaseDataProcessor

Bases: AbobaBase

Base processor class that is applied at full dataframe

Source code in aboba/base/base_processors.py
class BaseDataProcessor(AbobaBase):
    """

    Base processor class that is applied at full dataframe

    """

    def fit(self, data: pd.DataFrame):
        """
        This called once on **all** available data

        Args:
            data (pd.DataFrame): full data, with all groups
        """
        pass

    def transform(self, data: pd.DataFrame) -> Tuple[pd.DataFrame, Optional[Dict]]:
        """
        Transforms data and returns transformed dataframe.
        Can generate artefacts that can be used later

        Args:
            data (pd.DataFrame): full dataframe to process

        Returns:
            Tuple[pd.DataFrame, Optional[Dict]]: tuple with processed row and artefacts dict
        """

        raise NotImplemented

    def fit_transform(self, data: pd.DataFrame) -> Tuple[pd.DataFrame, Dict]:
        """

        Combination of fit and transform

        Args:
            data (pd.DataFrame): data to fit on and to transform

        Returns:
            Tuple[pd.DataFrame, Dict]: tuple with processed row and artefacts dict
        """
        self.fit(data)
        return self.transform(data)

    def __call__(self, data: pd.DataFrame) -> Tuple[pd.DataFrame, Optional[Dict]]:
        return self.transform(data)

fit

fit(data: DataFrame)

This called once on all available data

PARAMETER DESCRIPTION
data

full data, with all groups

TYPE: DataFrame

Source code in aboba/base/base_processors.py
def fit(self, data: pd.DataFrame):
    """
    This called once on **all** available data

    Args:
        data (pd.DataFrame): full data, with all groups
    """
    pass

transform

transform(data: DataFrame) -> Tuple[pd.DataFrame, Optional[Dict]]

Transforms data and returns transformed dataframe. Can generate artefacts that can be used later

PARAMETER DESCRIPTION
data

full dataframe to process

TYPE: DataFrame

RETURNS DESCRIPTION
Tuple[DataFrame, Optional[Dict]]

Tuple[pd.DataFrame, Optional[Dict]]: tuple with processed row and artefacts dict

Source code in aboba/base/base_processors.py
def transform(self, data: pd.DataFrame) -> Tuple[pd.DataFrame, Optional[Dict]]:
    """
    Transforms data and returns transformed dataframe.
    Can generate artefacts that can be used later

    Args:
        data (pd.DataFrame): full dataframe to process

    Returns:
        Tuple[pd.DataFrame, Optional[Dict]]: tuple with processed row and artefacts dict
    """

    raise NotImplemented

fit_transform

fit_transform(data: DataFrame) -> Tuple[pd.DataFrame, Dict]

Combination of fit and transform

PARAMETER DESCRIPTION
data

data to fit on and to transform

TYPE: DataFrame

RETURNS DESCRIPTION
Tuple[DataFrame, Dict]

Tuple[pd.DataFrame, Dict]: tuple with processed row and artefacts dict

Source code in aboba/base/base_processors.py
def fit_transform(self, data: pd.DataFrame) -> Tuple[pd.DataFrame, Dict]:
    """

    Combination of fit and transform

    Args:
        data (pd.DataFrame): data to fit on and to transform

    Returns:
        Tuple[pd.DataFrame, Dict]: tuple with processed row and artefacts dict
    """
    self.fit(data)
    return self.transform(data)

DataSplitter

DataSplitter module-attribute

DataSplitter = Union[BaseDataSplitter, Callable[[DataFrame, Dict], List[DataFrame]]]

EffectModifier

EffectModifier module-attribute

EffectModifier = Union[BaseEffectModifier, Callable[[List[DataFrame]], List[DataFrame]]]

BaseDataSource

BaseDataSource

Bases: AbobaBase

Defines source of data

Source code in aboba/base/base_data_source.py
class BaseDataSource(AbobaBase):
    """

    Defines source of data

    """

    def get(self) -> pd.DataFrame:
        """

        Returns data

        """
        raise NotImplemented

    def is_generated(self) -> bool:
        """

        Tells if data is generated.
        If it is not generated, then data processing can be cached

        """
        raise NotImplemented

    def __call__(self) -> pd.DataFrame:
        return self.get()

get

get() -> pd.DataFrame

Returns data

Source code in aboba/base/base_data_source.py
def get(self) -> pd.DataFrame:
    """

    Returns data

    """
    raise NotImplemented

is_generated

is_generated() -> bool

Tells if data is generated. If it is not generated, then data processing can be cached

Source code in aboba/base/base_data_source.py
def is_generated(self) -> bool:
    """

    Tells if data is generated.
    If it is not generated, then data processing can be cached

    """
    raise NotImplemented