Skip to content

Roadmap: pandas SparseDataFrame may be deprecated #12800

Closed

Description

@justmarkham

I noticed in the new roadmap that the second item on the list relates to "Pandas DataFrames and SparseDataFrames". I wanted to mention that according to an August 2018 talk by @datapythonista (who is a pandas core contributor), SparseDataFrames will be deprecated. Here are the slides from the talk (in notebook form).

I mentioned this to @amueller on Twitter, and he suggested opening an issue to document this.

This PR seems to be the most up-to-date discussion among the pandas team about deprecation.

Hope this is helpful!

Activity

  1. justmarkham commented on Dec 17, 2018

    @justmarkham
    ContributorAuthor

    Additional information, that I just noticed on Twitter from @jorisvandenbossche (another pandas core contributor):

    Small clarification: for now, DataFrames with sparse data will not be deprecated, but we are considering to deprecate the SparseDataFrame subclass (because a normal DataFrame can also hold sparse data) https://mail.python.org/pipermail/pandas-dev/2018-November/000855.html

  2. amueller commented on Dec 17, 2018

    @amueller
    Member

    Thanks for the input.
    So it looks like they might

    Deprecate SparseDataFrame in favor of a DataFrame holding sparse arrays

    So maybe we should change it to "DataFrames for dense and sparse data" to accommodate what ever solution they are going for

  3. TomAugspurger commented on Dec 17, 2018

    @TomAugspurger
    Contributor

    Just to note: the memory usage of the old SparseDataFrame and the "new" (it's been possible for a while) DataFrame where some of the columns are sparse is identical.

    And, I don't think either are that good for very wide matrices. Each column is stored independently as two arrays: One array for the "sparse index" (the positions where the value is explicitly) and the "sparse values" (the value at each sparse index position).

  4. jnothman commented on Dec 18, 2018

    @jnothman
    Member
  5. mitar commented on May 26, 2019

    @mitar
    Contributor

    So if one would pass into scikit-learn method which accepts "sparse array" as input a DataFrame with SparseSeries, would that work or explode at the moment?

  6. jnothman commented on May 26, 2019

    @jnothman
    Member
  7. jorisvandenbossche commented on May 26, 2019

    @jorisvandenbossche
    Member

    A check_array on a (sparse) DataFrame will convert it to a numpy array (__array__), which for a sparse DataFrame means it gets densified, and memory usage will increase.
    You can convert your sparse DataFrame to a scipy sparse matrix, which is probably the best approach for now if you want to keep it sparse.

  8. mitar commented on May 26, 2019

    @mitar
    Contributor

    So for me the beauty of using DataFrame is that I can have both string columns and numerical columns and throw it at random forest and it just works.

    Now, with some columns sparse, we cannot just convert it to scipy sparse matrix, because the latter does not support object dtype.

    What would be the ideal implementation here to support this properly in scikit-learn?

  9. jnothman commented on May 26, 2019

    @jnothman
    Member
  10. amueller commented on Sep 18, 2019

    @amueller
    Member

    I agree that we should make it a scipy sparse matrix. Should densifying be considered a bug? also cc @thomasjpfan as a potential todo.

  11. mitar commented on Mar 27, 2020

    @mitar
    Contributor

    So currently sparse Pandas DataFrames are supported only if all columns are sparse. What about supporting mixed case where dense columns could be converted to sparse ones?

  12. thomasjpfan commented on Apr 5, 2020

    @thomasjpfan
    Member

    What kind of behavior would be reasonable for the mixed case?

  13. mitar commented on Apr 5, 2020

    @mitar
    Contributor

    Making dense columns into sparse columns, I would say, and then everything into sparse?

  14. jnothman commented on Apr 5, 2020

    @jnothman
    Member
  15. mitar commented on Apr 5, 2020

    @mitar
    Contributor

    That would be ideal, but it might be hard to know in advance?

  16. TomAugspurger commented on Apr 6, 2020

    @TomAugspurger
    Contributor

    I don't think trying to guess here is a good idea. I would direct the user to process the dense and sparse subsets independently using a ColumnTrasformer. Or if they really want them processed together then the user should convert the dense to sparse ahead of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions