Skip to content

Commit ca77450

Browse files
jbrockmendelPingviinituutti
authored andcommitted
clear out a bunch of algos, de-duplicate a bunch of core.missing (pandas-dev#24652)
1 parent 3f2f01e commit ca77450

File tree

7 files changed

+50
-239
lines changed

7 files changed

+50
-239
lines changed

pandas/_libs/algos.pyx

-103
Original file line numberDiff line numberDiff line change
@@ -369,31 +369,6 @@ ctypedef fused algos_t:
369369
uint8_t
370370

371371

372-
# TODO: unused; needed?
373-
@cython.wraparound(False)
374-
@cython.boundscheck(False)
375-
cpdef map_indices(ndarray[algos_t] index):
376-
"""
377-
Produce a dict mapping the values of the input array to their respective
378-
locations.
379-
380-
Example:
381-
array(['hi', 'there']) --> {'hi' : 0 , 'there' : 1}
382-
383-
Better to do this with Cython because of the enormous speed boost.
384-
"""
385-
cdef:
386-
Py_ssize_t i, length
387-
dict result = {}
388-
389-
length = len(index)
390-
391-
for i in range(length):
392-
result[index[i]] = i
393-
394-
return result
395-
396-
397372
@cython.boundscheck(False)
398373
@cython.wraparound(False)
399374
def pad(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
@@ -458,20 +433,6 @@ def pad(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
458433
return indexer
459434

460435

461-
pad_float64 = pad["float64_t"]
462-
pad_float32 = pad["float32_t"]
463-
pad_object = pad["object"]
464-
pad_int64 = pad["int64_t"]
465-
pad_int32 = pad["int32_t"]
466-
pad_int16 = pad["int16_t"]
467-
pad_int8 = pad["int8_t"]
468-
pad_uint64 = pad["uint64_t"]
469-
pad_uint32 = pad["uint32_t"]
470-
pad_uint16 = pad["uint16_t"]
471-
pad_uint8 = pad["uint8_t"]
472-
pad_bool = pad["uint8_t"]
473-
474-
475436
@cython.boundscheck(False)
476437
@cython.wraparound(False)
477438
def pad_inplace(ndarray[algos_t] values,
@@ -509,15 +470,6 @@ def pad_inplace(ndarray[algos_t] values,
509470
val = values[i]
510471

511472

512-
pad_inplace_float64 = pad_inplace["float64_t"]
513-
pad_inplace_float32 = pad_inplace["float32_t"]
514-
pad_inplace_object = pad_inplace["object"]
515-
pad_inplace_int64 = pad_inplace["int64_t"]
516-
pad_inplace_int32 = pad_inplace["int32_t"]
517-
pad_inplace_uint64 = pad_inplace["uint64_t"]
518-
pad_inplace_bool = pad_inplace["uint8_t"]
519-
520-
521473
@cython.boundscheck(False)
522474
@cython.wraparound(False)
523475
def pad_2d_inplace(ndarray[algos_t, ndim=2] values,
@@ -557,15 +509,6 @@ def pad_2d_inplace(ndarray[algos_t, ndim=2] values,
557509
val = values[j, i]
558510

559511

560-
pad_2d_inplace_float64 = pad_2d_inplace["float64_t"]
561-
pad_2d_inplace_float32 = pad_2d_inplace["float32_t"]
562-
pad_2d_inplace_object = pad_2d_inplace["object"]
563-
pad_2d_inplace_int64 = pad_2d_inplace["int64_t"]
564-
pad_2d_inplace_int32 = pad_2d_inplace["int32_t"]
565-
pad_2d_inplace_uint64 = pad_2d_inplace["uint64_t"]
566-
pad_2d_inplace_bool = pad_2d_inplace["uint8_t"]
567-
568-
569512
"""
570513
Backfilling logic for generating fill vector
571514
@@ -657,20 +600,6 @@ def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
657600
return indexer
658601

659602

660-
backfill_float64 = backfill["float64_t"]
661-
backfill_float32 = backfill["float32_t"]
662-
backfill_object = backfill["object"]
663-
backfill_int64 = backfill["int64_t"]
664-
backfill_int32 = backfill["int32_t"]
665-
backfill_int16 = backfill["int16_t"]
666-
backfill_int8 = backfill["int8_t"]
667-
backfill_uint64 = backfill["uint64_t"]
668-
backfill_uint32 = backfill["uint32_t"]
669-
backfill_uint16 = backfill["uint16_t"]
670-
backfill_uint8 = backfill["uint8_t"]
671-
backfill_bool = backfill["uint8_t"]
672-
673-
674603
@cython.boundscheck(False)
675604
@cython.wraparound(False)
676605
def backfill_inplace(ndarray[algos_t] values,
@@ -708,15 +637,6 @@ def backfill_inplace(ndarray[algos_t] values,
708637
val = values[i]
709638

710639

711-
backfill_inplace_float64 = backfill_inplace["float64_t"]
712-
backfill_inplace_float32 = backfill_inplace["float32_t"]
713-
backfill_inplace_object = backfill_inplace["object"]
714-
backfill_inplace_int64 = backfill_inplace["int64_t"]
715-
backfill_inplace_int32 = backfill_inplace["int32_t"]
716-
backfill_inplace_uint64 = backfill_inplace["uint64_t"]
717-
backfill_inplace_bool = backfill_inplace["uint8_t"]
718-
719-
720640
@cython.boundscheck(False)
721641
@cython.wraparound(False)
722642
def backfill_2d_inplace(ndarray[algos_t, ndim=2] values,
@@ -756,15 +676,6 @@ def backfill_2d_inplace(ndarray[algos_t, ndim=2] values,
756676
val = values[j, i]
757677

758678

759-
backfill_2d_inplace_float64 = backfill_2d_inplace["float64_t"]
760-
backfill_2d_inplace_float32 = backfill_2d_inplace["float32_t"]
761-
backfill_2d_inplace_object = backfill_2d_inplace["object"]
762-
backfill_2d_inplace_int64 = backfill_2d_inplace["int64_t"]
763-
backfill_2d_inplace_int32 = backfill_2d_inplace["int32_t"]
764-
backfill_2d_inplace_uint64 = backfill_2d_inplace["uint64_t"]
765-
backfill_2d_inplace_bool = backfill_2d_inplace["uint8_t"]
766-
767-
768679
@cython.wraparound(False)
769680
@cython.boundscheck(False)
770681
def arrmap(ndarray[algos_t] index, object func):
@@ -875,20 +786,6 @@ def is_monotonic(ndarray[algos_t, ndim=1] arr, bint timelike):
875786
return is_monotonic_inc, is_monotonic_dec, is_strict_monotonic
876787

877788

878-
is_monotonic_float64 = is_monotonic["float64_t"]
879-
is_monotonic_float32 = is_monotonic["float32_t"]
880-
is_monotonic_object = is_monotonic["object"]
881-
is_monotonic_int64 = is_monotonic["int64_t"]
882-
is_monotonic_int32 = is_monotonic["int32_t"]
883-
is_monotonic_int16 = is_monotonic["int16_t"]
884-
is_monotonic_int8 = is_monotonic["int8_t"]
885-
is_monotonic_uint64 = is_monotonic["uint64_t"]
886-
is_monotonic_uint32 = is_monotonic["uint32_t"]
887-
is_monotonic_uint16 = is_monotonic["uint16_t"]
888-
is_monotonic_uint8 = is_monotonic["uint8_t"]
889-
is_monotonic_bool = is_monotonic["uint8_t"]
890-
891-
892789
# generated from template
893790
include "algos_common_helper.pxi"
894791
include "algos_rank_helper.pxi"

pandas/_libs/algos_common_helper.pxi.in

-12
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@ def diff_2d_{{name}}(ndarray[{{c_type}}, ndim=2] arr,
7070
for j in range(start, stop):
7171
out[i, j] = arr[i, j] - arr[i, j - periods]
7272

73-
74-
def put2d_{{name}}_{{dest_name}}(ndarray[{{c_type}}, ndim=2, cast=True] values,
75-
ndarray[int64_t] indexer, Py_ssize_t loc,
76-
ndarray[{{dest_type}}] out):
77-
cdef:
78-
Py_ssize_t i, j, k
79-
80-
k = len(values)
81-
for j in range(k):
82-
i = indexer[j]
83-
out[i] = values[j, loc]
84-
8573
{{endfor}}
8674

8775
# ----------------------------------------------------------------------

pandas/_libs/index.pyx

+7-8
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ cdef class DatetimeEngine(Int64Engine):
392392
return self.vgetter().view('i8')
393393

394394
def _call_monotonic(self, values):
395-
return algos.is_monotonic_int64(values, timelike=True)
395+
return algos.is_monotonic(values, timelike=True)
396396

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

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

463462

464463
cdef class TimedeltaEngine(DatetimeEngine):
@@ -492,15 +491,15 @@ cdef class PeriodEngine(Int64Engine):
492491
freq = super(PeriodEngine, self).vgetter().freq
493492
ordinal = periodlib.extract_ordinals(other, freq)
494493

495-
return algos.pad_int64(self._get_index_values(),
496-
np.asarray(ordinal), limit=limit)
494+
return algos.pad(self._get_index_values(),
495+
np.asarray(ordinal), limit=limit)
497496

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

502-
return algos.backfill_int64(self._get_index_values(),
503-
np.asarray(ordinal), limit=limit)
501+
return algos.backfill(self._get_index_values(),
502+
np.asarray(ordinal), limit=limit)
504503

505504
def get_indexer_non_unique(self, targets):
506505
freq = super(PeriodEngine, self).vgetter().freq

pandas/_libs/index_class_helper.pxi.in

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ dtypes = [('Float64', 'float64', 'float64_t', 'Float64', 'float64'),
3131
cdef class {{name}}Engine(IndexEngine):
3232

3333
def _call_monotonic(self, values):
34-
return algos.is_monotonic_{{dtype}}(values, timelike=False)
34+
return algos.is_monotonic(values, timelike=False)
3535

3636
def get_backfill_indexer(self, other, limit=None):
37-
return algos.backfill_{{dtype}}(self._get_index_values(),
38-
other, limit=limit)
37+
return algos.backfill(self._get_index_values(), other, limit=limit)
3938

4039
def get_pad_indexer(self, other, limit=None):
41-
return algos.pad_{{dtype}}(self._get_index_values(),
42-
other, limit=limit)
40+
return algos.pad(self._get_index_values(), other, limit=limit)
4341

4442
cdef _make_hash_table(self, n):
4543
return _hash.{{hashtable_name}}HashTable(n)

0 commit comments

Comments
 (0)