From 1e662c5c6c4f7f3ed01706b78802976cc53a8b5e Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 5 Feb 2021 20:38:07 -0800 Subject: [PATCH] REF: remove Float64Index get_loc, __contains__ --- pandas/_libs/index_class_helper.pxi.in | 6 +++++- pandas/core/indexes/numeric.py | 17 +---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/pandas/_libs/index_class_helper.pxi.in b/pandas/_libs/index_class_helper.pxi.in index e1ea1fbf9bd46..e5026ce2fa292 100644 --- a/pandas/_libs/index_class_helper.pxi.in +++ b/pandas/_libs/index_class_helper.pxi.in @@ -34,10 +34,14 @@ cdef class {{name}}Engine(IndexEngine): cdef _make_hash_table(self, Py_ssize_t n): return _hash.{{name}}HashTable(n) - {{if name not in {'Float64', 'Float32'} }} cdef _check_type(self, object val): + {{if name not in {'Float64', 'Float32'} }} if not util.is_integer_object(val): raise KeyError(val) + {{else}} + if util.is_bool_object(val): + # avoid casting to True -> 1.0 + raise KeyError(val) {{endif}} cdef void _call_map_locations(self, values): diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index 777fc1c7c4ad2..d6427aed6edf3 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -1,4 +1,4 @@ -from typing import Any, Hashable, Optional +from typing import Hashable, Optional import warnings import numpy as np @@ -9,7 +9,6 @@ from pandas.core.dtypes.cast import astype_nansafe from pandas.core.dtypes.common import ( - is_bool, is_dtype_equal, is_extension_array_dtype, is_float, @@ -336,13 +335,6 @@ def _convert_slice_indexer(self, key: slice, kind: str): # translate to locations return self.slice_indexer(key.start, key.stop, key.step, kind=kind) - @doc(Index.get_loc) - def get_loc(self, key, method=None, tolerance=None): - if is_bool(key): - # Catch this to avoid accidentally casting to 1.0 - raise KeyError(key) - return super().get_loc(key, method=method, tolerance=tolerance) - # ---------------------------------------------------------------- def _format_native_types( @@ -359,10 +351,3 @@ def _format_native_types( fixed_width=False, ) return formatter.get_result_as_array() - - def __contains__(self, other: Any) -> bool: - hash(other) - if super().__contains__(other): - return True - - return is_float(other) and np.isnan(other) and self.hasnans