DOC: clarify scalar vs list-like return types for .loc and []#65642
Merged
Conversation
closes pandas-dev#46593 Extend the indexing basics table with rows for the list-like ``DataFrame`` cases, and add a short note to the ``.loc`` docstring explaining that the *form* of the indexer (scalar vs. list-like) is what determines the return type, with the duplicate-labels exception called out. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mroeschke
reviewed
May 15, 2026
| - A ``callable`` function with one argument (the calling Series or | ||
| DataFrame) and that returns valid output for indexing (one of the above) | ||
|
|
||
| The *form* of the indexer, not the number of items it selects, |
Member
There was a problem hiding this comment.
Could we show this as an example instead (note: I'm generally more fond of using Examples w/ doctest to ensure what we're describing doesn't go stale)
CloseChoice
approved these changes
May 16, 2026
Member
CloseChoice
left a comment
There was a problem hiding this comment.
Since I was mentioned in the PR description, I'll leave a review here. Take it for what you deem it's worth.
As mentioned by @mroeschke I would also appreciate an example + doctest. Otherwise this looks good and exactly what I had in mind when writing the referenced comment.
Per reviewer feedback (@mroeschke, @CloseChoice), swap the prose paragraph for a doctest-checked example pair contrasting ``df.loc[:, "max_speed"]`` (Series) with ``df.loc[:, ["max_speed"]]`` (DataFrame), so the documented behavior can't drift from reality. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mroeschke
approved these changes
May 16, 2026
Member
|
Thanks @jbrockmendel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #46593
Summary
frame[[colname]]andframe[list_of_colnames](per @CloseChoice's suggestion in DOC: .loc improvement #46593)..locdocstring explaining that the form of the indexer (scalar vs. list-like) determines the return type, with the duplicate-labels exception spelled out.Test plan
pandas/core/indexing.py(9 passed)pre-commitclean on changed files