Skip to content

UInt64Index: lookup by label gives KeyError for values over 2**63-1 #19399

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

Closed
mdickinson opened this issue Jan 25, 2018 · 2 comments
Closed

UInt64Index: lookup by label gives KeyError for values over 2**63-1 #19399

mdickinson opened this issue Jan 25, 2018 · 2 comments
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite
Milestone

Comments

@mdickinson
Copy link

mdickinson commented Jan 25, 2018

[From a StackOverflow question]

Lookup in a UInt64Index appears to fail for values larger than 2**63-1 (but smaller than 2**64). Here's a simple example session (Pandas 0.22.0, Python 3.6.)

>>> import pandas as pd
>>> s = pd.Series({0x7fff_ffff_ffff_ffff: 3, 0x8000_0000_0000_0000: 4})
>>> type(s.index)
<class 'pandas.core.indexes.numeric.UInt64Index'>
>>> s.loc[0x7fff_ffff_ffff_ffff]
3
>>> s.loc[0x8000_0000_0000_0000]
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py", line 1505, in _has_valid_type
    if not ax.contains(key):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 1716, in contains
    return key in self._engine
  File "pandas/_libs/index.pyx", line 81, in pandas._libs.index.IndexEngine.__contains__
  File "pandas/_libs/hashtable_class_helper.pxi", line 591, in pandas._libs.hashtable.UInt64HashTable.__contains__
OverflowError: Python int too large to convert to C long

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py", line 1373, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py", line 1626, in _getitem_axis
    self._has_valid_type(key, axis)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py", line 1514, in _has_valid_type
    error()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py", line 1501, in error
    axis=self.obj._get_axis_name(axis)))
KeyError: 'the label [9223372036854775808] is not in the [index]'

I would have expected the second lookup to succeed, returning 4.

Output of pd.show_versions()

>>> pd.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.6.4.final.0 python-bits: 64 OS: Darwin OS-release: 17.3.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 36.8.0
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@mdickinson mdickinson changed the title UInt64Index: lookup by label gives traceback for values over 2**63-1 UInt64Index: lookup by label gives KeyError for values over 2**63-1 Jan 25, 2018
@mroeschke
Copy link
Member

This looks fixed on master. Do we have tests for this @gfyoung?

In [1]: >>> import pandas as pd
   ...: >>> s = pd.Series({0x7fff_ffff_ffff_ffff: 3, 0x8000_0000_0000_0000: 4})
   ...:
   ...:

In [2]: >>> s.loc[0x7fff_ffff_ffff_ffff]
Out[2]: 3

In [3]: >>> s.loc[0x8000_0000_0000_0000]
Out[3]: 4

@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions good first issue labels Nov 23, 2018
@gfyoung
Copy link
Member

gfyoung commented Nov 23, 2018

@mroeschke : Similar, but not exactly like this. Would be good to just add this.

gfyoung added a commit to forking-repos/pandas that referenced this issue Nov 23, 2018
@gfyoung gfyoung added Testing pandas testing functions or related to the test suite and removed Needs Tests Unit test(s) needed to prevent regressions good first issue labels Nov 23, 2018
@jreback jreback added this to the 0.24.0 milestone Nov 25, 2018
jreback pushed a commit that referenced this issue Nov 25, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this issue Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this issue Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

4 participants