Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hexbyte-lab
Copy link

  • Add validation in _validate_steps to check for uninstantiated classes
  • Raise clear TypeError suggesting to use ClassName() instead of ClassName
  • Add test to verify the improved error message

Reference Issues/PRs

Fixes #32719

What does this implement/fix? Explain your changes.

This PR improves the error message when a user accidentally passes an uninstantiated class to a Pipeline step instead of an instance.

Before (confusing error):
AttributeError: 'numpy.ndarray' object has no attribute '_validate_params'

After (clear error):
TypeError: All steps should be estimator instances (objects), not classes.
Step 'pca' is a class: (PCA). Did you forget parentheses?
Use PCA() instead of PCA.

Changes made:

  • Added validation in _validate_steps() to check if a step is a class using inspect.isclass()
  • Raises a clear TypeError with a helpful message
  • Added test test_pipeline_step_class_instead_of_instance() to verify the improved error message

Any other comments?

This is my first contribution to scikit-learn. I've manually reviewed all changes and run the full test suite. All pipeline tests pass (141 passed, 5 skipped). Please let me know if any changes are needed!

- Add validation in _validate_steps to check for uninstantiated classes
- Raise clear TypeError suggesting to use ClassName() instead of ClassName
- Add test to verify the improved error message

Fixes scikit-learn#32719
@github-actions
Copy link

github-actions bot commented Nov 16, 2025

✔️ Linting Passed

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

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

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.

Failure to insert instantiated class of estimator in Pipeline produces an unclear error message

1 participant