-
-
Notifications
You must be signed in to change notification settings - Fork 26.1k
FIX _safe_indexing: improve error message for string indexing on axis=0 #31494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX _safe_indexing: improve error message for string indexing on axis=0 #31494
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should enable pre-commit
hooks to fix your linting issues in your commits.
sklearn/utils/_indexing.py
Outdated
raise ValueError( | ||
f"String indexing (indices={indices}) is not supported with 'axis=0'. Did you mean to use axis=1 for column selection?" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError( | |
f"String indexing (indices={indices}) is not supported with 'axis=0'. Did you mean to use axis=1 for column selection?" | |
) | |
raise ValueError( | |
f"String indexing (indices={indices}) is not supported with 'axis=0'. " | |
"Did you mean to use axis=1 for column selection?" | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Roshangoli
This PR makes the ValueError from sklearn.utils._indexing._safe_indexing more informative
when a string index is passed with axis=0. The new message shows the actual value of
indices
and suggests using axis=1 for column selection.ValueError(f"String indexing (indices={indices}) is not supported with 'axis=0'. "
"Did you mean to use axis=1 for column selection?")
(using a regex).
All existing indexing tests now pass. The only local test failure is test_openmp_parallelism_enabled,
which can be ignored on macOS; CI will run on Linux with OpenMP support.