Skip to content

Commit abc5461

Browse files
committed
Merge pull request #5125 from jtratner/fix-segfault-mi-isnull
BUG: Fix segfault on isnull(MultiIndex)
2 parents e3632f8 + b6222d4 commit abc5461

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ Bug Fixes
584584
- Made sure different locales are tested on travis-ci (:issue:`4918`). Also
585585
adds a couple of utilities for getting locales and setting locales with a
586586
context manager.
587+
- Fixed segfault on ``isnull(MultiIndex)`` (now raises an error instead)
588+
(:issue:`5123`, :issue:`5125`)
587589

588590
pandas 0.12.0
589591
-------------

pandas/core/common.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from numpy.lib.format import read_array, write_array
1313
import numpy as np
1414

15+
import pandas as pd
1516
import pandas.algos as algos
1617
import pandas.lib as lib
1718
import pandas.tslib as tslib
@@ -116,8 +117,10 @@ def isnull(obj):
116117
def _isnull_new(obj):
117118
if lib.isscalar(obj):
118119
return lib.checknull(obj)
119-
120-
if isinstance(obj, (ABCSeries, np.ndarray)):
120+
# hack (for now) because MI registers as ndarray
121+
elif isinstance(obj, pd.MultiIndex):
122+
raise NotImplementedError("isnull is not defined for MultiIndex")
123+
elif isinstance(obj, (ABCSeries, np.ndarray)):
121124
return _isnull_ndarraylike(obj)
122125
elif isinstance(obj, ABCGeneric):
123126
return obj.apply(isnull)
@@ -141,8 +144,10 @@ def _isnull_old(obj):
141144
'''
142145
if lib.isscalar(obj):
143146
return lib.checknull_old(obj)
144-
145-
if isinstance(obj, (ABCSeries, np.ndarray)):
147+
# hack (for now) because MI registers as ndarray
148+
elif isinstance(obj, pd.MultiIndex):
149+
raise NotImplementedError("isnull is not defined for MultiIndex")
150+
elif isinstance(obj, (ABCSeries, np.ndarray)):
146151
return _isnull_ndarraylike_old(obj)
147152
elif isinstance(obj, ABCGeneric):
148153
return obj.apply(_isnull_old)

pandas/tests/test_index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,13 @@ def test_slice_keep_name(self):
23142314
names=['x', 'y'])
23152315
self.assertEqual(x[1:].names, x.names)
23162316

2317+
def test_isnull_behavior(self):
2318+
# should not segfault GH5123
2319+
# NOTE: if MI representation changes, may make sense to allow
2320+
# isnull(MI)
2321+
with tm.assertRaises(NotImplementedError):
2322+
pd.isnull(self.index)
2323+
23172324

23182325
def test_get_combined_index():
23192326
from pandas.core.index import _get_combined_index

0 commit comments

Comments
 (0)