Skip to content

Conversation

@gdacciaro
Copy link
Contributor

@gdacciaro gdacciaro commented Nov 3, 2024

Reference Issues/PRs
Fixes #30197
This pull request addresses the issue reported in scikit-learn issue #30197, where an IndexError occurs when attempting to access the last estimator in an empty Pipeline.
The current implementation raises an "out of range" error when the steps attribute is empty, which does not provide sufficient context for users.

Changes

  • Modified sklearn/pipeline.py:

    • Updated _estimator_type method to return None if the pipeline is empty.
    • Updated sklearn_tags method to return tags if the pipeline is empty.
  • Added tests in sklearn/tests/test_pipeline.py:

    • Test for _estimator_type with classifier and regressor.
    • Test for _estimator_type when the last step is not an estimator.
    • Test for _estimator_type in an empty pipeline.
    • Test for sklearn_tags with an empty pipeline.

@github-actions
Copy link

github-actions bot commented Nov 3, 2024

✔️ Linting Passed

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

Generated for commit: 67bd522. Link to the linter CI: here

@gdacciaro gdacciaro changed the title ENH - add informative error for empty Pipeline in _estimator_type property FIX - rendering html from an empty pipeline Nov 4, 2024
Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

we should also add a test to make sure repr and html repr of the empty pipeline don't raise.

@gdacciaro
Copy link
Contributor Author

Hey @adrinjalali, the PR is completed on my end. Please let me know if any further reviews are needed. Thank you!

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

LGTM. cc @glemaitre for the second review.

@glemaitre glemaitre self-requested a review November 7, 2024 16:59
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.

So here a couple comments just to simplify a bit the tests but otherwise it looks good.

@gdacciaro
Copy link
Contributor Author

I have committed the suggestions, thank you very much!
@glemaitre

@glemaitre glemaitre self-requested a review November 8, 2024 09:33
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.

I just pushed a small fix to make the linter happy by removing a trailing space.

@glemaitre glemaitre changed the title FIX - rendering html from an empty pipeline FIX handle empty steps in Pipeline Nov 8, 2024
@glemaitre glemaitre enabled auto-merge (squash) November 8, 2024 09:36
@glemaitre
Copy link
Member

Enabling auto-merge

@glemaitre glemaitre added this to the 1.6 milestone Nov 8, 2024
@glemaitre glemaitre added the To backport PR merged in master that need a backport to a release branch defined based on the milestone. label Nov 8, 2024
@glemaitre
Copy link
Member

adding the label "To Backport" and the milestone to not forget this PR.

@glemaitre glemaitre merged commit 6ce072a into scikit-learn:main Nov 8, 2024
33 checks passed
glemaitre added a commit that referenced this pull request Nov 8, 2024
Co-authored-by: Adrin Jalali <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
@glemaitre
Copy link
Member

Backported in 1.6.X

@gdacciaro gdacciaro deleted the fix/empty-pipeline-informative-error branch November 8, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:pipeline To backport PR merged in master that need a backport to a release branch defined based on the milestone.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception on rendering html empty pipeline

3 participants