Skip to content

Commit caf462c

Browse files
jbrockmendeljreback
authored andcommitted
REF: move templated index.pyx code to non-template (#24669)
1 parent 2897fca commit caf462c

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

pandas/_libs/index.pyx

+15-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ cdef class IndexEngine:
226226
return self.vgetter()
227227

228228
def _call_monotonic(self, values):
229-
raise NotImplementedError
229+
return algos.is_monotonic(values, timelike=False)
230+
231+
def get_backfill_indexer(self, other, limit=None):
232+
return algos.backfill(self._get_index_values(), other, limit=limit)
233+
234+
def get_pad_indexer(self, other, limit=None):
235+
return algos.pad(self._get_index_values(), other, limit=limit)
230236

231237
cdef _make_hash_table(self, n):
232238
raise NotImplementedError
@@ -371,6 +377,14 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
371377
return mid + 1
372378

373379

380+
cdef class ObjectEngine(IndexEngine):
381+
"""
382+
Index Engine for use with object-dtype Index, namely the base class Index
383+
"""
384+
cdef _make_hash_table(self, n):
385+
return _hash.PyObjectHashTable(n)
386+
387+
374388
cdef class DatetimeEngine(Int64Engine):
375389

376390
cdef _get_box_dtype(self):

pandas/_libs/index_class_helper.pxi.in

+2-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ dtypes = [('Float64', 'float64', 'float64_t', 'Float64', 'float64'),
2121
('UInt32', 'uint32', 'uint32_t', 'UInt64', 'uint64'),
2222
('UInt16', 'uint16', 'uint16_t', 'UInt64', 'uint64'),
2323
('UInt8', 'uint8', 'uint8_t', 'UInt64', 'uint64'),
24-
('Object', 'object', 'object', 'PyObject', 'object'),
2524
]
2625
}}
2726

@@ -30,30 +29,15 @@ dtypes = [('Float64', 'float64', 'float64_t', 'Float64', 'float64'),
3029

3130
cdef class {{name}}Engine(IndexEngine):
3231

33-
def _call_monotonic(self, values):
34-
return algos.is_monotonic(values, timelike=False)
35-
36-
def get_backfill_indexer(self, other, limit=None):
37-
return algos.backfill(self._get_index_values(), other, limit=limit)
38-
39-
def get_pad_indexer(self, other, limit=None):
40-
return algos.pad(self._get_index_values(), other, limit=limit)
41-
4232
cdef _make_hash_table(self, n):
4333
return _hash.{{hashtable_name}}HashTable(n)
4434

45-
{{if name not in {'Float64', 'Float32', 'Object'} }}
35+
{{if name not in {'Float64', 'Float32'} }}
4636
cdef _check_type(self, object val):
47-
hash(val)
48-
if util.is_bool_object(val):
49-
raise KeyError(val)
50-
elif util.is_float_object(val):
51-
raise KeyError(val)
52-
elif not util.is_integer_object(val):
37+
if not util.is_integer_object(val):
5338
raise KeyError(val)
5439
{{endif}}
5540

56-
{{if name != 'Object'}}
5741
cpdef _call_map_locations(self, values):
5842
# self.mapping is of type {{hashtable_name}}HashTable,
5943
# so convert dtype of values
@@ -87,6 +71,4 @@ cdef class {{name}}Engine(IndexEngine):
8771

8872
raise KeyError(val)
8973

90-
{{endif}}
91-
9274
{{endfor}}

0 commit comments

Comments
 (0)