lenskit.data.ListILC#

class lenskit.data.ListILC(key, *, index=True)#

Bases: MutableItemListCollection[K], Generic[K]

Mutable item list collection backed by a Python list.

Parameters:
__init__(key, *, index=True)#

Create a new item list collection.

Parameters:

Methods

__init__(key, *[, index])

Create a new item list collection.

add(list, *fields, **kwfields)

Add a single item list to this list.

add_from(other, **fields)

Add all collection from another collection to this collection.

empty(key, *[, index])

Create a new empty, mutable item list collection.

from_df(df, key, *others)

Create an item list collection from a data frame.

from_dict()

Create an item list collection from a dictionary.

items()

Iterate over item lists and keys.

keys()

Iterate over keys.

lists()

Iterate over item lists without keys.

load_parquet(path[, key, layout])

Load this item list from a Parquet file.

lookup()

Look up a list by key.

lookup_projected(key)

Look up an item list using a projected key.

record_batches([batch_size, columns])

Get the item list collection as Arrow record batches (in native layout).

save_parquet(path, *[, layout, batch_size, ...])

Save this item list collection to a Parquet file.

to_arrow(*[, batch_size])

Convert this item list collection to an Arrow table.

to_df()

Convert this item list collection to a data frame.

Attributes

key_fields

The names of the key fields.

key_type

The type of collection keys.

list_schema

Get the schema for the lists in this ILC.

property list_schema#

Get the schema for the lists in this ILC.

classmethod from_dict(data: Mapping[tuple[int | str | bytes | integer[Any] | str_ | bytes_ | object_, ...] | int | str | bytes | integer[Any] | str_ | bytes_ | object_, ItemList], key: type[K]) ItemListCollection[K]#
classmethod from_dict(data: Mapping[tuple[int | str | bytes | integer[Any] | str_ | bytes_ | object_, ...] | int | str | bytes | integer[Any] | str_ | bytes_ | object_, ItemList], key: Sequence[str] | str | None = None) ItemListCollection[tuple[int | str | bytes | integer[Any] | str_ | bytes_ | object_, ...]]

Create an item list collection from a dictionary.

classmethod from_df(df, key, *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 (DataFrame) – The data frame to convert.

  • key (type[K] | Sequence[str | AliasedColumn] | str | AliasedColumn) – The key type or field(s). Can be specified as a single column name (or AliasedColumn).

  • others (str | AliasedColumn) – Other columns to consider; primarily used to pass additional aliased columns to normalize other clumnes like the item ID.

add(list, *fields, **kwfields)#

Add a single item list to this list.

Parameters:
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:
lookup(key: tuple) ItemList | None#
lookup(*key: int | str | bytes | integer[Any] | str_ | bytes_ | object_, **kwkey: int | str | bytes | integer[Any] | str_ | bytes_ | object_) 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:

Iterator[tuple[K, ItemList]]