Skip to content

[Mathijs] Task 14 (Windsurf): ENH Make _safe_indexing a public API function by renaming to safe_indexing - #14

Open
dokterbob wants to merge 7 commits into
mainfrom
make-safe-indexing-public
Open

dokterbob wants to merge 7 commits into
mainfrom
make-safe-indexing-public

Conversation

@dokterbob

Copy link
Copy Markdown
Collaborator

Description

This PR addresses issue scikit-learn#27439 by making _safe_indexing public, exposing it like other public functions in the scikit-learn API.

Currently, _safe_indexing is the only private utility function listed in the documentation, which is inconsistent with the project's API design. As discussed in the issue, this function is widely used internally and could be useful for third-party libraries that want to comply with scikit-learn's estimator API.

Changes

  • Renamed _safe_indexing to safe_indexing (removing the leading underscore)
  • Removed the warning about it being a private function from the docstring
  • Maintained backward compatibility by keeping _safe_indexing as a reference to the new public function
  • Added safe_indexing to the __all__ list in sklearn.utils.__init__
  • Updated examples in the docstring to reflect the new public name
  • Updated internal references to use the new name where appropriate

References

Fixes scikit-learn#27439

Additional Information

Backward compatibility is fully preserved as the original _safe_indexing function continues to work as before, now implemented as a thin wrapper around the public API function.

This PR follows all guidelines from scikit-learn's contribution standards.

…exing

This addresses issue scikit-learn#27439 by making _safe_indexing public, exposing it like other public functions. The function was already listed in the documentation despite being marked as private. Backward compatibility is maintained by keeping _safe_indexing as a reference to safe_indexing.
@github-actions

github-actions Bot commented Mar 24, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

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

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

@dokterbob dokterbob changed the title ENH Make _safe_indexing a public API function by renaming to safe_indexing [Mathijs] Task 14: ENH Make _safe_indexing a public API function by renaming to safe_indexing Mar 24, 2025
This change makes the previously private _safe_indexing function a public API by:
- Renaming it to safe_indexing in sklearn.utils._indexing
- Exposing it in sklearn.utils.__init__
- Adding backward compatibility for _safe_indexing
Update test_indexing.py to use the new public API name. This ensures test coverage for the newly exposed function.
Update references in ColumnTransformer and TransformedTargetRegressor to use the public API name.
…fe_indexing

Update references in the permutation importance module to use the public API name.
… _safe_indexing

Update references in the model selection validation module to use the public API name.
Update documentation to reference the new public API name.
@dokterbob
dokterbob force-pushed the make-safe-indexing-public branch 2 times, most recently from e708187 to 4147095 Compare March 24, 2025 11:25
Indexes the data on its second axis. Integers are interpreted as
positional columns, while strings can reference DataFrame columns
by name. A scalar string or int should be used where
by name. A scalar string or int should be used where

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Randomly added whitespace!??

- callable: a scorer callable object (e.g., function) with signature
``scorer(estimator, X, y)``, which should return only a single value.
See :ref:`scoring_callable` for details.
``scorer(estimator, X, y)``. See :ref:`scoring_callable` for details.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Irrelevant change. Possibly due to linter line-length feedback.

If replace is False it should not be larger than the length of
arrays.
automatically set to the first dimension of the arrays. If replace is False it
should not be larger than the length of arrays.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dokterbob dokterbob changed the title [Mathijs] Task 14: ENH Make _safe_indexing a public API function by renaming to safe_indexing [Mathijs] Task 14 (Windsurf): ENH Make _safe_indexing a public API function by renaming to safe_indexing Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant