lenskit.data.ListILC#
- class lenskit.data.ListILC(key, *, index=True)#
Bases:
lenskit.data._collection._base.MutableItemListCollection[lenskit.data._collection._keys.K],Generic[lenskit.data._collection._keys.K]Mutable item list collection backed by a Python list.
- Parameters:
key (type[lenskit.data._collection._keys.K] | collections.abc.Sequence[str])
index (bool)
- list_schema: pyarrow.Schema#
Get the schema for the lists in this ILC.
- classmethod from_dict(data: collections.abc.Mapping[lenskit.data._collection._keys.GenericKey | lenskit.data._collection._keys.ID, lenskit.data._items.ItemList], key: type[lenskit.data._collection._keys.K]) lenskit.data._collection._base.ItemListCollection[lenskit.data._collection._keys.K]#
- classmethod from_dict(data: collections.abc.Mapping[lenskit.data._collection._keys.GenericKey | lenskit.data._collection._keys.ID, lenskit.data._items.ItemList], key: collections.abc.Sequence[str] | str | None = None) lenskit.data._collection._base.ItemListCollection[lenskit.data._collection._keys.GenericKey]
Create an item list collection from a dictionary.
- classmethod from_df(df, key=None, *others)#
Create an item list collection from a data frame.
Note
Keys with empty item lists will be silently excluded from the output data.
- Parameters:
df (pandas.DataFrame) – The data frame to convert.
key (type[lenskit.data._collection._keys.K] | collections.abc.Sequence[lenskit.data._adapt.Column] | lenskit.data._adapt.Column | None) – The key type or field(s). Can be specified as a single column name (or
AliasedColumn).others (lenskit.data._adapt.Column) – Other columns to consider; primarily used to pass additional aliased columns to normalize other clumnes like the item ID.
- static from_arrow(table)#
Convert an Arrow table into an item list collection.
- Parameters:
table (pyarrow.Table)
- Return type:
lenskit.data._collection._base.MutableItemListCollection[Any]
- add(list, *fields, **kwfields)#
Add a single item list to this list.
- Parameters:
list (lenskit.data._items.ItemList) – The item list to add.
fields (lenskit.data._collection._keys.ID) – The key fields for this list.
kwfields (lenskit.data._collection._keys.ID) – The key fields for this list.
- add_from(other, **fields)#
Add all collection from another collection to this collection. If field values are supplied, they are used to supplement or overwrite the keys in
other; a common use case is to add results from multiple recommendation runs and save them a single field.- Parameters:
other (lenskit.data._collection._base.ItemListCollection[lenskit.data._collection._keys.Ko]) – The item list collection to incorporate into this one.
fields (lenskit.data._collection._keys.ID) – Additional key fields (must be specified by name).
- lookup(key: tuple) lenskit.data._items.ItemList | None#
- lookup(*key: lenskit.data._collection._keys.ID, **kwkey: lenskit.data._collection._keys.ID) lenskit.data._items.ItemList | None
Look up a list by key. If multiple lists have the same key, this returns the last (like a dictionary).
This method can be called with the key tuple as a single argument (and this can be either the actual named tuple, or an ordinary tuple of the same length), or with the individual key fields as positional or named arguments.
- Parameters:
key – The key tuple or key tuple fields.
- items()#
Iterate over item lists and keys.
- Return type:
collections.abc.Iterator[tuple[lenskit.data._collection._keys.K, lenskit.data._items.ItemList]]
- __len__()#
- __getitem__(pos, /)#
Get an item list and its key by position.
- Parameters:
pos (int) – The position in the list (starting from 0).
- Returns:
The key and list at position
pos.- Raises:
IndexError – when
posis out-of-bounds.- Return type:
tuple[lenskit.data._collection._keys.K, lenskit.data._items.ItemList]
- __repr__()#