Skip to content

API Make _safe_indexing public as safe_indexing - #35295

Open
cakedev0 wants to merge 7 commits into
scikit-learn:mainfrom
cakedev0:public-safe-indexing
Open

cakedev0 wants to merge 7 commits into
scikit-learn:mainfrom
cakedev0:public-safe-indexing

Conversation

@cakedev0

@cakedev0 cakedev0 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixes #27439. Follow-up of the discussion in #32728: _safe_indexing is used by 21 of the ~70 scikit-learn based libraries I surveyed (comment), so we agreed to make it public.

What does this implement/fix? Explain your changes.

  • Rename _safe_indexing to safe_indexing and remove the "documented, but private" warning from its docstring.
  • Keep _safe_indexing as a plain alias (_safe_indexing = safe_indexing), importable from sklearn.utils as before, without a deprecation warning.
  • List safe_indexing instead of _safe_indexing in the API reference, and redirect the old API page to the new one (it is linked from the docs of downstream libraries).
  • Commit 769fc2f renames the internal callers to safe_indexing (34 files, a pure rename).

Why no deprecation for now: most users who would see the warning can't do anything about it, since the call is inside imbalanced-learn, MAPIE, skrub, etc. I propose the following plan:

  1. ship safe_indexing with the _safe_indexing alias for a few releases,
  2. open PRs in the main downstream packages to use the public name (once their minimum supported scikit-learn version has it, or through sklearn-compat),
  3. then deprecate _safe_indexing,
  4. then remove it.

AI usage disclosure

I used AI assistance for:

  • Code generation
  • Research and understanding (the downstream usage survey)

cakedev0 and others added 2 commits November 2, 2026 13:10
`_safe_indexing` stays importable from `sklearn.utils` as a plain alias,
without a warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/L and removed size/M labels Nov 2, 2026
@cakedev0
cakedev0 marked this pull request as draft November 2, 2026 12:17
@cakedev0
cakedev0 marked this pull request as ready for review November 2, 2026 12:30

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

I would make it clear that either _safe_indexing is removed in a future version or at least that it might be removed. Otherwise, we carry on having a semi-public-private function that we deal with as if 100% public. That was never the intention and never communicated.

Comment thread doc/conf.py Resolved
Comment thread sklearn/utils/_indexing.py Resolved
Comment thread sklearn/utils/_indexing.py Resolved
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 2, 2026
add: Maintenance: get [sklearn#35295](scikit-learn/scikit-learn#35295) reviewed (make `_safe_indexing` public as `safe_indexing`)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 2, 2026
todo: move [sklearn#35295](scikit-learn/scikit-learn#35295) from Waiting to Now: address lorentzenchr's review on removing the `_safe_indexing` alias
add: Maintenance: re-review [sklearn#35261](scikit-learn/scikit-learn#35261) (1.10 deprecations in MDS; FrancoisPgm addressed my comments)
todo: betatim's fixes on [sklearn#35053](scikit-learn/scikit-learn#35053), ogrisel asking jjerphan to review [sklearn#34935](scikit-learn/scikit-learn#34935)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cakedev0

cakedev0 commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Yeah we should totally add TODOs in the code to not forget to deprecate then remove it. Thanks @lorentzenchr for the suggestion 👍

I chose 1.14 for deprecation and 1.15 for removal.

cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
todo: move [sklearn#35295](scikit-learn/scikit-learn#35295) from Now to Waiting, lorentzenchr's review addressed
todo: [fork#40](cakedev0/scikit-learn#40) is the fix for the red CI of [sklearn#34339](scikit-learn/scikit-learn#34339), waiting on lorentzenchr

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lorentzenchr lorentzenchr added the Waiting for Second Reviewer First reviewer is done, need a second one! label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:utils size/L Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_safe_indexing being the only *private* thing listed in classes.rst

2 participants