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

BUG: Overflow encountered when using .loc with UInt64Index #20722

glemaitre opened this Issue Apr 17, 2018 · 2 comments


None yet
4 participants

glemaitre commented Apr 17, 2018

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> import numpy as np
>>> s = pd.Series([1, 2], index=[np.iinfo('uint64').max - 1, np.iinfo('uint64').max])
>>> s[np.iinfo('uint64').max]
>>> s.loc[np.iinfo('uint64').max]

OverflowError: Python int too large to convert to C long
During handling of the above exception, another exception occurred:

>>> s.index
UInt64Index([18446744073709551614, 18446744073709551615], dtype='uint64')

Problem description

loc leads to an overflow even with consistent dtype (uint64 for the index of the Series and the value pass to loc).

Expected Output

>>> s.loc[np.iinfo('uint64').max]

Output of pd.show_versions()

commit: None
python-bits: 64
OS: Linux
OS-release: 4.13.0-38-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None

pandas: 0.22.0
pytest: 3.3.2
pip: 9.0.1
setuptools: 38.5.1
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: 0.10.1
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jorisvandenbossche jorisvandenbossche changed the title from Overflow encountered when using .loc to BUG: Overflow encountered when using .loc with Uint64Index Apr 17, 2018

@jorisvandenbossche jorisvandenbossche changed the title from BUG: Overflow encountered when using .loc with Uint64Index to BUG: Overflow encountered when using .loc with UInt64Index Apr 17, 2018


This comment has been minimized.


jorisvandenbossche commented Apr 17, 2018

Thanks for the report!
In contrast to loc, getitem works:

In [29]: s[18446744073709551614]
Out[29]: 1

One of the errors is happening in contains:

In [30]: s.index.contains(18446744073709551614)
OverflowError                             Traceback (most recent call last)
<ipython-input-30-cec353dff8b1> in <module>()
----> 1 s.index.contains(18446744073709551614)

/home/joris/scipy/pandas/pandas/core/indexes/ in contains(self, key)
   2008         hash(key)
   2009         try:
-> 2010             return key in self._engine
   2011         except (TypeError, ValueError):
   2012             return False

/home/joris/scipy/pandas/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.__contains__()

/home/joris/scipy/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.UInt64HashTable.__contains__()

OverflowError: Python int too large to convert to C long

cc @gfyoung


This comment has been minimized.

ClemShirestock commented Apr 19, 2018

Ran into this today. One thing to add is that it seems to only happen when passing a scalar to .loc.

df = pd.DataFrame([[1, 2, 3]], pd.UInt64Index([2**63 + 1]))

works fine but


raises the error

@Licht-T Licht-T referenced this issue May 6, 2018


BUG: Fix wrong khash method definition #20966

4 of 4 tasks complete

@jreback jreback added this to the 0.23.0 milestone May 7, 2018

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