PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices
See original GitHub issueWhen running a the test suite we get a number PendingDeprecationWarning
,
PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
return matrix(data, dtype=dtype, copy=False)
See for instance https://ci.appveyor.com/project/sklearn-ci/scikit-learn/builds/19341228/job/q6rysq7flma8hi6v Warnings seems to be hidden on Travis so we don’t see those there.
This typically happens when we have a sparse matrix, sum along one axis to get a dense one, than do some mathematical operation with this matrix. It should be explicitly converted to an array first.
This has also been reported by @drorata in https://github.com/scikit-learn/scikit-learn/pull/11251#issuecomment-427865173. There was previous discussion about this in https://github.com/scikit-learn/scikit-learn/pull/11251 but it doesn’t look like it’s fixed. I also saw this recently when running PyPy CI.
To investigate where this happen it’s sufficient to run pytest tests with -Werror::PendingDeprecationWarning
to error on those warnings, as they don’t seem to be raised with the right stacklevel (see also https://github.com/scikit-learn/scikit-learn/issues/7963#issuecomment-265420200 for workarounds)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:42 (36 by maintainers)
Top GitHub Comments
It’s not a regression, and not a blocker for 0.20.1 (please feel free to untag it), but it still fairly annoying as it means we get
PendingDeprecationWarning
when using the latest scipy and it’s better to fix that as soon as possible.In my case, within my code, changing from “
.todense()
” to “.toarray()
” for sparse matrices removed the warnings. As well as “.sum()
” over the some axis on sparse matrix are converted to np.matrix. Here may lie the specific problem. This last one forced me to convert sparse matricestoarray
or only by adding use a redefinition with the following function (not fully implemented):If you avoid them, you avoid the warnings with pytest. Hope my toc helps someone.