8000 TST replace pytest.warns(None) in test_label_propagation.py by Ben3940 · Pull Request #22998 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

TST replace pytest.warns(None) in test_label_propagation.py #22998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed

TST replace pytest.warns(None) in test_label_propagation.py #22998

wants to merge 8 commits into from

Conversation

Ben3940
Copy link
Contributor
@Ben3940 Ben3940 commented Mar 30, 2022

Reference Issues/PRs

Part of issue #22572 (Specifically sklearn/semi_supervised/tests/test_label_propagation.py part)

What does this implement/fix? Explain your changes.

Refactored pytest.warns(None) to use warnings.catch_warnings() and warnings.simplefilter("error"). This was done because of a deprecation warning from Pytest for using pytest.warns(None)

Ben3940 and others added 8 commits March 30, 2022 09:23
This commit updates the fit(X, y) definition, in the docs, of the sklearn.covariance.EllipticEnvelope class.
The original definition stated that parameter X could be of type 'array-like' or 'sparse matrix', however,
an error would be thrown if a 'sparse matrix' is passed ("TypeError: A sparse matrix was passed, but dense
data is required.").  To resolve this, 'sparse matrix' was removed from the list of types X could be, in the
docstring.
This commit is part of the process to update the docs on the sklearn.covariance.EllipticEnvelope class's
fit(X, y) definition, as explained in issue #14613.
Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
This commit is to resolve part of issue #22572, specifically, refactoring
test_label_propagation.  This is being done to update the file and address
the deprecation warning from Pytest when using "pytest.warns(None)".
@Ben3940
Copy link
Contributor Author
Ben3940 commented Mar 30, 2022

@thomasjpfan this is the PR for test_label_propagation.py, however, part of the PR contains commits from PR #22997 and I'm not sure why (still new to GitHub and Git). That pull request was reviewed by @jeremiedbb and it says it was merged. I am just pushing this PR in case the commits from PR #22997 were not brought over to the main branch of Sklearn, though I would think they would since GitHub says the PR was merged.

@jeremiedbb
Copy link
Member

@Ben3940 I didn't notice that your PR #22997 was made from the main branch of your fork (this one too btw). We advise to make PRs from a feature branch instead. Here's a guide describing how to properly setup your dev environment: https://scikit-learn.org/dev/developers/contributing.html#how-to-contribute

That said, you can leave this PR as is since we squash all the commits before merging anyway.

@Ben3940
Copy link
Contributor Author
Ben3940 commented Mar 30, 2022

I see, I thought at some point I would have to merge my changes to my fork's main branch before making a PR to Sklearn's main branch. Though with this mess of commits now stringing together, I see why we don't want to work on the main branch. Sorry for the trouble and I am glad to hear that the commits will be dealt with before the merging. Thank you for your help @jeremiedbb.

Copy link
Member
@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

I made a few comments. You also have linting issues. Make sure you run black before pushing new commits.

@@ -151,14 +152,16 @@ def test_convergence_warning():
assert mdl.n_iter_ == mdl.max_iter

mdl = label_propagation.LabelSpreading(kernel="rbf", max_iter=500)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error")
Copy link
Member

Choose a reason for hiding this comment

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

We prefer to explicitely pass the warning category that motivated this check. Based on the content of this test, it seems that it's a ConvergenceWarning

Comment on lines +179 to 180
with warnings.catch_warnings():
mdl.fit(X, y)
Copy link
Member

Choose a reason for hiding this comment

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

You need to add to error on warnings otherwise this is not checking that there's no warning.
you can look at this issue linked in this test to find which warning is expected here (#9292)

@jeremiedbb jeremiedbb added No Changelog Needed Quick Review For PRs that are quick to review labels Mar 31, 2022
@Ben3940
Copy link
Contributor Author
Ben3940 commented Mar 31, 2022

@jeremiedbb I have gone back and made a new branch (test_label_propagation) on my fork of sklearn. I also made the changes you suggested in the comments above (and ran black) and have pushed them to the test_label_propagation branch on my fork. I am not sure how I can add those changes to this PR since it was originally started on my fork's main branch?

I am assuming that we are still wanting to avoid working on my fork's main branch, even in this current mess of a PR.

@jeremiedbb
Copy link
Member

If you already did that, I guess the simplest solution is that you open a new PR from your new branch and then close this one.

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.

2 participants
0