New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No implicit casting of int -> float on full indexing of multiindex #15994

Closed
toobaz opened this Issue Apr 14, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@toobaz
Member

toobaz commented Apr 14, 2017

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)
<ipython-input-5-eb387fc9b362> in <module>()
----> 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

@toobaz

This comment has been minimized.

Member

toobaz commented Apr 14, 2017

Forgot to mention: this emerged in some code which ran fine some months ago, so I think it is a regression (where "I think" means "I'm not 100% sure the difference in behaviour comes from the portion of my code affected by this bug").

@jorisvandenbossche

This comment has been minimized.

Member

jorisvandenbossche commented Apr 14, 2017

In any case, the isolated example you show is clearly a regression:

In [5]: pd.__version__
Out[5]: '0.19.2'

In [6]: mi = pd.MultiIndex.from_product([[0., 1.], ['begin', 'end']])

In [7]: mi.get_loc((1, 'end'))
Out[7]: 3
In [19]: pd.__version__
Out[19]: '0.19.0+783.g7453b63'

In [20]: mi = pd.MultiIndex.from_product([[0., 1.], ['begin', 'end']])

In [21]: mi.get_loc((1, 'end'))
...
KeyError: (1, 'end')

@jorisvandenbossche jorisvandenbossche added this to the 0.20.0 milestone Apr 14, 2017

@jreback jreback modified the milestones: Next Minor Release, 0.20.0 Apr 14, 2017

@toobaz

This comment has been minimized.

Member

toobaz commented Apr 14, 2017

In any case, the isolated example you show is clearly a regression:

Indeed, git bisect points at e351ed0

@jreback jreback modified the milestones: Interesting Issues, Next Major Release Nov 26, 2017

@toobaz toobaz referenced this issue Jan 4, 2018

Merged

REF: codes-based MultiIndex engine #19074

3 of 3 tasks complete

@jreback jreback modified the milestones: Next Major Release, 0.23.0 Jan 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment