Skip to content

loc: label index does not raise KeyError with list of ints #3449

@kyleam

Description

@kyleam

I didn't expect the last line of code to pass.

import numpy as np
import pandas as pd

pd.__version__
#[Out]# '0.12.0.dev-5c3ccdb'

np.random.seed(33)
df = pd.DataFrame(np.random.random((3, 3)),
                  index=['a', 'b', 'c'],
                  columns=['e', 'f', 'g'])

# raise a KeyError?
df.loc[[1, 2], [1, 2]]
#[Out]#           f         g
#[Out]# b  0.870396  0.185040
#[Out]# c  0.953252  0.680451

Being strictly label based, shouldn't loc fail when it doesn't find 1 or 2 as a label?

Metadata

Metadata

Assignees

Labels

BugIndexingRelated 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