@@ -10,24 +10,26 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
10
10
11
11
{{py:
12
12
13
- # name, dtype, ctype, hashtable_name, hashtable_dtype
14
- dtypes = [('Float64', 'float64', 'float64_t', ' Float64', 'float64 '),
15
- ('Float32', 'float32', 'float32_t', ' Float64', 'float64 '),
16
- ('Int64', 'int64', 'int64_t', ' Int64', 'int64 '),
17
- ('Int32', 'int32', 'int32_t', ' Int64', 'int64 '),
18
- ('Int16', 'int16', 'int16_t', ' Int64', 'int64 '),
19
- ('Int8', 'int8', 'int8_t', ' Int64', 'int64 '),
20
- ('UInt64', 'uint64', 'uint64_t', ' UInt64', 'uint64 '),
21
- ('UInt32', 'uint32', 'uint32_t', ' UInt64', 'uint64 '),
22
- ('UInt16', 'uint16', 'uint16_t', ' UInt64', 'uint64 '),
23
- ('UInt8', 'uint8', 'uint8_t', ' UInt64', 'uint64 '),
13
+ # name, dtype, hashtable_name
14
+ dtypes = [('Float64', 'float64', 'Float64'),
15
+ ('Float32', 'float32', 'Float64'),
16
+ ('Int64', 'int64', 'Int64'),
17
+ ('Int32', 'int32', 'Int64'),
18
+ ('Int16', 'int16', 'Int64'),
19
+ ('Int8', 'int8', 'Int64'),
20
+ ('UInt64', 'uint64', 'UInt64'),
21
+ ('UInt32', 'uint32', 'UInt64'),
22
+ ('UInt16', 'uint16', 'UInt64'),
23
+ ('UInt8', 'uint8', 'UInt64'),
24
24
]
25
25
}}
26
26
27
- {{for name, dtype, ctype, hashtable_name, hashtable_dtype in dtypes}}
27
+ {{for name, dtype, hashtable_name in dtypes}}
28
28
29
29
30
30
cdef class {{name}}Engine(IndexEngine):
31
+ # constructor-caller is responsible for ensuring that vgetter()
32
+ # returns an ndarray with dtype {{dtype}}_t
31
33
32
34
cdef _make_hash_table(self, Py_ssize_t n):
33
35
return _hash.{{hashtable_name}}HashTable(n)
@@ -41,22 +43,18 @@ cdef class {{name}}Engine(IndexEngine):
41
43
cdef void _call_map_locations(self, values):
42
44
# self.mapping is of type {{hashtable_name}}HashTable,
43
45
# so convert dtype of values
44
- self.mapping.map_locations(algos.ensure_{{hashtable_dtype}}(values))
45
-
46
- cdef _get_index_values(self):
47
- return algos.ensure_{{dtype}}(self.vgetter())
46
+ self.mapping.map_locations(algos.ensure_{{hashtable_name.lower()}}(values))
48
47
49
48
cdef _maybe_get_bool_indexer(self, object val):
50
49
cdef:
51
50
ndarray[uint8_t, ndim=1, cast=True] indexer
52
51
ndarray[intp_t, ndim=1] found
53
- ndarray[{{ctype}} ] values
52
+ ndarray[{{dtype}}_t, ndim=1 ] values
54
53
int count = 0
55
54
56
55
self._check_type(val)
57
56
58
- # A view is needed for some subclasses, such as PeriodEngine:
59
- values = self._get_index_values().view('{{dtype}}')
57
+ values = self._get_index_values()
60
58
try:
61
59
with warnings.catch_warnings():
62
60
# e.g. if values is float64 and `val` is a str, suppress warning
@@ -67,14 +65,6 @@ cdef class {{name}}Engine(IndexEngine):
67
65
# when trying to cast it to ndarray
68
66
raise KeyError(val)
69
67
70
- found = np.where(indexer)[0]
71
- count = len(found)
72
-
73
- if count > 1:
74
- return indexer
75
- if count == 1:
76
- return int(found[0])
77
-
78
- raise KeyError(val)
68
+ return self._unpack_bool_indexer(indexer, val)
79
69
80
70
{{endfor}}
0 commit comments