Skip to content

Commit ebd66ab

Browse files
committed
fixes based on jreback feedback
1 parent 80bbefc commit ebd66ab

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

doc/source/whatsnew/v0.20.0.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ Other enhancements
4242
- ``pd.read_excel`` now preserves sheet order when using ``sheetname=None`` (:issue:`9930`)
4343

4444
- New ``UnsortedIndexError`` (subclass of ``KeyError``) thrown when indexing into an
45-
unsorted index (:issue:'11897`)
45+
unsorted MultiIndex (:issue:'11897`)
46+
47+
- Change message when indexing via a boolean ``Series`` that has an incompatible index (:issue:`14491`)
4648

4749

4850
.. _whatsnew_0200.api_breaking:

pandas/core/common.py

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class UnsupportedFunctionCall(ValueError):
9797
pass
9898

9999

100+
class UnsortedIndexError(KeyError):
101+
pass
102+
103+
100104
class AbstractMethodError(NotImplementedError):
101105
"""Raise this error instead of NotImplementedError for abstract methods
102106
while keeping compatibility with Python 2 and Python 3.

pandas/core/indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,8 @@ def check_bool_indexer(ax, key):
18141814
result = result.reindex(ax)
18151815
mask = isnull(result._values)
18161816
if mask.any():
1817-
raise IndexingError('Unalignable labels in boolean Series index')
1817+
raise IndexingError('Unalignable labels in boolean Series index '
1818+
'{}'.format(key.index))
18181819
result = result.astype(bool)._values
18191820
elif is_sparse(result):
18201821
result = result.to_dense()

pandas/indexes/multi.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
from pandas.core.common import (_values_from_object,
2626
is_bool_indexer,
2727
is_null_slice,
28-
PerformanceWarning)
28+
PerformanceWarning,
29+
UnsortedIndexError)
2930

3031

3132
from pandas.core.base import FrozenList
@@ -45,10 +46,6 @@
4546
import pandas.indexes.base as ibase
4647

4748

48-
class UnsortedIndexError(KeyError):
49-
pass
50-
51-
5249
class MultiIndex(Index):
5350
"""
5451
A multi-level, or hierarchical, index object for pandas objects

pandas/tests/indexes/test_multi.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
from pandas import (DataFrame, date_range, period_range, MultiIndex, Index,
1010
CategoricalIndex, compat)
11-
from pandas.core.common import PerformanceWarning
11+
from pandas.core.common import PerformanceWarning, UnsortedIndexError
1212
from pandas.indexes.base import InvalidIndexError
13-
from pandas.indexes.multi import UnsortedIndexError
1413
from pandas.compat import range, lrange, u, PY3, long, lzip
1514

1615
import numpy as np

pandas/tests/indexing/test_indexing.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
MultiIndex, Timestamp, Timedelta)
2424
from pandas.formats.printing import pprint_thing
2525
from pandas import concat
26-
from pandas.core.common import PerformanceWarning
26+
from pandas.core.common import PerformanceWarning, UnsortedIndexError
2727

2828
import pandas.util.testing as tm
2929
from pandas import date_range
@@ -2230,7 +2230,7 @@ def f():
22302230
df = df.sortlevel(level=1, axis=0)
22312231
self.assertEqual(df.index.lexsort_depth, 0)
22322232
with tm.assertRaisesRegexp(
2233-
KeyError,
2233+
UnsortedIndexError,
22342234
'MultiIndex Slicing requires the index to be fully '
22352235
r'lexsorted tuple len \(2\), lexsort depth \(0\)'):
22362236
df.loc[(slice(None), df.loc[:, ('a', 'bar')] > 5), :]
@@ -2417,7 +2417,7 @@ def test_per_axis_per_level_doc_examples(self):
24172417
def f():
24182418
df.loc['A1', (slice(None), 'foo')]
24192419

2420-
self.assertRaises(KeyError, f)
2420+
self.assertRaises(UnsortedIndexError, f)
24212421
df = df.sortlevel(axis=1)
24222422

24232423
# slicing
@@ -3480,8 +3480,10 @@ def test_iloc_mask(self):
34803480
('index', '.loc'): '0b11',
34813481
('index', '.iloc'): ('iLocation based boolean indexing '
34823482
'cannot use an indexable as a mask'),
3483-
('locs', ''): 'Unalignable labels in boolean Series index',
3484-
('locs', '.loc'): 'Unalignable labels in boolean Series index',
3483+
('locs', ''): 'Unalignable labels in boolean Series index '
3484+
"Int64Index([3, 2, 1, 0], dtype='int64')",
3485+
('locs', '.loc'): 'Unalignable labels in boolean Series index '
3486+
"Int64Index([3, 2, 1, 0], dtype='int64')",
34853487
('locs', '.iloc'): ('iLocation based boolean indexing on an '
34863488
'integer type is not available'),
34873489
}

0 commit comments

Comments
 (0)