forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex_class_helper.pxi.in
94 lines (73 loc) · 3.11 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, hashtable_name, hashtable_dtype
dtypes = [('Float64', 'float64', 'float64_t', 'Float64', 'float64'),
('Float32', 'float32', 'float32_t', 'Float64', 'float64'),
('Int64', 'int64', 'int64_t', 'Int64', 'int64'),
('Int32', 'int32', 'int32_t', 'Int64', 'int64'),
('Int16', 'int16', 'int16_t', 'Int64', 'int64'),
('Int8', 'int8', 'int8_t', 'Int64', 'int64'),
('UInt64', 'uint64', 'uint64_t', 'UInt64', 'uint64'),
('UInt32', 'uint32', 'uint32_t', 'UInt64', 'uint64'),
('UInt16', 'uint16', 'uint16_t', 'UInt64', 'uint64'),
('UInt8', 'uint8', 'uint8_t', 'UInt64', 'uint64'),
('Object', 'object', 'object', 'PyObject', 'object'),
]
}}
{{for name, dtype, ctype, hashtable_name, hashtable_dtype 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):
return _hash.{{hashtable_name}}HashTable(n)
{{if name not in {'Float64', 'Float32', '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)
elif not util.is_integer_object(val):
raise KeyError(val)
{{endif}}
{{if name != 'Object'}}
cpdef _call_map_locations(self, values):
# self.mapping is of type {{hashtable_name}}HashTable,
# so convert dtype of values
self.mapping.map_locations(algos.ensure_{{hashtable_dtype}}(values))
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 not in {'Float64', 'Float32'} }}
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}}