Skip to content

Commit c52f92a

Browse files
committed
GH14554, rolled back changes per discussion thread. Added test.
1 parent 474adf1 commit c52f92a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pandas/core/indexing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ def _multi_take(self, tup):
848848
[(a, self._convert_for_reindex(t, axis=o._get_axis_number(a)))
849849
for t, a in zip(tup, o._AXIS_ORDERS)])
850850
return o.reindex(**d)
851+
except (KeyError, IndexError, self._exception):
852+
raise self._exception
851853
except:
852854
raise
853855

@@ -1320,8 +1322,8 @@ def _getbool_axis(self, key, axis=0):
13201322
inds, = key.nonzero()
13211323
try:
13221324
return self.obj.take(inds, axis=axis, convert=False)
1323-
except:
1324-
raise
1325+
except Exception as detail:
1326+
raise self._exception(detail)
13251327

13261328
def _get_slice_axis(self, slice_obj, axis=0):
13271329
""" this is pretty simple as we just have to deal with labels """

pandas/tests/indexing/test_indexing.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def _axify(obj, key, axis):
9494
def _mklbl(prefix, n):
9595
return ["%s%s" % (prefix, i) for i in range(n)]
9696

97-
9897
class TestIndexing(tm.TestCase):
9998

10099
_multiprocess_can_split_ = True
@@ -279,6 +278,11 @@ def _print(result, error=None):
279278
k2 = key2
280279
_eq(t, o, a, obj, key1, k2)
281280

281+
#GH14554: used to make sure recursion errors bubble up as expected
282+
recursive_df = pd.DataFrame({'a':[1,]}, index=['a'])
283+
def recursive_indexing_function(self, a):
284+
return self.recursive_indexing_function(self.recursive_df.loc[['a'], ['a']])
285+
282286
def test_indexer_caching(self):
283287
# GH5727
284288
# make sure that indexers are in the _internal_names_set
@@ -1216,7 +1220,19 @@ def test_loc_getitem_bool(self):
12161220
self.check_result('bool', 'loc', b, 'ix', b,
12171221
typs=['ints', 'labels', 'mixed', 'ts', 'floats'])
12181222
self.check_result('bool', 'loc', b, 'ix', b, typs=['empty'],
1219-
fails=IndexError)
1223+
fails=KeyError)
1224+
1225+
def test_recursion_fails_loc(self):
1226+
#GH14554
1227+
#RuntimeError should bubble up if appropriate, rather
1228+
#than method specific exception
1229+
oldVal=sys.getrecursionlimit()
1230+
sys.setrecursionlimit(50)
1231+
with self.assertRaises(RuntimeError):
1232+
try:
1233+
self.recursive_indexing_function(1)
1234+
finally:
1235+
sys.setrecursionlimit(oldVal)
12201236

12211237
def test_loc_getitem_int_slice(self):
12221238

0 commit comments

Comments
 (0)