forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_class_helper.pxi.in
94 lines (72 loc) · 2.53 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
84
85
86
87
88
89
90
91
92
93
94
"""
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, cast=True] indexer
ndarray[{{ctype}}] values
int count = 0
Py_ssize_t i, n
int last_true
{{if name != 'Float64'}}
if not util.is_integer_object(val):
raise KeyError(val)
{{endif}}
values = self._get_index_values_for_bool_indexer()
n = len(values)
result = np.empty(n, dtype=bool)
indexer = result.view(np.uint8)
for i in range(n):
if values[i] == val:
count += 1
indexer[i] = 1
last_true = i
else:
indexer[i] = 0
if count == 0:
raise KeyError(val)
if count == 1:
return last_true
return result
cdef _get_index_values_for_bool_indexer(self):
return self._get_index_values()
{{endif}}
{{endfor}}