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

Skip to content

FIX Use check_same_namespace in PCA array API validation - #34493

Merged
ogrisel merged 5 commits into
scikit-learn:mainfrom
ajayraj30002:ajayraj30002-patch-PCA-Array-API
Aug 18, 2026
Merged

FIX Use check_same_namespace in PCA array API validation#34493
ogrisel merged 5 commits into
scikit-learn:mainfrom
ajayraj30002:ajayraj30002-patch-PCA-Array-API

Conversation

@ajayraj30002

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #34483

What does this implement/fix? Explain your changes.

Currently, PCA.transform and PCA.inverse_transform call get_namespace(X, self.components_, ...) directly, which throws a generic TypeError when namespaces do not match.

This PR aligns PCA with linear models (like Ridge) by explicitly calling the check_same_namespace utility first. This ensures users receive the standard, informative ValueError when 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:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Research and understanding

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!

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

@github-actions github-actions Bot added module:decomposition CI:Linter failure The linter CI is failing on this PR labels Jul 16, 2026
Reformat code for better readability by adjusting line breaks.
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Jul 16, 2026

@betatim betatim 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.

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

@betatim

betatim commented Aug 3, 2026

Copy link
Copy Markdown
Member

I also just noticed that their are conflicts in sklearn/decomposition/_base.py, can you resolve those as well please?

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Aug 11, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Aug 11, 2026
@ajayraj30002

Copy link
Copy Markdown
Contributor Author

Hi @betatim , I have successfully resolved the merge conflicts, fixed the styling imports, and removed the PCA xfail from the test generator.

@ogrisel ogrisel moved this to In Progress in Array API Aug 18, 2026
@ogrisel
ogrisel enabled auto-merge (squash) August 18, 2026 09:12
@ogrisel
ogrisel merged commit 845eaf3 into scikit-learn:main Aug 18, 2026
42 of 43 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Array API Aug 18, 2026
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 8, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

PCA does not follow same namespace checking logic as others

3 participants