Skip to content

FIX Fixes common test for requires_positive_X #24667

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

Merged
merged 5 commits into from
Oct 26, 2022

Conversation

thomasjpfan
Copy link
Member

Reference Issues/PRs

Fixes #24659

What does this implement/fix? Explain your changes.

This PR fixes the common tests to pass when requires_positive_X is True. Updates include:

  1. Rename _enforce_estimator_tags_x to _enforce_estimator_tags_X
  2. Put _pairwise_estimator_convert_X into _enforce_estimator_tags_x so there is a single entry point to "adjust X".
  3. SkewedChi2Sampler with skewedness=1.0 is a strange case where it accepts negative values in fit but not in transform. This estimator is special cased in _enforce_estimator_tags_X.


# Check regressor with requires_positive_X estimator tag
msg = "negative X values not supported!"
with raises(ValueError, match=msg):
check_estimator(RequiresPositiveXRegressor())
check_estimator(RequiresPositiveXRegressor())
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the non-regression test. check_estimator should pass if the estimator requires positive X.

X = _enforce_estimator_tags_x(estimator, X)
X = _pairwise_estimator_convert_X(X, estimator)
X = _enforce_estimator_tags_X(estimator, X)
X = _enforce_estimator_tags_X(estimator, X)
Copy link
Member

Choose a reason for hiding this comment

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

Double double trouble? I think one line can be removed.

Copy link
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.

I like the "normalisation" of using an upper case X and that it fixes the bug. On the rest I don't have a strong opinion (+0).

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. Thanks @thomasjpfan

@glemaitre
Copy link
Member

I will merge main on this branch to be sure that the tests are still passing but it looks good.

@glemaitre glemaitre merged commit 7dc7f8a into scikit-learn:main Oct 26, 2022
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Oct 31, 2022
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
andportnoy pushed a commit to andportnoy/scikit-learn that referenced this pull request Nov 5, 2022
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
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.

check_classifiers_train fails when tag requires_positive_X=True
3 participants