Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
import pandas as pd
import numpy as np
ser = pd.Series([1, 2, 3])
arr8 = np.array([4], dtype=np.uint8)
arr16 = np.array([4], dtype=np.uint16)
arr32 = np.array([4], dtype=np.uint32)
arr64 = np.array([4], dtype=np.uint64)
print(ser[arr8]) # prints random number, probably out-of-bounds memory address
print(ser[arr16]) # prints random number, probably out-of-bounds memory address
print(ser[arr32]) # segfault
print(ser[arr64]) # correctly returns a KeyError
Problem description
Indexing into a Series without .iloc
or .loc
using an unsigned integer that points outside of the Series sometimes results in pandas returning some bogus value, and sometimes causes a segfault. I wasn't able to reproduce this behavior with signed integer arrays.
Expected Output
I assume that these queries should return a KeyError.
Output of pd.show_versions()
I confirmed the bug with the following two versions:
INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.147-1-MANJARO
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_IL.UTF-8
LOCALE : en_IL.UTF-8
pandas : 1.0.3
numpy : 1.17.1
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.2.0
Cython : 0.29.19
pytest : 5.1.2
hypothesis : None
sphinx : 2.4.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.1
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.1.2
pyxlsb : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : 0.15.1
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.45.1
INSTALLED VERSIONS
commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.147-1-MANJARO
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_IL.UTF-8
LOCALE : en_IL.UTF-8
pandas : 1.0.3
numpy : 1.17.1
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.2.0
Cython : 0.29.19
pytest : 5.1.2
hypothesis : None
sphinx : 2.4.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.1
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.1.2
pyxlsb : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : 0.15.1
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.45.1