Skip to content

DOC: Index.get_loc Cannot Accept List-like Tolerance #20930

Closed
@WillAyd

Description

@WillAyd

The docs for Index.get_loc suggest that the tolerance parameter may accept both a scalar and list-like argument. However, I don't think this is actually possible:

# Can only pass scalar label to unique Index, so tolerance cannot be list-like
>>> pd.Index([0, 1, 2]).get_loc(1)
1
>>> pd.Index([0, 1, 2]).get_loc([1, 1])
TypeError: '[1, 1]' is an invalid key

# Inexact matches do not work against non-unique index
>>> pd.Index([1, 1, 2]).get_loc(1.1, method='nearest')
pandas.core.indexes.base.InvalidIndexError: Reindexing only valid with uniquely valued Index objects

In short I don't think this method can ever return a list using inexact matches. IIUC the documented list-like tolerance argument is therefore invalid.

I don't see any tests for this behavior and my assumption is it was documented as part of this methods overlap with get_indexer, but the documentation for get_loc should be updated to reflect what can actually be accepted

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions