daf.typing.sparse

The types here describe a sparse compressed scipy.sparse.csr_matrix and scipy.sparse.csc_matrix data, which can be fetched from daf.

In theory it should have been possible to store sparse data inside a pandas.DataFrame, but in practice this fails in various ways, so don’t. When fetching data from daf, frames will alway contain dense (numpy.ndarray 2D) data.

Note

Other sparse formats (e.g. scipy.sparse.coo_matrix) can’t be fetched from daf. This allows daf to ensure that all fetched data is in either ROW_MAJOR or COLUMN_MAJOR layout, which greatly simplifies the code accessing the data.

Data:

Sparse

2D scipy.sparse.spmatrix in compressed layout.

SparseInRows(x)

SparseInColumns(x)

Functions:

is_sparse(data, *[, dtype, shape, layout])

Check whether some data is a Sparse, optionally only of some dtype, optionally only of some shape, optionally only of some layout.

be_sparse(data, *[, dtype, shape, layout])

Assert that some data is a Sparse optionally only of some dtype, optionally only of some shape, optionally of some layout, and return it as such for mypy.

is_sparse_in_rows(data, *[, dtype, shape])

Check whether some data is a SparseInRows, optionally only of some dtype, optionally only of some shape.

be_sparse_in_rows(data, *[, dtype, shape])

Assert that some data is a SparseInRows, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

is_sparse_in_columns(data, *[, dtype, shape])

Check whether some data is a SparseInColumns, optionally only of some dtype, optionally only of some shape.

be_sparse_in_columns(data, *[, dtype, shape])

Assert that some data is a SparseInColumns, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

daf.typing.sparse.Sparse(*args, **kwargs)

2D scipy.sparse.spmatrix in compressed layout.

alias of Union[SparseInRows, SparseInColumns]

daf.typing.sparse.is_sparse(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None, layout: Optional[_layouts.AnyMajor] = None) TypeGuard[Sparse][source]

Check whether some data is a Sparse, optionally only of some dtype, optionally only of some shape, optionally only of some layout.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.sparse.be_sparse(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None, layout: Optional[AnyMajor] = None) Union[SparseInRows, SparseInColumns][source]

Assert that some data is a Sparse optionally only of some dtype, optionally only of some shape, optionally of some layout, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.sparse.SparseInRows

2D scipy.sparse.spmatrix in CSR layout (that is, scipy.sparse.csr_matrix).

alias of _fake_sparse.cs_matrix

daf.typing.sparse.is_sparse_in_rows(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None) TypeGuard[SparseInRows][source]

Check whether some data is a SparseInRows, optionally only of some dtype, optionally only of some shape.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.sparse.be_sparse_in_rows(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None) SparseInRows[source]

Assert that some data is a SparseInRows, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.sparse.SparseInColumns

2D scipy.sparse.spmatrix in CSC layout (that is, scipy.sparse.csc_matrix).

alias of _fake_sparse.cs_matrix

daf.typing.sparse.is_sparse_in_columns(data: Any, *, dtype: Optional[_dtypes.DTypes] = None, shape: Optional[Tuple[int, int]] = None) TypeGuard[SparseInColumns][source]

Check whether some data is a SparseInColumns, optionally only of some dtype, optionally only of some shape.

By default, checks that the data type is one of ALL_DTYPES.

daf.typing.sparse.be_sparse_in_columns(data: Any, *, dtype: Optional[Union[str, dtype, Collection[str], Collection[dtype], Collection[Union[str, dtype]]]] = None, shape: Optional[Tuple[int, int]] = None) SparseInColumns[source]

Assert that some data is a SparseInColumns, optionally only of some dtype, optionally only of some shape, and return it as such for mypy.

By default, checks that the data type is one of ALL_DTYPES.