No implicit casting of int -> float on full indexing of multiindex · Issue #15994 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
In [2]: mi = pd.MultiIndex.from_product([[0., 1.], ['begin', 'end']])
In [3]: mi.get_loc(1) Out[3]: slice(2, 4, None)
In [4]: mi.get_indexer_for([(1, 'end')]) Out[4]: array([3])
In [5]: mi.get_loc((1, 'end'))
KeyError Traceback (most recent call last) in () ----> 1 mi.get_loc((1, 'end'))
/home/pietro/nobackup/repo/pandas/pandas/indexes/multi.py in get_loc(self, key, method) 1962 key = _values_from_object(key) 1963 key = tuple(map(_maybe_str_to_time_stamp, key, self.levels)) -> 1964 return self._engine.get_loc(key) 1965 1966 # -- partial selection or non-unique index
/home/pietro/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.MultiIndexEngine.get_loc (pandas/_libs/index.c:13171)()
/home/pietro/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.MultiIndexEngine.get_loc (pandas/_libs/index.c:13018)()
/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.MultiIndexHashTable.get_item (pandas/_libs/hashtable.c:23625)()
/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.MultiIndexHashTable.get_item (pandas/_libs/hashtable.c:23578)()
KeyError: (1, 'end')
Problem description
We implicitly cast if indexing only one level, and if asking a list of (complete) keys: we should do the same for a single complete key.
Expected Output
In [6]: mi.get_loc((1., 'end')) Out[6]: 3
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.0-1-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8
pandas: 0.19.0+783.gcd35d22a0.dirty
pytest: 3.0.6
pip: 9.0.1
setuptools: 33.1.1
Cython: 0.25.2
numpy: 1.12.0
scipy: 0.18.1
xarray: 0.9.1
IPython: 5.1.0.dev
sphinx: 1.4.9
patsy: 0.3.0-dev
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
feather: 0.3.1
matplotlib: 2.0.0
openpyxl: 2.3.0
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.6
lxml: 3.7.1
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: 0.2.1