Skip to content

Deprecate sparse.spmatrix.todense #14494

@akhmerov

Description

@akhmerov

Is your feature request related to a problem? Please describe.

np.matrix is deprecated, and is slowly wiped from the public code. New users, I hope, don't learn what np.matrix is, and that's to the better.

At the same time, sparse matrices have a public interface for creating numpy matrices, which is actually used quite a lot in scipy tests. A new user who is unaware about the existence of numpy matrix type does not have a clear way to anticipate that a matrix is returned, or that it's deprecated. So a possible scenario (from my personal experience, even though I'm not a new user) is that:

  • The user calls spmatrix.todense()
  • The following code either emits a deprecation warning for doing matrix operations, or does the usual confusing stuff with matrix vector multiplication.
  • The user realizes they should have used spmatrix.toarray(), switches to it and carries on.

Describe the solution you'd like

I propose to move towards making .todense an alias for .toarray through a deprecation cycle. This could be done by:

  1. Eliminating .todense from scipy own codebase
  2. Adding a keyword-only argument return_array=False to .todense and emitting a deprecation warning if it isn't set to True.
  3. Making return_array=True a default
  4. Eventually eliminating it and making .todense an alias to .toarray.

Describe alternatives you've considered

Other options are:

  • Keeping todense around until numpy removes it.
  • Making it an alias right away and hoping nobody will notice 🙃 idk

Metadata

Metadata

Assignees

No one assigned

    Labels

    deprecatedItems related to behavior that has been deprecatedscipy.sparse

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions