Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ Indexing
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`)
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`)
- ``Float64Index.get_loc`` now raises ``KeyError`` when boolean key passed. (:issue:`19087`)

Missing
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def __contains__(self, other):
@Appender(_index_shared_docs['get_loc'])
def get_loc(self, key, method=None, tolerance=None):
try:
if np.all(np.isnan(key)):
if np.all(np.isnan(key)) or is_bool(key):
nan_idxs = self._nan_idxs
try:
return nan_idxs.item()
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def test_get_loc(self):
pytest.raises(KeyError, idx.get_loc, 1.5)
pytest.raises(KeyError, idx.get_loc, 1.5, method='pad',
tolerance=0.1)
pytest.raises(KeyError, idx.get_loc, True)
pytest.raises(KeyError, idx.get_loc, False)

with tm.assert_raises_regex(ValueError, 'must be numeric'):
idx.get_loc(1.4, method='nearest', tolerance='foo')
Expand Down