-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
/
Copy pathindex_class_helper.pxi.in
83 lines (63 loc) · 2.31 KB
/
index_class_helper.pxi.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Template for functions of IndexEngine subclasses.
WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
"""
#----------------------------------------------------------------------
# IndexEngine Subclass Methods
#----------------------------------------------------------------------
{{py:
# name, dtype, ctype
dtypes = [('Float64', 'float64', 'float64_t'),
('UInt64', 'uint64', 'uint64_t'),
('Int64', 'int64', 'int64_t'),
('Object', 'object', 'object')]
}}
{{for name, dtype, ctype in dtypes}}
cdef class {{name}}Engine(IndexEngine):
def _call_monotonic(self, values):
return algos.is_monotonic_{{dtype}}(values, timelike=False)
def get_backfill_indexer(self, other, limit=None):
return algos.backfill_{{dtype}}(self._get_index_values(),
other, limit=limit)
def get_pad_indexer(self, other, limit=None):
return algos.pad_{{dtype}}(self._get_index_values(),
other, limit=limit)
cdef _make_hash_table(self, n):
{{if name == 'Object'}}
return _hash.PyObjectHashTable(n)
{{else}}
return _hash.{{name}}HashTable(n)
{{endif}}
{{if name != 'Float64' and name != 'Object'}}
cdef _check_type(self, object val):
hash(val)
if util.is_bool_object(val):
raise KeyError(val)
elif util.is_float_object(val):
raise KeyError(val)
{{endif}}
{{if name != 'Object'}}
cdef _get_index_values(self):
return algos.ensure_{{dtype}}(self.vgetter())
cdef _maybe_get_bool_indexer(self, object val):
cdef:
ndarray[uint8_t, ndim=1, cast=True] indexer
ndarray[intp_t, ndim=1] found
ndarray[{{ctype}}] values
int count = 0
{{if name != 'Float64'}}
if not util.is_integer_object(val):
raise KeyError(val)
{{endif}}
# A view is needed for some subclasses, such as PeriodEngine:
values = self._get_index_values().view('{{dtype}}')
indexer = values == val
found = np.where(indexer)[0]
count = len(found)
if count > 1:
return indexer
if count == 1:
return int(found[0])
raise KeyError(val)
{{endif}}
{{endfor}}