Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lucyleeow
Copy link
Member

@lucyleeow lucyleeow commented Nov 9, 2023

What does this implement/fix? Explain your changes.

_ensure_sparse_format is used to check X and y and other parameters but the warning says:

Use X.toarray() convert to a dense numpy array."

This updates the warning to "Use '.'toarray()'" because it is possible that it was not X that needs to be converted (and even so, the user has not necessarily named the data X).

@github-actions
Copy link

github-actions bot commented Nov 9, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: eee4b20. Link to the linter CI: here

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()' "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I assume that it can be a sparse matrix or array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't follow?

Copy link
Member

@lesteve lesteve Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you, I did not know the difference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used 'sparse data' as I think that is enough info but happy to change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@glemaitre glemaitre changed the title Amend warning in _ensure_sparse_format FIX improve warning message in _ensure_sparse_format Nov 9, 2023
@lucyleeow
Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document the public function that is impacted.

Suggested change
- |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

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise.

@glemaitre
Copy link
Member

Thanks @lucyleeow

@lucyleeow
Copy link
Member Author

Changes made, thanks!

@lucyleeow lucyleeow added the Waiting for Second Reviewer First reviewer is done, need a second one! label Nov 13, 2023
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still good to me. @lesteve do you want to have a new look at it.

@lesteve lesteve merged commit 926671b into scikit-learn:main Nov 14, 2023
@lesteve
Copy link
Member

lesteve commented Nov 14, 2023

Merging, thanks!

@lucyleeow lucyleeow deleted the prf_rm_none branch November 15, 2023 00:55
@lucyleeow
Copy link
Member Author

Thanks for the reviews!

REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:utils Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants