Skip to content

REF: move templated index.pyx code to non-template #24669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ cdef class IndexEngine:
return self.vgetter()

def _call_monotonic(self, values):
raise NotImplementedError
return algos.is_monotonic(values, timelike=False)

def get_backfill_indexer(self, other, limit=None):
return algos.backfill(self._get_index_values(), other, limit=limit)

def get_pad_indexer(self, other, limit=None):
return algos.pad(self._get_index_values(), other, limit=limit)

cdef _make_hash_table(self, n):
raise NotImplementedError
Expand Down Expand Up @@ -371,6 +377,14 @@ cdef Py_ssize_t _bin_search(ndarray values, object val) except -1:
return mid + 1


cdef class ObjectEngine(IndexEngine):
"""
Index Engine for use with object-dtype Index, namely the base class Index
"""
cdef _make_hash_table(self, n):
return _hash.PyObjectHashTable(n)


cdef class DatetimeEngine(Int64Engine):

cdef _get_box_dtype(self):
Expand Down
22 changes: 2 additions & 20 deletions pandas/_libs/index_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dtypes = [('Float64', 'float64', 'float64_t', 'Float64', 'float64'),
('UInt32', 'uint32', 'uint32_t', 'UInt64', 'uint64'),
('UInt16', 'uint16', 'uint16_t', 'UInt64', 'uint64'),
('UInt8', 'uint8', 'uint8_t', 'UInt64', 'uint64'),
('Object', 'object', 'object', 'PyObject', 'object'),
]
}}

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

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

def _call_monotonic(self, values):
return algos.is_monotonic(values, timelike=False)

def get_backfill_indexer(self, other, limit=None):
return algos.backfill(self._get_index_values(), other, limit=limit)

def get_pad_indexer(self, other, limit=None):
return algos.pad(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'} }}
{{if name not in {'Float64', 'Float32'} }}
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):
if 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
Expand Down Expand Up @@ -87,6 +71,4 @@ cdef class {{name}}Engine(IndexEngine):

raise KeyError(val)

{{endif}}

{{endfor}}