Skip to content

FIX Removes validation in __init__ for Pipeline - #21888

Merged
thomasjpfan merged 5 commits into
scikit-learn:mainfrom
arisayosh:Issue-21406
Dec 10, 2021
Merged

thomasjpfan merged 5 commits into
scikit-learn:mainfrom
arisayosh:Issue-21406

Conversation

@arisayosh

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Relates to issue #21406

What does this implement/fix? Explain your changes.

  1. Removed validation from __init__ by removing self.__validate_steps()
  2. Modified test_pipeline_init function in test_pipeline.py to test in .fit() instead of __init__

Any other comments?

Curious if we should instead create another function test_pipeline_fit for our changes since we are testing some of the parameters during fit and not init.

@ogrisel ogrisel left a comment

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.

Thank for the pull request! Can you please update the tests to check that the exceptions can only be raised in the fit method below?

Also document this change in the doc/whats_new/v1.1.rst by taking example to other PRs that address part of #21406.

Comment thread sklearn/tests/test_pipeline.py Outdated
# Test the various init parameters of the pipeline.
with pytest.raises(TypeError):
Pipeline()
Pipeline().fit([[1]], [1])

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.

Can you please rewrite those test to make it explicit that the error is raised in fit?

    pipeline = Pipeline()
    with pytest.raises(TypeError):
        pipeline.fit([[1]], [1])

@arisayosh arisayosh Dec 7, 2021 •

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.

Hi @ogrisel, thank you for reviewing. Would you like me to edit so that the above is done for each instance of pipeline in the test file?

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.

Yes.

@arisayosh

Copy link
Copy Markdown
Contributor Author

Thank you @ogrisel for the review. Will fix the changes and document them in that file.

What are your thoughts on creating a new test function for those that are tested in .fit()?

@ogrisel

ogrisel commented Dec 7, 2021

Copy link
Copy Markdown
Member

What are your thoughts on creating a new test function for those that are tested in .fit()?

That's a very good point. test_pipeline_init is a bad test for checking exception raised in fit on invalid paramaters. Let's move those assertions to a dedicated test named test_pipeline_invalid_parameters.


def test_pipeline_init():
# Test the various init parameters of the pipeline.
def test_pipeline_invalid_parameters():

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.

Renamed function since we are not validating parameters during instantiation. We decided not to split the function in two because it caused code repetition.

@arisayosh arisayosh changed the title [WIP] ENH Removes validation in __init__ for Pipeline FIX Removes validation in __init__ for Pipeline Dec 8, 2021

@ogrisel ogrisel left a comment

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.

LGTM. Thanks for the PR @arisayosh!

Comment thread doc/whats_new/v1.1.rst Resolved
Co-authored-by: Olivier Grisel <[email protected]>

@thomasjpfan thomasjpfan left a comment

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.

Thank you for the PR @arisayosh !

LGTM

@thomasjpfan
thomasjpfan merged commit 0110921 into scikit-learn:main Dec 10, 2021
@arisayosh

Copy link
Copy Markdown
Contributor Author

This was a combined effort with @iofall! Thank you for the reviews @ogrisel and @thomasjpfan :)

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