From 53d68ab9fa165f4604f6a98ce3c70faf24654dc5 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 7 Jan 2019 19:23:24 -0800 Subject: [PATCH 1/2] move templated index.pyx code to non-template --- pandas/_libs/index.pyx | 13 ++++++++++++- pandas/_libs/index_class_helper.pxi.in | 22 ++-------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index c919086701536..c2371e02e34a9 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -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 @@ -681,5 +687,10 @@ cdef class BaseMultiIndexCodesEngine: return False +cdef class ObjectEngine(IndexEngine): + cdef _make_hash_table(self, n): + return _hash.PyObjectHashTable(n) + + # Generated from template. include "index_class_helper.pxi" diff --git a/pandas/_libs/index_class_helper.pxi.in b/pandas/_libs/index_class_helper.pxi.in index 6383c1534fb44..3c9a096e7ecc0 100644 --- a/pandas/_libs/index_class_helper.pxi.in +++ b/pandas/_libs/index_class_helper.pxi.in @@ -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'), ] }} @@ -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 @@ -87,6 +71,4 @@ cdef class {{name}}Engine(IndexEngine): raise KeyError(val) - {{endif}} - {{endfor}} From 60fc5ff1b8c4c04817bcf04d6d1247990a2fd81f Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 8 Jan 2019 08:51:53 -0800 Subject: [PATCH 2/2] move ObjectEngine up, with docstring --- pandas/_libs/index.pyx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index c2371e02e34a9..8cea529fbb07e 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -377,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): @@ -687,10 +695,5 @@ cdef class BaseMultiIndexCodesEngine: return False -cdef class ObjectEngine(IndexEngine): - cdef _make_hash_table(self, n): - return _hash.PyObjectHashTable(n) - - # Generated from template. include "index_class_helper.pxi"