Skip to content

Improve check for sparse dataframes #16845

Closed

Description

@jorisvandenbossche

Originally posted by @jorisvandenbossche in #16728

To be safe, I would also add a check that all columns are indeed sparse (the .sparse accessor now raises if not all columns are sparse, but I am not sure this is necessarily guaranteed to stay that way).
The explicit check would be something like:

df.dtypes.apply(pd.api.types.is_sparse).all()

See also pandas-dev/pandas#26706

Activity

  1. thomasjpfan commented on Jun 7, 2020

    @thomasjpfan
    Member

    For context, this should be updating:

    # When all dataframe columns are sparse, convert to a sparse array
    if hasattr(array, 'sparse') and array.ndim > 1:
    # DataFrame.sparse only supports `to_coo`
    array = array.sparse.to_coo()

  2. genvalen commented on Jun 7, 2020

    @genvalen
    Contributor

    take

  3. Repository owner moved this from Todo📬 to Done🚀 in Quansight's scikit-learn Project Boardon Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions