Skip to content

Commit 15974c2

Browse files
authored
REF: remove Float64Index get_loc, __contains__ (#39620)
1 parent dbb88c7 commit 15974c2

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

pandas/_libs/index_class_helper.pxi.in

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ cdef class {{name}}Engine(IndexEngine):
3434
cdef _make_hash_table(self, Py_ssize_t n):
3535
return _hash.{{name}}HashTable(n)
3636

37-
{{if name not in {'Float64', 'Float32'} }}
3837
cdef _check_type(self, object val):
38+
{{if name not in {'Float64', 'Float32'} }}
3939
if not util.is_integer_object(val):
4040
raise KeyError(val)
41+
{{else}}
42+
if util.is_bool_object(val):
43+
# avoid casting to True -> 1.0
44+
raise KeyError(val)
4145
{{endif}}
4246

4347
cdef void _call_map_locations(self, values):

pandas/core/indexes/numeric.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Hashable, Optional
1+
from typing import Hashable, Optional
22
import warnings
33

44
import numpy as np
@@ -9,7 +9,6 @@
99

1010
from pandas.core.dtypes.cast import astype_nansafe
1111
from pandas.core.dtypes.common import (
12-
is_bool,
1312
is_dtype_equal,
1413
is_extension_array_dtype,
1514
is_float,
@@ -336,13 +335,6 @@ def _convert_slice_indexer(self, key: slice, kind: str):
336335
# translate to locations
337336
return self.slice_indexer(key.start, key.stop, key.step, kind=kind)
338337

339-
@doc(Index.get_loc)
340-
def get_loc(self, key, method=None, tolerance=None):
341-
if is_bool(key):
342-
# Catch this to avoid accidentally casting to 1.0
343-
raise KeyError(key)
344-
return super().get_loc(key, method=method, tolerance=tolerance)
345-
346338
# ----------------------------------------------------------------
347339

348340
def _format_native_types(
@@ -359,10 +351,3 @@ def _format_native_types(
359351
fixed_width=False,
360352
)
361353
return formatter.get_result_as_array()
362-
363-
def __contains__(self, other: Any) -> bool:
364-
hash(other)
365-
if super().__contains__(other):
366-
return True
367-
368-
return is_float(other) and np.isnan(other) and self.hasnans

0 commit comments

Comments
 (0)