Skip to content

Features Storage

Different classes to optimize RAM usage with repeated features over time.

ArrayStorage

Bases: Storage

Function to store features with ids as NumPy Array.

Source code in choice_learn/data/storage.py
class ArrayStorage(Storage):
    """Function to store features with ids as NumPy Array."""

    def __init__(self, values=None, values_names=None, name=None):
        """Build the store.

        Parameters
        ----------
        values : array_like
            list of values of features to store
        values_names : array_like
            Iterable of str indicating the name of the features. Must be same length as values.
        name: string, optional
            name of the features store
        """
        if isinstance(values, list):
            storage = np.array(values)
        elif not isinstance(values, np.ndarray):
            raise ValueError("ArrayStorage Values must be a list or a numpy array")

        # self.storage = storage
        self.values_names = values_names
        self.name = name

        self.shape = storage.shape
        self.indexer = storage

    def get_element_from_index(self, index):
        """Getter method over self.sequence.

        Returns the features stored at index index. Compared to __getitem__, it does take
        the index-th element of sequence but the index-th element of the store.

        Parameters
        ----------
        index : (int, list, slice)
            index argument of the feature

        Returns
        -------
        array_like
            features corresponding to the index index in self.store
        """
        return self.batch[index]

    def __len__(self):
        """Return the length of the sequence of apparition of the features."""
        return self.shape[0]

    def __getitem__(self, id_keys):
        """Subset FeaturesStorage, keeping only features which id is in keys.

        Parameters
        ----------
        id_keys : Iterable
            List of ids to keep.

        Returns
        -------
        FeaturesStorage
            Subset of the FeaturesStorage, with only the features whose id is in id_keys
        """
        if not isinstance(id_keys, list):
            id_keys = [id_keys]
        return ArrayStorage(
            values=self.batch[id_keys], values_names=self.values_names, name=self.name
        )

    def get_storage_type(self):
        """Functions to access stored elements dtypes.

        Returns
        -------
        tuple
            tuple of dtypes of the stored elements, as returned by np.dtype
        """
        element = self.get_element_from_index(0)
        return element.dtype

    @property
    def batch(self):
        """Indexing attribute."""
        return self.indexer

batch property

Indexing attribute.

__getitem__(id_keys)

Subset FeaturesStorage, keeping only features which id is in keys.

Parameters:

Name Type Description Default
id_keys Iterable

List of ids to keep.

required

Returns:

Type Description
FeaturesStorage

Subset of the FeaturesStorage, with only the features whose id is in id_keys

Source code in choice_learn/data/storage.py
def __getitem__(self, id_keys):
    """Subset FeaturesStorage, keeping only features which id is in keys.

    Parameters
    ----------
    id_keys : Iterable
        List of ids to keep.

    Returns
    -------
    FeaturesStorage
        Subset of the FeaturesStorage, with only the features whose id is in id_keys
    """
    if not isinstance(id_keys, list):
        id_keys = [id_keys]
    return ArrayStorage(
        values=self.batch[id_keys], values_names=self.values_names, name=self.name
    )

__init__(values=None, values_names=None, name=None)

Build the store.

Parameters:

Name Type Description Default
values array_like

list of values of features to store

None
values_names array_like

Iterable of str indicating the name of the features. Must be same length as values.

None
name

name of the features store

None
Source code in choice_learn/data/storage.py
def __init__(self, values=None, values_names=None, name=None):
    """Build the store.

    Parameters
    ----------
    values : array_like
        list of values of features to store
    values_names : array_like
        Iterable of str indicating the name of the features. Must be same length as values.
    name: string, optional
        name of the features store
    """
    if isinstance(values, list):
        storage = np.array(values)
    elif not isinstance(values, np.ndarray):
        raise ValueError("ArrayStorage Values must be a list or a numpy array")

    # self.storage = storage
    self.values_names = values_names
    self.name = name

    self.shape = storage.shape
    self.indexer = storage

__len__()

Return the length of the sequence of apparition of the features.

Source code in choice_learn/data/storage.py
def __len__(self):
    """Return the length of the sequence of apparition of the features."""
    return self.shape[0]

get_element_from_index(index)

Getter method over self.sequence.

Returns the features stored at index index. Compared to getitem, it does take the index-th element of sequence but the index-th element of the store.

Parameters:

Name Type Description Default
index (int, list, slice)

index argument of the feature

required

Returns:

Type Description
array_like

features corresponding to the index index in self.store

Source code in choice_learn/data/storage.py
def get_element_from_index(self, index):
    """Getter method over self.sequence.

    Returns the features stored at index index. Compared to __getitem__, it does take
    the index-th element of sequence but the index-th element of the store.

    Parameters
    ----------
    index : (int, list, slice)
        index argument of the feature

    Returns
    -------
    array_like
        features corresponding to the index index in self.store
    """
    return self.batch[index]

get_storage_type()

Functions to access stored elements dtypes.

Returns:

Type Description
tuple

tuple of dtypes of the stored elements, as returned by np.dtype

Source code in choice_learn/data/storage.py
def get_storage_type(self):
    """Functions to access stored elements dtypes.

    Returns
    -------
    tuple
        tuple of dtypes of the stored elements, as returned by np.dtype
    """
    element = self.get_element_from_index(0)
    return element.dtype

DictStorage

Bases: Storage

Function to store features with ids.

Source code in choice_learn/data/storage.py
class DictStorage(Storage):
    """Function to store features with ids."""

    def __init__(
        self,
        ids=None,
        values=None,
        values_names=None,
        name=None,
        indexer=StorageIndexer,
    ):
        """Build the store.

        Parameters
        ----------
        ids : array_like or None
            list of ids of features to store. If None is given, ids are created from
            apparition order of values
        values : array_like
            list of values of features to store
        values_names : array_like
            Iterable of str indicating the name of the features. Must be same length as values.
        name: string, optional
            name of the features store
        """
        print("DictStorage")
        if isinstance(values, dict):
            storage = values
            lengths = []
            for k, v in storage.items():
                if not isinstance(v, np.ndarray) | isinstance(v, list):
                    raise ValueError("values must be a dict of np.ndarray or list")
                if not len(np.array(v).shape) == 1:
                    raise ValueError(
                        "values (features) must be a dict of np.ndarray or list of 1D arrays"
                    )
                lengths.append(len(v))
                if isinstance(v, list):
                    storage[k] = np.array(v)
            if not len(set(lengths)) == 1:
                raise ValueError("values (dict values) must all have same length")
            if ids is not None:
                print("Warning: ids is ignored when values is a dict")

        elif isinstance(values, pd.DataFrame):
            if values_names is not None:
                print("Warning: values_names is ignored when values is a DataFrame")
            if "id" in values.columns:
                values = values.set_index("id")
            values_names = values.columns
            storage = {k: v.to_numpy() for (k, v) in values.iterrows()}
        elif isinstance(values, list) or isinstance(values, np.ndarray):
            if ids is None:
                ids = list(range(len(values)))
            storage = {k: np.array(v) for (k, v) in zip(ids, values)}
        else:
            raise ValueError("values must be a dict, a DataFrame, a list or a numpy array")

        self.storage = storage
        self.values_names = values_names
        self.name = name

        self.shape = (len(self), len(next(iter(self.storage.values()))))
        self.indexer = indexer(self)

    def get_element_from_index(self, index):
        """Getter method over self.sequence.

        Returns the features stored at index index. Compared to __getitem__, it does take
        the index-th element of sequence but the index-th element of the store.

        Parameters
        ----------
        index : (int, list, slice)
            index argument of the feature

        Returns
        -------
        array_like
            features corresponding to the index index in self.store
        """
        if isinstance(index, int):
            index = [index]
        keys = [list(self.storage.keys())[i] for i in index]
        return self.batch[keys]

    def __len__(self):
        """Return the length of the sequence of apparition of the features."""
        return len(self.storage)

    def __getitem__(self, id_keys):
        """Subset FeaturesStorage, keeping only features which id is in keys.

        Parameters
        ----------
        id_keys : Iterable
            List of ids to keep.

        Returns
        -------
        FeaturesStorage
            Subset of the FeaturesStorage, with only the features whose id is in id_keys
        """
        if not isinstance(id_keys, list):
            id_keys = [id_keys]
        sub_storage = {k: self.storage[k] for k in id_keys}
        return FeaturesStorage(values=sub_storage, values_names=self.values_names, name=self.name)

    def get_storage_type(self):
        """Functions to access stored elements dtypes.

        Returns
        -------
        tuple
            tuple of dtypes of the stored elements, as returned by np.dtype
        """
        element = self.get_element_from_index(0)
        return element.dtype

    @property
    def batch(self):
        """Indexing attribute."""
        return self.indexer

batch property

Indexing attribute.

__getitem__(id_keys)

Subset FeaturesStorage, keeping only features which id is in keys.

Parameters:

Name Type Description Default
id_keys Iterable

List of ids to keep.

required

Returns:

Type Description
FeaturesStorage

Subset of the FeaturesStorage, with only the features whose id is in id_keys

Source code in choice_learn/data/storage.py
def __getitem__(self, id_keys):
    """Subset FeaturesStorage, keeping only features which id is in keys.

    Parameters
    ----------
    id_keys : Iterable
        List of ids to keep.

    Returns
    -------
    FeaturesStorage
        Subset of the FeaturesStorage, with only the features whose id is in id_keys
    """
    if not isinstance(id_keys, list):
        id_keys = [id_keys]
    sub_storage = {k: self.storage[k] for k in id_keys}
    return FeaturesStorage(values=sub_storage, values_names=self.values_names, name=self.name)

__init__(ids=None, values=None, values_names=None, name=None, indexer=StorageIndexer)

Build the store.

Parameters:

Name Type Description Default
ids array_like or None

list of ids of features to store. If None is given, ids are created from apparition order of values

None
values array_like

list of values of features to store

None
values_names array_like

Iterable of str indicating the name of the features. Must be same length as values.

None
name

name of the features store

None
Source code in choice_learn/data/storage.py
def __init__(
    self,
    ids=None,
    values=None,
    values_names=None,
    name=None,
    indexer=StorageIndexer,
):
    """Build the store.

    Parameters
    ----------
    ids : array_like or None
        list of ids of features to store. If None is given, ids are created from
        apparition order of values
    values : array_like
        list of values of features to store
    values_names : array_like
        Iterable of str indicating the name of the features. Must be same length as values.
    name: string, optional
        name of the features store
    """
    print("DictStorage")
    if isinstance(values, dict):
        storage = values
        lengths = []
        for k, v in storage.items():
            if not isinstance(v, np.ndarray) | isinstance(v, list):
                raise ValueError("values must be a dict of np.ndarray or list")
            if not len(np.array(v).shape) == 1:
                raise ValueError(
                    "values (features) must be a dict of np.ndarray or list of 1D arrays"
                )
            lengths.append(len(v))
            if isinstance(v, list):
                storage[k] = np.array(v)
        if not len(set(lengths)) == 1:
            raise ValueError("values (dict values) must all have same length")
        if ids is not None:
            print("Warning: ids is ignored when values is a dict")

    elif isinstance(values, pd.DataFrame):
        if values_names is not None:
            print("Warning: values_names is ignored when values is a DataFrame")
        if "id" in values.columns:
            values = values.set_index("id")
        values_names = values.columns
        storage = {k: v.to_numpy() for (k, v) in values.iterrows()}
    elif isinstance(values, list) or isinstance(values, np.ndarray):
        if ids is None:
            ids = list(range(len(values)))
        storage = {k: np.array(v) for (k, v) in zip(ids, values)}
    else:
        raise ValueError("values must be a dict, a DataFrame, a list or a numpy array")

    self.storage = storage
    self.values_names = values_names
    self.name = name

    self.shape = (len(self), len(next(iter(self.storage.values()))))
    self.indexer = indexer(self)

__len__()

Return the length of the sequence of apparition of the features.

Source code in choice_learn/data/storage.py
def __len__(self):
    """Return the length of the sequence of apparition of the features."""
    return len(self.storage)

get_element_from_index(index)

Getter method over self.sequence.

Returns the features stored at index index. Compared to getitem, it does take the index-th element of sequence but the index-th element of the store.

Parameters:

Name Type Description Default
index (int, list, slice)

index argument of the feature

required

Returns:

Type Description
array_like

features corresponding to the index index in self.store

Source code in choice_learn/data/storage.py
def get_element_from_index(self, index):
    """Getter method over self.sequence.

    Returns the features stored at index index. Compared to __getitem__, it does take
    the index-th element of sequence but the index-th element of the store.

    Parameters
    ----------
    index : (int, list, slice)
        index argument of the feature

    Returns
    -------
    array_like
        features corresponding to the index index in self.store
    """
    if isinstance(index, int):
        index = [index]
    keys = [list(self.storage.keys())[i] for i in index]
    return self.batch[keys]

get_storage_type()

Functions to access stored elements dtypes.

Returns:

Type Description
tuple

tuple of dtypes of the stored elements, as returned by np.dtype

Source code in choice_learn/data/storage.py
def get_storage_type(self):
    """Functions to access stored elements dtypes.

    Returns
    -------
    tuple
        tuple of dtypes of the stored elements, as returned by np.dtype
    """
    element = self.get_element_from_index(0)
    return element.dtype

FeaturesStorage

Bases: object

Base FeaturesStorage class that redirects toward the right one.

Source code in choice_learn/data/storage.py
class FeaturesStorage(object):
    """Base FeaturesStorage class that redirects toward the right one."""

    def __new__(
        cls,
        ids=None,
        values=None,
        values_names=None,
        name=None,
        as_one_hot=False,
    ):
        """Redirects toward the right object.

        Parameters
        ----------
        ids : Iterable, optional
            IDs to references features with, by default None
        values : Iterable, optional
            Features to be stored, by default None
        values_names : list, optional
            List of names for the features to be stored, by default None
        name : str, optional
            Name of the FeaturesStorage, to be matched in ChoiceDataset, by default None
        as_one_hot: bool
            Whether features are OneHot representations or not.

        Returns
        -------
        FeaturesStorage
            One of ArrayStorage, DictStorage or OneHotStorage
        """
        if as_one_hot:
            return OneHotStorage(ids=ids, values=values, name=name)

        if ids is None and (isinstance(values, np.ndarray) or isinstance(values, list)):
            return ArrayStorage(values=values, values_names=values_names, name=name)

        if ids is not None:
            check_ids = np.unique(ids) == np.arange(len(ids))
            if isinstance(check_ids, np.ndarray):
                check_ids = check_ids.all()
            if check_ids:
                values = [values[np.where(np.array(ids) == i)[0][0]] for i in np.arange(len(ids))]
                return ArrayStorage(values=values, values_names=values_names, name=name)

        return DictStorage(
            ids=ids, values=values, values_names=values_names, name=name, indexer=StorageIndexer
        )

__new__(ids=None, values=None, values_names=None, name=None, as_one_hot=False)

Redirects toward the right object.

Parameters:

Name Type Description Default
ids Iterable

IDs to references features with, by default None

None
values Iterable

Features to be stored, by default None

None
values_names list

List of names for the features to be stored, by default None

None
name str

Name of the FeaturesStorage, to be matched in ChoiceDataset, by default None

None
as_one_hot

Whether features are OneHot representations or not.

False

Returns:

Type Description
FeaturesStorage

One of ArrayStorage, DictStorage or OneHotStorage

Source code in choice_learn/data/storage.py
def __new__(
    cls,
    ids=None,
    values=None,
    values_names=None,
    name=None,
    as_one_hot=False,
):
    """Redirects toward the right object.

    Parameters
    ----------
    ids : Iterable, optional
        IDs to references features with, by default None
    values : Iterable, optional
        Features to be stored, by default None
    values_names : list, optional
        List of names for the features to be stored, by default None
    name : str, optional
        Name of the FeaturesStorage, to be matched in ChoiceDataset, by default None
    as_one_hot: bool
        Whether features are OneHot representations or not.

    Returns
    -------
    FeaturesStorage
        One of ArrayStorage, DictStorage or OneHotStorage
    """
    if as_one_hot:
        return OneHotStorage(ids=ids, values=values, name=name)

    if ids is None and (isinstance(values, np.ndarray) or isinstance(values, list)):
        return ArrayStorage(values=values, values_names=values_names, name=name)

    if ids is not None:
        check_ids = np.unique(ids) == np.arange(len(ids))
        if isinstance(check_ids, np.ndarray):
            check_ids = check_ids.all()
        if check_ids:
            values = [values[np.where(np.array(ids) == i)[0][0]] for i in np.arange(len(ids))]
            return ArrayStorage(values=values, values_names=values_names, name=name)

    return DictStorage(
        ids=ids, values=values, values_names=values_names, name=name, indexer=StorageIndexer
    )

OneHotStorage

Bases: Storage

Specific Storage for one hot features storage.

Inherits from Storage. For example can be used to store a OneHot representation of the days of week.

Has the same attributes as FeaturesStoage, only differs whit some One-Hot optimized methods. It only stores the indexes of the features, and creates the OneHot matrix when needed, using .batch[].

Source code in choice_learn/data/storage.py
class OneHotStorage(Storage):
    """Specific Storage for one hot features storage.

    Inherits from Storage.
    For example can be used to store a OneHot representation of the days of week.

    Has the same attributes as FeaturesStoage, only differs whit some One-Hot optimized methods.
    It only stores the indexes of the features, and creates the OneHot matrix
    when needed, using .batch[].
    """

    def __init__(
        self, ids=None, values=None, name=None, dtype=np.uint8, indexer=OneHotStorageIndexer
    ):
        """Build the store.

        Parameters
        ----------
        ids : array_like or None
            list of ids of features to store. If None is given, ids are created from
            apparition order of values
        values : array_like
            list of values of features to store
        dtype: type
            type for One Hot representation, usually int or float, default is np.uint8
        name: string, optional
            name of the features store
        """
        if isinstance(values, dict):
            storage = values
            for k, v in storage.items():
                if not isinstance(v, int):
                    raise ValueError(
                        """values of values dict must be int as
                        they are indexes of the one hot vector ones."""
                    )
            length = np.max(list(storage.values())) + 1
            if ids is not None:
                print("Warning: ids is ignored when values is a dict")

        elif isinstance(values, list) or isinstance(values, np.ndarray):
            if ids is None:
                ids = list(range(len(values)))
            storage = {k: int(v) for (k, v) in zip(ids, values)}
            length = np.max(values) + 1

        elif values is None:
            if ids is None:
                raise ValueError("ids or values must be given, both are None")
            value = 0
            storage = {}
            for id in ids:
                storage[id] = value
                value += 1
            length = value
        else:
            raise ValueError("values must be a dict, a DataFrame, a list or a numpy array")

        self.storage = storage
        self.name = name

        self.shape = (len(self), length)
        self.dtype = dtype
        self.indexer = indexer(self)

    def __len__(self):
        """Return the length of the sequence of apparition of the features."""
        return len(self.storage)

    def __getitem__(self, id_keys):
        """Subset FeaturesStorage, keeping only features which id is in keys.

        Parameters
        ----------
        id_keys : Iterable
            List of ids to keep.

        Returns
        -------
        OneHotStorage
            Subset of the OneHotStorage, with only the features whose id is in id_keys
        """
        if isinstance(id_keys, int):
            id_keys = [id_keys]
        sub_storage = {k: self.storage[k] for k in id_keys}

        return OneHotStorage(values=sub_storage, name=self.name, dtype=self.dtype)

    def astype(self, dtype):
        """Change (mainly int or float) type of returned OneHot features vectors.

        Parameters
        ----------
        dtype : type
            Type to set the features as
        """
        self.dtype = dtype

    def get_element_from_index(self, index):
        """Getter method over self.sequence.

        Returns the features stored at index index. Compared to __getitem__, it does take
        the index-th element of sequence but the index-th element of the store.

        Parameters
        ----------
        index : (int, list, slice)
            index argument of the feature

        Returns
        -------
        array_like
            features corresponding to the index index in self.store
        """
        keys = list(self.storage.keys())[index]
        return self.storage[keys]

    def get_storage_type(self):
        """Functions to access stored elements dtypes.

        Returns
        -------
        type
            tuple of dtypes of the stored elements, as returned by np.dtype
        """
        return self.dtype

    @property
    def batch(self):
        """Indexing attribute."""
        return self.indexer

batch property

Indexing attribute.

__getitem__(id_keys)

Subset FeaturesStorage, keeping only features which id is in keys.

Parameters:

Name Type Description Default
id_keys Iterable

List of ids to keep.

required

Returns:

Type Description
OneHotStorage

Subset of the OneHotStorage, with only the features whose id is in id_keys

Source code in choice_learn/data/storage.py
def __getitem__(self, id_keys):
    """Subset FeaturesStorage, keeping only features which id is in keys.

    Parameters
    ----------
    id_keys : Iterable
        List of ids to keep.

    Returns
    -------
    OneHotStorage
        Subset of the OneHotStorage, with only the features whose id is in id_keys
    """
    if isinstance(id_keys, int):
        id_keys = [id_keys]
    sub_storage = {k: self.storage[k] for k in id_keys}

    return OneHotStorage(values=sub_storage, name=self.name, dtype=self.dtype)

__init__(ids=None, values=None, name=None, dtype=np.uint8, indexer=OneHotStorageIndexer)

Build the store.

Parameters:

Name Type Description Default
ids array_like or None

list of ids of features to store. If None is given, ids are created from apparition order of values

None
values array_like

list of values of features to store

None
dtype

type for One Hot representation, usually int or float, default is np.uint8

uint8
name

name of the features store

None
Source code in choice_learn/data/storage.py
def __init__(
    self, ids=None, values=None, name=None, dtype=np.uint8, indexer=OneHotStorageIndexer
):
    """Build the store.

    Parameters
    ----------
    ids : array_like or None
        list of ids of features to store. If None is given, ids are created from
        apparition order of values
    values : array_like
        list of values of features to store
    dtype: type
        type for One Hot representation, usually int or float, default is np.uint8
    name: string, optional
        name of the features store
    """
    if isinstance(values, dict):
        storage = values
        for k, v in storage.items():
            if not isinstance(v, int):
                raise ValueError(
                    """values of values dict must be int as
                    they are indexes of the one hot vector ones."""
                )
        length = np.max(list(storage.values())) + 1
        if ids is not None:
            print("Warning: ids is ignored when values is a dict")

    elif isinstance(values, list) or isinstance(values, np.ndarray):
        if ids is None:
            ids = list(range(len(values)))
        storage = {k: int(v) for (k, v) in zip(ids, values)}
        length = np.max(values) + 1

    elif values is None:
        if ids is None:
            raise ValueError("ids or values must be given, both are None")
        value = 0
        storage = {}
        for id in ids:
            storage[id] = value
            value += 1
        length = value
    else:
        raise ValueError("values must be a dict, a DataFrame, a list or a numpy array")

    self.storage = storage
    self.name = name

    self.shape = (len(self), length)
    self.dtype = dtype
    self.indexer = indexer(self)

__len__()

Return the length of the sequence of apparition of the features.

Source code in choice_learn/data/storage.py
def __len__(self):
    """Return the length of the sequence of apparition of the features."""
    return len(self.storage)

astype(dtype)

Change (mainly int or float) type of returned OneHot features vectors.

Parameters:

Name Type Description Default
dtype type

Type to set the features as

required
Source code in choice_learn/data/storage.py
def astype(self, dtype):
    """Change (mainly int or float) type of returned OneHot features vectors.

    Parameters
    ----------
    dtype : type
        Type to set the features as
    """
    self.dtype = dtype

get_element_from_index(index)

Getter method over self.sequence.

Returns the features stored at index index. Compared to getitem, it does take the index-th element of sequence but the index-th element of the store.

Parameters:

Name Type Description Default
index (int, list, slice)

index argument of the feature

required

Returns:

Type Description
array_like

features corresponding to the index index in self.store

Source code in choice_learn/data/storage.py
def get_element_from_index(self, index):
    """Getter method over self.sequence.

    Returns the features stored at index index. Compared to __getitem__, it does take
    the index-th element of sequence but the index-th element of the store.

    Parameters
    ----------
    index : (int, list, slice)
        index argument of the feature

    Returns
    -------
    array_like
        features corresponding to the index index in self.store
    """
    keys = list(self.storage.keys())[index]
    return self.storage[keys]

get_storage_type()

Functions to access stored elements dtypes.

Returns:

Type Description
type

tuple of dtypes of the stored elements, as returned by np.dtype

Source code in choice_learn/data/storage.py
def get_storage_type(self):
    """Functions to access stored elements dtypes.

    Returns
    -------
    type
        tuple of dtypes of the stored elements, as returned by np.dtype
    """
    return self.dtype

Storage

Bases: ABC

Parent Class to have OneHotStorage and FeaturesStorage with same parent.

Source code in choice_learn/data/storage.py
class Storage(ABC):
    """Parent Class to have OneHotStorage and FeaturesStorage with same parent."""

    def __init__(self, features_to_store):
        """Instantiate the storage.

        Parameters
        ----------
        features_to_store : object
            Object to store
        """
        self.features_to_store = features_to_store

    @abstractmethod
    def __getitem__(self, keys):
        """Access an element. To be implemented in children classes.

        Parameters
        ----------
        keys : float, int, str or list of
            values among indexes of the stiage
        """
        pass

    @abstractmethod
    def __len__(self):
        """Return the length of the sequence of apparition of the features."""
        pass

    @property
    def batch(self):
        """Indexing method."""
        pass

    def __str__(self):
        """Return string representation method.

        Returns
        -------
        str
            Description of the storage.
        """
        return f"FeatureStorage with name {self.name}"

batch property

Indexing method.

__getitem__(keys) abstractmethod

Access an element. To be implemented in children classes.

Parameters:

Name Type Description Default
keys float, int, str or list of

values among indexes of the stiage

required
Source code in choice_learn/data/storage.py
@abstractmethod
def __getitem__(self, keys):
    """Access an element. To be implemented in children classes.

    Parameters
    ----------
    keys : float, int, str or list of
        values among indexes of the stiage
    """
    pass

__init__(features_to_store)

Instantiate the storage.

Parameters:

Name Type Description Default
features_to_store object

Object to store

required
Source code in choice_learn/data/storage.py
def __init__(self, features_to_store):
    """Instantiate the storage.

    Parameters
    ----------
    features_to_store : object
        Object to store
    """
    self.features_to_store = features_to_store

__len__() abstractmethod

Return the length of the sequence of apparition of the features.

Source code in choice_learn/data/storage.py
@abstractmethod
def __len__(self):
    """Return the length of the sequence of apparition of the features."""
    pass

__str__()

Return string representation method.

Returns:

Type Description
str

Description of the storage.

Source code in choice_learn/data/storage.py
def __str__(self):
    """Return string representation method.

    Returns
    -------
    str
        Description of the storage.
    """
    return f"FeatureStorage with name {self.name}"