lenskit.data.matrix.SparseRowArray#
- class lenskit.data.matrix.SparseRowArray#
Bases:
ExtensionArray
An array of sparse rows (a compressed sparse row matrix).
Stability: Internal
This API is at the internal or experimental stability level: it may change at any time, and breaking changes will not necessarily be described in the release notes. See Stability Levels for details.
- __init__(*args, **kwargs)#
Methods
__init__
(*args, **kwargs)buffers
(self)Return a list of Buffer objects pointing to this array's physical storage.
cast
(self[, target_type, safe, options, ...])Cast array values to another data type
copy_to
(self, destination)Construct a copy of the array with all buffers on destination device.
dictionary_encode
(self[, null_encoding])Compute dictionary-encoded representation of array.
diff
(self, Array other)Compare contents of this array against another one.
drop_null
(self)Remove missing values from an array.
equals
(self, Array other)fill_null
(self, fill_value)See
pyarrow.compute.fill_null()
for usage.filter
(self, mask, *[, null_selection_behavior])Select values from an array.
format
(self, **kwargs)DEPRECATED, use pyarrow.Array.to_string
from_array
(array[, dimension])Interpret an Arrow array as a sparse row array, if possible.
from_arrays
(offsets, indices[, values, shape])from_buffers
(DataType type, length, buffers)Construct an Array from a sequence of buffers.
from_pandas
(obj[, mask, type])Convert pandas.Series to an Arrow Array.
from_scipy
(csr, *[, values, large])Create a sparse row array from a SciPy sparse matrix.
from_storage
(BaseExtensionType typ, ...)Construct ExtensionArray from type and storage array.
get_total_buffer_size
(self)The sum of bytes in each buffer referenced by the array.
index
(self, value[, start, end, memory_pool])Find the first index of a value.
is_nan
(self)Return BooleanArray indicating the NaN values.
is_null
(self, *[, nan_is_null])Return BooleanArray indicating the null values.
is_valid
(self)Return BooleanArray indicating the non-null values.
row_extent
(row)Get the start and end of a row.
row_indices
(row)Get the index array for a compressed sparse row.
slice
(self[, offset, length])Compute zero-copy slice of this array.
sort
(self[, order])Sort the Array
sum
(self, **kwargs)Sum the values in a numerical array.
take
(self, indices)Select values from an array.
to_numpy
(self[, zero_copy_only, writable])Return a NumPy view or copy of this array.
to_pandas
(self[, memory_pool, categories, ...])Convert to a pandas-compatible NumPy array or DataFrame, as appropriate
to_pylist
(self)Convert to a list of native Python objects.
to_scipy
()Convert this sparse row array to a SciPy sparse array.
to_string
(self, *, int indent=2, ...)Render a "pretty-printed" string representation of the Array.
to_torch
()Convert this sparse row array to a Torch sparse tensor.
tolist
(self)Alias of to_pylist for compatibility with NumPy.
unique
(self)Compute distinct elements in array.
validate
(self, *[, full])Perform validation checks.
value_counts
(self)Compute counts of unique elements in array.
view
(self, target_type)Return zero-copy "view" of array as another data type.
Attributes
device_type
The device type where the array resides.
Get the number of columns in the sparse matrix.
has_values
indices
is_cpu
Whether the array is CPU-accessible.
nbytes
Total number of bytes consumed by the elements of the array.
null_count
offset
A relative position into another array's data.
offsets
shape
storage
type
values
- classmethod from_array(array, dimension=None)#
Interpret an Arrow array as a sparse row array, if possible. Handles legacy layouts without the extension types.
- Parameters:
- Return type:
- classmethod from_scipy(csr, *, values=True, large=None)#
Create a sparse row array from a SciPy sparse matrix.
- Parameters:
- Returns:
The sparse row array.
- Return type:
- to_scipy()#
Convert this sparse row array to a SciPy sparse array.