Skip to content

Filtering - API Reference

warprec.data.filtering.Filter

Bases: ABC

Abstract definition of a filter. Filters are used to process datasets by applying specific conditions or transformations to the data.

Parameters:

Name Type Description Default
user_id_label str

Column name for user IDs.

'user_id'
item_id_label str

Column name for item IDs.

'item_id'
rating_label str

Column name for ratings.

'rating'
timestamp_label str

Column name for timestamps.

'timestamp'
**kwargs Any

Additional keyword arguments.

{}
Source code in warprec/data/filtering.py
class Filter(ABC):
    """Abstract definition of a filter.
    Filters are used to process datasets by applying specific conditions
    or transformations to the data.

    Args:
        user_id_label (str): Column name for user IDs.
        item_id_label (str): Column name for item IDs.
        rating_label (str): Column name for ratings.
        timestamp_label (str): Column name for timestamps.
        **kwargs (Any): Additional keyword arguments.
    """

    def __init__(
        self,
        user_id_label: str = "user_id",
        item_id_label: str = "item_id",
        rating_label: str = "rating",
        timestamp_label: str = "timestamp",
        **kwargs: Any,
    ):
        self.user_label = user_id_label
        self.item_label = item_id_label
        self.rating_label = rating_label
        self.timestamp_label = timestamp_label

    def __call__(self, dataset: DataFrame[Any]) -> DataFrame[Any]:
        """Apply the filter to the dataset."""
        raise NotImplementedError("Subclasses should implement this method.")

__call__(dataset)

Apply the filter to the dataset.

Source code in warprec/data/filtering.py
def __call__(self, dataset: DataFrame[Any]) -> DataFrame[Any]:
    """Apply the filter to the dataset."""
    raise NotImplementedError("Subclasses should implement this method.")