Skip to content

filter

Module defining the filter object.

Classes:

Name Description
Filter

Filter class, used to filter a dataset for causal explanation on a subset.

Filter(name: str, fitted_parquet_dataset: FittedParquetDataset, criteria: list[NumericalCriterion | CategoricalCriterion | MultivariateCriterion | TimeseriesBoxCriterion] | None = None, row_indexes: list[int] | None = None) #

Filter class, used to filter a dataset for causal explanation on a subset.

Initialize the filter object.

Parameters:

Name Type Description Default

name #

str

The filter name.

required

fitted_parquet_dataset #

FittedParquetDataset

The dataset to filter will be applied to.

required

criteria #

list[NumericalCriterion | CategoricalCriterion] | None

An optional list of filter criteria to filter by feature.

None

row_indexes #

list[int] | None

An optional list of row indexes to filter by sample.

None.

Methods:

Name Description
add_criterion

Add criterion.

add_criteria

Add many criteria.

apply

Generate/update a remote filter.

__len__

Get filter's result size.

Attributes:

Name Type Description
name
criteria
row_indexes
dataset
id str | None

Get id.

Source code in src/xpdeep/filtering/filter.py
def __init__(
    self,
    name: str,
    fitted_parquet_dataset: FittedParquetDataset,
    criteria: list[NumericalCriterion | CategoricalCriterion | MultivariateCriterion | TimeseriesBoxCriterion]
    | None = None,
    row_indexes: list[int] | None = None,
) -> None:
    """
    Initialize the filter object.

    Parameters
    ----------
    name : str
        The filter name.
    fitted_parquet_dataset : FittedParquetDataset
        The dataset to filter will be applied to.
    criteria : list[NumericalCriterion | CategoricalCriterion] | None
        An optional list of filter criteria to filter by feature.
    row_indexes : list[int] | None, default None.
        An optional list of row indexes to filter by sample.
    """
    self._id: str | None = None
    self.name = name
    self.criteria = criteria if criteria is not None else []
    self.row_indexes = row_indexes
    self.dataset = fitted_parquet_dataset

name = name #

criteria = criteria if criteria is not None else [] #

row_indexes = row_indexes #

dataset = fitted_parquet_dataset #

id: str | None #

Get id.

add_criterion(criterion: NumericalCriterion | CategoricalCriterion) -> None #

Add criterion.

Source code in src/xpdeep/filtering/filter.py
def add_criterion(self, criterion: NumericalCriterion | CategoricalCriterion) -> None:
    """Add criterion."""
    self.criteria.append(criterion)

add_criteria(*args: NumericalCriterion | CategoricalCriterion) -> None #

Add many criteria.

Source code in src/xpdeep/filtering/filter.py
def add_criteria(self, *args: NumericalCriterion | CategoricalCriterion) -> None:
    """Add many criteria."""
    self.criteria += list(args)

apply() -> None #

Generate/update a remote filter.

Source code in src/xpdeep/filtering/filter.py
def apply(self) -> None:
    """Generate/update a remote filter."""
    if self._id is None:
        self._create()
    else:
        self._update()

__len__() -> int #

Get filter's result size.

Source code in src/xpdeep/filtering/filter.py
@initialized_client_verification
@initialized_project_verification
def __len__(self) -> int:
    """Get filter's result size."""
    if self.id is None:
        msg = "This filer is not applied yet. Call `apply` method before computing filter's results size."
        raise ApiError(msg)

    return cast(
        FilterSizeResponseBody,
        get_filter_size.sync(
            project_id=Project.CURRENT.get().model.id, id=self.id, client=ClientFactory.CURRENT.get()()
        ),
    ).size