Skip to content

API: should .loc be as strict as .ix in tuple indexing? #3390

Closed
@jreback

Description

@jreback

from ML

https://groups.google.com/forum/?fromgroups=#!topic/pydata/fzPGjVrj9lU

df = pd.DataFrame.from_items([('a', [1,2]), ('b', ([3,4]))])
df.index = pd.MultiIndex.from_tuples([('A', 'B'),('C', 'D')],
        names=['k1', 'k2'])

# A dataframe, with a multiindex:
>>> df
       a  b
k1 k2
A  B   1  3
C  D   2  4

.ix[('A','B')] succeeds
.ix['A','B'] succeeds as the A, B is tried as a tuple (.ix tries hard here)

propose that we change .loc to disallow the 2nd case and instead raise a KeyError
its more 'strict'

Metadata

Metadata

Assignees

No one assigned

    Labels

    IdeasLong-Term Enhancement DiscussionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions