Skip to content

REF: remove Float64Index get_loc, __contains__ #39620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2021
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
6 changes: 5 additions & 1 deletion pandas/_libs/index_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 1 addition & 16 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Hashable, Optional
from typing import Hashable, Optional
import warnings

import numpy as np
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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