Skip to content

Commit

Permalink
clear out a bunch of algos, de-duplicate a bunch of core.missing (pan…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and Pingviinituutti committed Feb 28, 2019
1 parent 3f2f01e commit ca77450
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 239 deletions.
103 changes: 0 additions & 103 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -369,31 +369,6 @@ ctypedef fused algos_t:
uint8_t


# TODO: unused; needed?
@cython.wraparound(False)
@cython.boundscheck(False)
cpdef map_indices(ndarray[algos_t] index):
"""
Produce a dict mapping the values of the input array to their respective
locations.
Example:
array(['hi', 'there']) --> {'hi' : 0 , 'there' : 1}
Better to do this with Cython because of the enormous speed boost.
"""
cdef:
Py_ssize_t i, length
dict result = {}

length = len(index)

for i in range(length):
result[index[i]] = i

return result


@cython.boundscheck(False)
@cython.wraparound(False)
def pad(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
Expand Down Expand Up @@ -458,20 +433,6 @@ def pad(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
return indexer


pad_float64 = pad["float64_t"]
pad_float32 = pad["float32_t"]
pad_object = pad["object"]
pad_int64 = pad["int64_t"]
pad_int32 = pad["int32_t"]
pad_int16 = pad["int16_t"]
pad_int8 = pad["int8_t"]
pad_uint64 = pad["uint64_t"]
pad_uint32 = pad["uint32_t"]
pad_uint16 = pad["uint16_t"]
pad_uint8 = pad["uint8_t"]
pad_bool = pad["uint8_t"]


@cython.boundscheck(False)
@cython.wraparound(False)
def pad_inplace(ndarray[algos_t] values,
Expand Down Expand Up @@ -509,15 +470,6 @@ def pad_inplace(ndarray[algos_t] values,
val = values[i]


pad_inplace_float64 = pad_inplace["float64_t"]
pad_inplace_float32 = pad_inplace["float32_t"]
pad_inplace_object = pad_inplace["object"]
pad_inplace_int64 = pad_inplace["int64_t"]
pad_inplace_int32 = pad_inplace["int32_t"]
pad_inplace_uint64 = pad_inplace["uint64_t"]
pad_inplace_bool = pad_inplace["uint8_t"]


@cython.boundscheck(False)
@cython.wraparound(False)
def pad_2d_inplace(ndarray[algos_t, ndim=2] values,
Expand Down Expand Up @@ -557,15 +509,6 @@ def pad_2d_inplace(ndarray[algos_t, ndim=2] values,
val = values[j, i]


pad_2d_inplace_float64 = pad_2d_inplace["float64_t"]
pad_2d_inplace_float32 = pad_2d_inplace["float32_t"]
pad_2d_inplace_object = pad_2d_inplace["object"]
pad_2d_inplace_int64 = pad_2d_inplace["int64_t"]
pad_2d_inplace_int32 = pad_2d_inplace["int32_t"]
pad_2d_inplace_uint64 = pad_2d_inplace["uint64_t"]
pad_2d_inplace_bool = pad_2d_inplace["uint8_t"]


"""
Backfilling logic for generating fill vector
Expand Down Expand Up @@ -657,20 +600,6 @@ def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
return indexer


backfill_float64 = backfill["float64_t"]
backfill_float32 = backfill["float32_t"]
backfill_object = backfill["object"]
backfill_int64 = backfill["int64_t"]
backfill_int32 = backfill["int32_t"]
backfill_int16 = backfill["int16_t"]
backfill_int8 = backfill["int8_t"]
backfill_uint64 = backfill["uint64_t"]
backfill_uint32 = backfill["uint32_t"]
backfill_uint16 = backfill["uint16_t"]
backfill_uint8 = backfill["uint8_t"]
backfill_bool = backfill["uint8_t"]


@cython.boundscheck(False)
@cython.wraparound(False)
def backfill_inplace(ndarray[algos_t] values,
Expand Down Expand Up @@ -708,15 +637,6 @@ def backfill_inplace(ndarray[algos_t] values,
val = values[i]


backfill_inplace_float64 = backfill_inplace["float64_t"]
backfill_inplace_float32 = backfill_inplace["float32_t"]
backfill_inplace_object = backfill_inplace["object"]
backfill_inplace_int64 = backfill_inplace["int64_t"]
backfill_inplace_int32 = backfill_inplace["int32_t"]
backfill_inplace_uint64 = backfill_inplace["uint64_t"]
backfill_inplace_bool = backfill_inplace["uint8_t"]


@cython.boundscheck(False)
@cython.wraparound(False)
def backfill_2d_inplace(ndarray[algos_t, ndim=2] values,
Expand Down Expand Up @@ -756,15 +676,6 @@ def backfill_2d_inplace(ndarray[algos_t, ndim=2] values,
val = values[j, i]


backfill_2d_inplace_float64 = backfill_2d_inplace["float64_t"]
backfill_2d_inplace_float32 = backfill_2d_inplace["float32_t"]
backfill_2d_inplace_object = backfill_2d_inplace["object"]
backfill_2d_inplace_int64 = backfill_2d_inplace["int64_t"]
backfill_2d_inplace_int32 = backfill_2d_inplace["int32_t"]
backfill_2d_inplace_uint64 = backfill_2d_inplace["uint64_t"]
backfill_2d_inplace_bool = backfill_2d_inplace["uint8_t"]


@cython.wraparound(False)
@cython.boundscheck(False)
def arrmap(ndarray[algos_t] index, object func):
Expand Down Expand Up @@ -875,20 +786,6 @@ def is_monotonic(ndarray[algos_t, ndim=1] arr, bint timelike):
return is_monotonic_inc, is_monotonic_dec, is_strict_monotonic


is_monotonic_float64 = is_monotonic["float64_t"]
is_monotonic_float32 = is_monotonic["float32_t"]
is_monotonic_object = is_monotonic["object"]
is_monotonic_int64 = is_monotonic["int64_t"]
is_monotonic_int32 = is_monotonic["int32_t"]
is_monotonic_int16 = is_monotonic["int16_t"]
is_monotonic_int8 = is_monotonic["int8_t"]
is_monotonic_uint64 = is_monotonic["uint64_t"]
is_monotonic_uint32 = is_monotonic["uint32_t"]
is_monotonic_uint16 = is_monotonic["uint16_t"]
is_monotonic_uint8 = is_monotonic["uint8_t"]
is_monotonic_bool = is_monotonic["uint8_t"]


# generated from template
include "algos_common_helper.pxi"
include "algos_rank_helper.pxi"
Expand Down
12 changes: 0 additions & 12 deletions pandas/_libs/algos_common_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,6 @@ def diff_2d_{{name}}(ndarray[{{c_type}}, ndim=2] arr,
for j in range(start, stop):
out[i, j] = arr[i, j] - arr[i, j - periods]


def put2d_{{name}}_{{dest_name}}(ndarray[{{c_type}}, ndim=2, cast=True] values,
ndarray[int64_t] indexer, Py_ssize_t loc,
ndarray[{{dest_type}}] out):
cdef:
Py_ssize_t i, j, k

k = len(values)
for j in range(k):
i = indexer[j]
out[i] = values[j, loc]

{{endfor}}

# ----------------------------------------------------------------------
Expand Down
15 changes: 7 additions & 8 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ cdef class DatetimeEngine(Int64Engine):
return self.vgetter().view('i8')

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

cpdef get_loc(self, object val):
if is_definitely_invalid_key(val):
Expand Down Expand Up @@ -451,14 +451,13 @@ cdef class DatetimeEngine(Int64Engine):
if other.dtype != self._get_box_dtype():
return np.repeat(-1, len(other)).astype('i4')
other = np.asarray(other).view('i8')
return algos.pad_int64(self._get_index_values(), other, limit=limit)
return algos.pad(self._get_index_values(), other, limit=limit)

def get_backfill_indexer(self, other, limit=None):
if other.dtype != self._get_box_dtype():
return np.repeat(-1, len(other)).astype('i4')
other = np.asarray(other).view('i8')
return algos.backfill_int64(self._get_index_values(), other,
limit=limit)
return algos.backfill(self._get_index_values(), other, limit=limit)


cdef class TimedeltaEngine(DatetimeEngine):
Expand Down Expand Up @@ -492,15 +491,15 @@ cdef class PeriodEngine(Int64Engine):
freq = super(PeriodEngine, self).vgetter().freq
ordinal = periodlib.extract_ordinals(other, freq)

return algos.pad_int64(self._get_index_values(),
np.asarray(ordinal), limit=limit)
return algos.pad(self._get_index_values(),
np.asarray(ordinal), limit=limit)

def get_backfill_indexer(self, other, limit=None):
freq = super(PeriodEngine, self).vgetter().freq
ordinal = periodlib.extract_ordinals(other, freq)

return algos.backfill_int64(self._get_index_values(),
np.asarray(ordinal), limit=limit)
return algos.backfill(self._get_index_values(),
np.asarray(ordinal), limit=limit)

def get_indexer_non_unique(self, targets):
freq = super(PeriodEngine, self).vgetter().freq
Expand Down
8 changes: 3 additions & 5 deletions pandas/_libs/index_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ dtypes = [('Float64', 'float64', 'float64_t', 'Float64', 'float64'),
cdef class {{name}}Engine(IndexEngine):

def _call_monotonic(self, values):
return algos.is_monotonic_{{dtype}}(values, timelike=False)
return algos.is_monotonic(values, timelike=False)

def get_backfill_indexer(self, other, limit=None):
return algos.backfill_{{dtype}}(self._get_index_values(),
other, limit=limit)
return algos.backfill(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)
return algos.pad(self._get_index_values(), other, limit=limit)

cdef _make_hash_table(self, n):
return _hash.{{hashtable_name}}HashTable(n)
Expand Down
Loading

0 comments on commit ca77450

Please sign in to comment.