File tree 2 files changed +11
-20
lines changed
2 files changed +11
-20
lines changed Original file line number Diff line number Diff line change 1
- import warnings
2
-
3
1
cimport cython
4
2
5
3
import numpy as np
Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ cdef class {{name}}Engine(IndexEngine):
37
37
if not util.is_integer_object(val):
38
38
raise KeyError(val)
39
39
{{else}}
40
- if util.is_bool_object (val):
41
- # avoid casting to True -> 1.0
40
+ if not util.is_integer_object(val) and not util.is_float_object (val):
41
+ # in particular catch bool and avoid casting True -> 1.0
42
42
raise KeyError(val)
43
43
{{endif}}
44
44
@@ -53,22 +53,15 @@ cdef class {{name}}Engine(IndexEngine):
53
53
self._check_type(val)
54
54
55
55
values = self.values
56
- try:
57
- with warnings.catch_warnings():
58
- # e.g. if values is float64 and `val` is a str, suppress warning
59
- warnings.filterwarnings("ignore", category=FutureWarning)
60
- {{if name in {'Float64', 'Float32'} }}
61
- if util.is_nan(val):
62
- indexer = np.isnan(values)
63
- else:
64
- indexer = values == val
65
- {{else}}
66
- indexer = values == val
67
- {{endif}}
68
- except TypeError:
69
- # if the equality above returns a bool, cython will raise TypeError
70
- # when trying to cast it to ndarray
71
- raise KeyError(val)
56
+
57
+ {{if name in {'Float64', 'Float32'} }}
58
+ if util.is_nan(val):
59
+ indexer = np.isnan(values)
60
+ else:
61
+ indexer = values == val
62
+ {{else}}
63
+ indexer = values == val
64
+ {{endif}}
72
65
73
66
return indexer
74
67
You can’t perform that action at this time.
0 commit comments