Skip to content

Commit 28c9ccc

Browse files
jbrockmendeljorisvandenbossche
authored andcommittedNov 3, 2019
CLN: tighten Exception catching in indexing.py (#29305)
1 parent ecd315b commit 28c9ccc

File tree

4 files changed

+2
-21
lines changed

4 files changed

+2
-21
lines changed
 

‎doc/source/reference/indexing.rst

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Compatibility with MultiIndex
9393
:toctree: api/
9494

9595
Index.set_names
96-
Index.is_lexsorted_for_tuple
9796
Index.droplevel
9897

9998
Missing values

‎doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
257257
- Ability to read pickles containing :class:`Categorical` instances created with pre-0.16 version of pandas has been removed (:issue:`27538`)
258258
- Removed the previously deprecated ``reduce`` and ``broadcast`` arguments from :meth:`DataFrame.apply` (:issue:`18577`)
259259
- Removed the previously deprecated ``assert_raises_regex`` function in ``pandas.util.testing`` (:issue:`29174`)
260+
- Removed :meth:`Index.is_lexsorted_for_tuple` (:issue:`29305`)
260261
-
261262

262263
.. _whatsnew_1000.performance:

‎pandas/core/indexes/base.py

-3
Original file line numberDiff line numberDiff line change
@@ -1726,9 +1726,6 @@ def _is_strictly_monotonic_decreasing(self):
17261726
"""
17271727
return self.is_unique and self.is_monotonic_decreasing
17281728

1729-
def is_lexsorted_for_tuple(self, tup):
1730-
return True
1731-
17321729
@cache_readonly
17331730
def is_unique(self):
17341731
"""

‎pandas/core/indexing.py

+1-17
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class IndexingError(Exception):
101101

102102
class _NDFrameIndexer(_NDFrameIndexerBase):
103103
_valid_types = None # type: str
104-
_exception = Exception
105104
axis = None
106105

107106
def __call__(self, axis=None):
@@ -881,14 +880,6 @@ def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
881880
# else IndexingError will be raised
882881
if len(tup) <= self.obj.index.nlevels and len(tup) > self.ndim:
883882
raise ek
884-
except Exception as e1:
885-
if isinstance(tup[0], (slice, Index)):
886-
raise IndexingError("Handle elsewhere")
887-
888-
# raise the error if we are not sorted
889-
ax0 = self.obj._get_axis(0)
890-
if not ax0.is_lexsorted_for_tuple(tup):
891-
raise e1
892883

893884
return None
894885

@@ -1385,8 +1376,6 @@ def _convert_for_reindex(self, key, axis: int):
13851376

13861377

13871378
class _LocationIndexer(_NDFrameIndexer):
1388-
_exception = Exception
1389-
13901379
def __getitem__(self, key):
13911380
if type(key) is tuple:
13921381
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
@@ -1417,10 +1406,7 @@ def _getbool_axis(self, key, axis: int):
14171406
labels = self.obj._get_axis(axis)
14181407
key = check_bool_indexer(labels, key)
14191408
inds = key.nonzero()[0]
1420-
try:
1421-
return self.obj.take(inds, axis=axis)
1422-
except Exception as detail:
1423-
raise self._exception(detail)
1409+
return self.obj.take(inds, axis=axis)
14241410

14251411
def _get_slice_axis(self, slice_obj: slice, axis: int):
14261412
""" this is pretty simple as we just have to deal with labels """
@@ -1685,7 +1671,6 @@ class _LocIndexer(_LocationIndexer):
16851671
"endpoints included! Can be slices of integers if the "
16861672
"index is integers), listlike of labels, boolean"
16871673
)
1688-
_exception = KeyError
16891674

16901675
@Appender(_NDFrameIndexer._validate_key.__doc__)
16911676
def _validate_key(self, key, axis: int):
@@ -1970,7 +1955,6 @@ class _iLocIndexer(_LocationIndexer):
19701955
"integer, integer slice (START point is INCLUDED, END "
19711956
"point is EXCLUDED), listlike of integers, boolean array"
19721957
)
1973-
_exception = IndexError
19741958
_get_slice_axis = _NDFrameIndexer._get_slice_axis
19751959

19761960
def _validate_key(self, key, axis: int):

0 commit comments

Comments
 (0)
Please sign in to comment.