Proposal: deprecate spmatrix.A
See original GitHub issueIs your feature request related to a problem? Please describe.
Sparse matrices copy some parts of the interface from np.matrix
. In particular, I was surprised to learn that spmatrix.A
is an alias to spmatrix.toarray()
. This is extremely similar to np.matrix.A
, in turn equivalent to np.matrix.view(np.ndarray)
. However while in the latter case no data conversion happens, sparse matrices require a conversion, which is expensive both in computation and memory costs. As far as I understand, doing costly calculations on attribute access is not a good pattern and therefore should be discouraged.
Describe the solution you’d like
Emit a DeprecationWarning
, recommending users to switch to .toarray()
and subsequently remove spmatrix.A
in a later version.
Describe alternatives you’ve considered
- Emit a
SparseEfficiencyWarning
, recommending users to switch to.toarray()
to silence the warning and keepspmatrix.A
around. - Do nothing.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
I fear that especially to new users the implications may not be clear. However #14822 is a much better way forward, which removes the need for this proposal.
Thanks for doing this. If you want this topic to move forward, please send an email to the mailing list summarising all the issues you opened around the topic. For API changes and decisions like these we go with the mailing list as explained in our contributing guide.