FIX Use check_same_namespace in PCA array API validation - #34493
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
Reformat code for better readability by adjusting line breaks.
betatim
left a comment
There was a problem hiding this comment.
Thanks for working on this and taking the time to engage with the discussion in the issue!
I think this looks good as a fix. I think we should merge it.
One additional thing to do: can you remove the xfail for PCA for the check_array_api_same_namespace test (in sklearn/utils/_test_common/instance_generator.py)? That test should fail on main and pass with your patch
|
I also just noticed that their are conflicts in |
|
Hi @betatim , I have successfully resolved the merge conflicts, fixed the styling imports, and removed the PCA xfail from the test generator. |
Reference Issues/PRs
Fixes #34483
What does this implement/fix? Explain your changes.
Currently,
PCA.transformandPCA.inverse_transformcallget_namespace(X, self.components_, ...)directly, which throws a genericTypeErrorwhen namespaces do not match.This PR aligns
PCAwith linear models (likeRidge) by explicitly calling thecheck_same_namespaceutility first. This ensures users receive the standard, informativeValueErrorwhen passing arrays from different namespaces after calling.fit().First time contributor introduction
Hi everyone! I am an entry-level AI/ML engineer with a background in electronics and communication. I have used scikit-learn extensively throughout my projects and studies, and I am excited to finally start contributing back to the library that I rely on so heavily!
AI usage disclosure
I used AI assistance for:
Any other comments?
As noted by @StefanieSenger in the original issue thread, I understand there is an ongoing broader refactoring for namespace handling across the library by @lucyleeow. This PR is intended as a quick, targeted alignment for PCA to match linear models in the short term. If the broader design ends up superseding this patch globally later on, I completely understand if this PR gets closed in favor of that larger solution!