lenskit.data.AttributeSet#

class lenskit.data.AttributeSet(name, spec, table, vocab, rows)#

Bases: object

Base class for attributes associated with entities.

This is the general interface for attribute sets. Not all access methods are supported for all layouts.

Stability:
Caller (see Stability Levels).
Parameters:
__init__(name, spec, table, vocab, rows)#
Parameters:

Methods

__init__(name, spec, table, vocab, rows)

arrow()

Get the attribute values as an Arrow array.

drop_null()

Subset this attribute set to only entities for which it is defined.

ids()

Get the entity IDs for the rows in this attribute's values.

numbers()

Get the entity numbers for the rows in this attribute's values.

numpy()

Get the attribute values as a NumPy array.

pandas(*[, missing])

scipy()

Get this attribute as a SciPy sparse array (if it is sparse), or a NumPy array if it is dense.

torch()

Attributes

dim_names

Get the names attached to this attribute's dimensions.

is_list

Query whether this attribute is a list.

is_scalar

Query whether this attribute is scalar.

is_sparse

Query whether this attribute is a sparse vector.

is_vector

Query whether this attribute is a dense vector.

name

The name of the attribute.

name: str#

The name of the attribute.

ids()#

Get the entity IDs for the rows in this attribute’s values.

Return type:

ndarray[tuple[int], dtype[integer[Any] | str_ | bytes_ | object_]]

numbers()#

Get the entity numbers for the rows in this attribute’s values.

Return type:

ndarray[int, dtype[int32]]

property dim_names: list[str] | None#

Get the names attached to this attribute’s dimensions.

Note

Only applicable to vector and sparse attributes.

property is_scalar: bool#

Query whether this attribute is scalar.

property is_list: bool#

Query whether this attribute is a list.

property is_vector: bool#

Query whether this attribute is a dense vector.

property is_sparse: bool#

Query whether this attribute is a sparse vector.

numpy()#

Get the attribute values as a NumPy array.

Note

Undefined attribute values may have undefined contents; they will _usually_ be NaN or similar, but this is not fully guaranteed.

Return type:

ndarray[Any, dtype[Any]]

arrow()#

Get the attribute values as an Arrow array.

Return type:

pa.Array[Any] | pa.ChunkedArray[Any]

scipy()#

Get this attribute as a SciPy sparse array (if it is sparse), or a NumPy array if it is dense.

Return type:

ndarray[Any, dtype[Any]] | csr_array

drop_null()#

Subset this attribute set to only entities for which it is defined.