Skip to content

TST Extend tests for scipy.sparse.*array in sklearn/utils/tests/test_class_weight.py#27188

Merged
OmarManzoor merged 2 commits intoscikit-learn:mainfrom
yuanx749:sparse-class-weight
Aug 28, 2023
Merged

TST Extend tests for scipy.sparse.*array in sklearn/utils/tests/test_class_weight.py#27188
OmarManzoor merged 2 commits intoscikit-learn:mainfrom
yuanx749:sparse-class-weight

Conversation

@yuanx749
Copy link
Copy Markdown
Contributor

Towards #27090.

Reference Issues/PRs

What does this implement/fix? Explain your changes.

Any other comments?

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 28, 2023

✔️ Linting Passed

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

Generated for commit: 8bc23f8. Link to the linter CI: here

Comment on lines +160 to +165
if sparse.issparse(y):
# Ok to densify a single column at a time
y_full = y_full.toarray().flatten()
# 1D sparse slices not yet implemented
y_full = y[:, [k]].toarray().flatten()
else:
y_full = y[:, k]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed the source code in this way because:

  1. y[:, k] raises NotImplementedError for sparse array.
  2. But for dense array, y[:, [k]] results in 2D array and break other tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me for now. If we have to repeat this pattern several times in other PRs, we should factorize this as a utility function somewhere under sklearn.utils.

Copy link
Copy Markdown
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the PR.

Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Copy link
Copy Markdown
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @yuanx749

@OmarManzoor OmarManzoor merged commit 407070b into scikit-learn:main Aug 28, 2023
@yuanx749 yuanx749 deleted the sparse-class-weight branch August 28, 2023 10:26
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Aug 29, 2023
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants