Repository navigation
FIX improve warning message in _ensure_sparse_format - #27757
Conversation
glemaitre
left a comment
There was a problem hiding this comment.
I am fine with this changes. We need to change the test and still have an entry in the changelog as a fix since it will change the error message.
| if accept_sparse is False: | ||
| raise TypeError( | ||
| "A sparse matrix was passed, but dense data is required. Use X.toarray() " | ||
| "A sparse matrix was passed, but dense data is required. Use '.toarray()' " |
There was a problem hiding this comment.
And I assume that it can be a sparse matrix or array.
There was a problem hiding this comment.
I suppose this is about sparse array vs sparse matrix and that you can get an error mentioning "sparse matrix" when you passed a sparse array. More context in #26418.
Maybe use something like "sparse data" or sparse_container.__class__ in the error message?
There was a problem hiding this comment.
Ah thank you, I did not know the difference.
There was a problem hiding this comment.
I've used 'sparse data' as I think that is enough info but happy to change.
There was a problem hiding this comment.
I've added input_name, if present, to the error message as sometimes more than one argument will be checked (e.g., X and y) and this can help. Happy to change back though.
cc @glemaitre in case this needs re-review.
_ensure_sparse_format_ensure_sparse_format
|
Thanks, changes made! @glemaitre |
| misdetects the CPU architecture. | ||
| :pr:`27614` by :user:`Olivier Grisel <ogrisel>`. | ||
|
|
||
| - |Fix| Error message in :func:`~utils._ensure_sparse_format` when a sparse matrix was |
There was a problem hiding this comment.
Let's document the public function that is impacted.
| - |Fix| Error message in :func:`~utils._ensure_sparse_format` when a sparse matrix was | |
| - |Fix| Error message in :func:`~utils.check_array` when a sparse matrix was |
|
Thanks @lucyleeow |
|
Changes made, thanks! |
|
Merging, thanks! |
|
Thanks for the reviews! |
What does this implement/fix? Explain your changes.
_ensure_sparse_formatis used to checkXandyand other parameters but the warning says:This updates the warning to "Use '.'toarray()'" because it is possible that it was not
Xthat needs to be converted (and even so, the user has not necessarily named the dataX).