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

Index.putmask with an invalid mask causes a crash due to stack overflow #18368

Closed
jschendel opened this Issue Nov 19, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@jschendel
Member

jschendel commented Nov 19, 2017

Code Sample, a copy-pastable example if possible

Seems to happen regardless of the type of index, and for any type of invalid mask.

mask with too few elements:

In [2]: idx = pd.Index(list('abca'))

In [3]: idx.putmask([True, True, False], 'x')
Fatal Python error: Cannot recover from stack overflow.

mask with too many elements:

In [2]: idx = pd.CategoricalIndex(list('abca'))

In [3]: idx.putmask(np.array([True, False]*3), 'c')
Fatal Python error: Cannot recover from stack overflow.

Entirely wrong mask:

In [2]: idx = pd.period_range('2017Q1', periods=4, freq='Q')

In [3]: idx.putmask('foo', 'bar')
Fatal Python error: Cannot recover from stack overflow.

Doesn't appear to be an issue with np.putmask:

In [2]: a = np.arange(5)

In [3]: np.putmask(a, [True, False], -1)
---------------------------------------------------------------------------
ValueError: putmask: mask and data must be the same size

Problem description

An invalid mask in Index.putmask causes a stack overflow.

Expected Output

I'd expect an exception to be raised.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: b00e62c
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0.dev0+159.gb00e62c
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.2
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.0
pandas_gbq: None
pandas_datareader: None

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Nov 19, 2017

Contributor

this almost a directly pass thru to np.putmask, I think we maybe recursing via the conversion to object. PR welcome!

Contributor

jreback commented Nov 19, 2017

this almost a directly pass thru to np.putmask, I think we maybe recursing via the conversion to object. PR welcome!

@jreback jreback modified the milestones: High Level Issue Tracking, Next Major Release Nov 19, 2017

@jreback jreback modified the milestones: Next Major Release, 0.21.1 Nov 25, 2017

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