Skip to content

TST move check_n_features_in_after_fitting to common tests #29844

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

Conversation

adrinjalali
Copy link
Member

Move the test to common tests and include it in the API checks.

Copy link

github-actions bot commented Sep 14, 2024

✔️ Linting Passed

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

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

@pytest.mark.parametrize(
"estimator", _tested_estimators(), ids=_get_check_estimator_ids
)
def test_check_n_features_in_after_fitting(estimator):
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to common tests

@@ -411,6 +411,14 @@ def predict_proba(self, X):
def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
tags.classifier_tags.multi_label = True
tags.input_tags.pairwise = self.metric == "precomputed"
Copy link
Member Author

Choose a reason for hiding this comment

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

no idea why this was missing

Comment on lines 2022 to 2023
X = _enforce_estimator_tags_X(estimator, X)
y = _enforce_estimator_tags_y(estimator, y)
Copy link
Member Author

Choose a reason for hiding this comment

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

a bunch of these came up since now we're testing pairwise data classifieries in common tests which I guess we were not before.

@@ -3925,6 +3960,27 @@ def check_n_features_in_after_fitting(name, estimator_orig):
]
X_bad = X[:, [1]]

err_msg = (
"`{name}.{method}()` does not check for consistency between input number "
Copy link
Member Author

Choose a reason for hiding this comment

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

with these long comments, I want to make it very easy for people to fix issues and as as a result follow our API. I'll create more PRs extending our error messages with fix suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of using "\n" everywhere, can we use this pattern:

    err_msg = textwrap.dedent("""\
    This is
    my
    multiple
    line 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.

I've used this format in other places I think, but I find it very ugly, since due to indentation it needs to be sth like:

def g():
    err_msg = """This
is
my
message"""
    print(err_msg)

Copy link
Member

@thomasjpfan thomasjpfan Sep 19, 2024

Choose a reason for hiding this comment

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

With textwrap.dedent, you can indent without any ugly formatting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, but note that this adds a newline at the beginning and the end of the message (not important to me)

@@ -753,10 +753,6 @@ def test_check_estimator():
msg = "object has no attribute 'fit'"
with raises(AttributeError, match=msg):
check_estimator(BaseEstimator())
# check that fit does input validation
msg = "Did not raise"
with raises(AssertionError, match=msg):
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 now redundant, tested in another test in the same file.

@adrinjalali adrinjalali marked this pull request as ready for review September 17, 2024 08:59
@adrinjalali
Copy link
Member Author

cc @OmarManzoor @adam2392

@adrinjalali adrinjalali added No Changelog Needed Developer API Third party developer API related labels Sep 17, 2024
Copy link
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 @adrinjalali

@OmarManzoor OmarManzoor added the Waiting for Second Reviewer First reviewer is done, need a second one! label Sep 19, 2024
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

Copy link
Member

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
@adrinjalali adrinjalali enabled auto-merge (squash) September 23, 2024 16:34
@adrinjalali adrinjalali merged commit 74a3375 into scikit-learn:main Sep 23, 2024
28 checks passed
@adrinjalali adrinjalali deleted the tests/check_n_features_in_after_fitting branch September 23, 2024 19:07
kbharat1210 pushed a commit to kbharat1210/scikit-learn that referenced this pull request Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer API Third party developer API related module:utils No Changelog Needed 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.

4 participants