From 3da777a8b52d28613e9b1a77446dabb86eb77b4b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 30 Oct 2019 17:58:37 -0700 Subject: [PATCH 1/3] CLN: tighten Exception catching in indexing.py --- doc/source/reference/indexing.rst | 1 - pandas/core/indexes/base.py | 3 --- pandas/core/indexing.py | 17 +---------------- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/doc/source/reference/indexing.rst b/doc/source/reference/indexing.rst index dd59a99b3df9e..409791c7530a2 100644 --- a/doc/source/reference/indexing.rst +++ b/doc/source/reference/indexing.rst @@ -93,7 +93,6 @@ Compatibility with MultiIndex :toctree: api/ Index.set_names - Index.is_lexsorted_for_tuple Index.droplevel Missing values diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 187c7e2f3a7f7..301426d237d19 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1726,9 +1726,6 @@ def _is_strictly_monotonic_decreasing(self): """ return self.is_unique and self.is_monotonic_decreasing - def is_lexsorted_for_tuple(self, tup): - return True - @cache_readonly def is_unique(self): """ diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 44c786f003369..de7673c5579e1 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -101,7 +101,6 @@ class IndexingError(Exception): class _NDFrameIndexer(_NDFrameIndexerBase): _valid_types = None # type: str - _exception = Exception axis = None def __call__(self, axis=None): @@ -881,14 +880,6 @@ def _handle_lowerdim_multi_index_axis0(self, tup: Tuple): # else IndexingError will be raised if len(tup) <= self.obj.index.nlevels and len(tup) > self.ndim: raise ek - except Exception as e1: - if isinstance(tup[0], (slice, Index)): - raise IndexingError("Handle elsewhere") - - # raise the error if we are not sorted - ax0 = self.obj._get_axis(0) - if not ax0.is_lexsorted_for_tuple(tup): - raise e1 return None @@ -1385,7 +1376,6 @@ def _convert_for_reindex(self, key, axis: int): class _LocationIndexer(_NDFrameIndexer): - _exception = Exception def __getitem__(self, key): if type(key) is tuple: @@ -1417,10 +1407,7 @@ def _getbool_axis(self, key, axis: int): labels = self.obj._get_axis(axis) key = check_bool_indexer(labels, key) inds = key.nonzero()[0] - try: - return self.obj.take(inds, axis=axis) - except Exception as detail: - raise self._exception(detail) + return self.obj.take(inds, axis=axis) def _get_slice_axis(self, slice_obj: slice, axis: int): """ this is pretty simple as we just have to deal with labels """ @@ -1685,7 +1672,6 @@ class _LocIndexer(_LocationIndexer): "endpoints included! Can be slices of integers if the " "index is integers), listlike of labels, boolean" ) - _exception = KeyError @Appender(_NDFrameIndexer._validate_key.__doc__) def _validate_key(self, key, axis: int): @@ -1970,7 +1956,6 @@ class _iLocIndexer(_LocationIndexer): "integer, integer slice (START point is INCLUDED, END " "point is EXCLUDED), listlike of integers, boolean array" ) - _exception = IndexError _get_slice_axis = _NDFrameIndexer._get_slice_axis def _validate_key(self, key, axis: int): From 6b89292a24cbca40f483912a54a1e95dee9fe78f Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 30 Oct 2019 20:25:33 -0700 Subject: [PATCH 2/3] blackify --- pandas/core/indexing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index de7673c5579e1..7db54f4305c2e 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1376,7 +1376,6 @@ def _convert_for_reindex(self, key, axis: int): class _LocationIndexer(_NDFrameIndexer): - def __getitem__(self, key): if type(key) is tuple: key = tuple(com.apply_if_callable(x, self.obj) for x in key) From 9a0a8630de3aa0ce1abd13c4202a3c74b85b1b31 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 2 Nov 2019 09:14:34 -0700 Subject: [PATCH 3/3] whatsnew --- doc/source/whatsnew/v1.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 2e2c5281e6752..f9cecd662e545 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -256,6 +256,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Ability to read pickles containing :class:`Categorical` instances created with pre-0.16 version of pandas has been removed (:issue:`27538`) - Removed the previously deprecated ``reduce`` and ``broadcast`` arguments from :meth:`DataFrame.apply` (:issue:`18577`) - Removed the previously deprecated ``assert_raises_regex`` function in ``pandas.util.testing`` (:issue:`29174`) +- Removed :meth:`Index.is_lexsorted_for_tuple` (:issue:`29305`) - .. _whatsnew_1000.performance: