Skip to content

Commit de87047

Browse files
committed
use more memoryviews
1 parent b9e2278 commit de87047

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

pandas/_libs/algos.pyx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def is_lexsorted(list_of_arrays: list) -> bint:
151151

152152
@cython.boundscheck(False)
153153
@cython.wraparound(False)
154-
def groupsort_indexer(ndarray[int64_t] index, Py_ssize_t ngroups):
154+
def groupsort_indexer(int64_t[:] index, Py_ssize_t ngroups):
155155
"""
156156
compute a 1-d indexer that is an ordering of the passed index,
157157
ordered by the groups. This is a reverse of the label
@@ -373,7 +373,7 @@ ctypedef fused algos_t:
373373
# TODO: unused; needed?
374374
@cython.wraparound(False)
375375
@cython.boundscheck(False)
376-
cpdef map_indices(ndarray[algos_t] index):
376+
cpdef map_indices(algos_t[:] index):
377377
"""
378378
Produce a dict mapping the values of the input array to their respective
379379
locations.
@@ -397,7 +397,7 @@ cpdef map_indices(ndarray[algos_t] index):
397397

398398
@cython.boundscheck(False)
399399
@cython.wraparound(False)
400-
def pad(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
400+
def pad(algos_t[:] old, algos_t[:] new, limit=None):
401401
cdef:
402402
Py_ssize_t i, j, nleft, nright
403403
ndarray[int64_t, ndim=1] indexer
@@ -475,8 +475,9 @@ pad_bool = pad["uint8_t"]
475475

476476
@cython.boundscheck(False)
477477
@cython.wraparound(False)
478-
def pad_inplace(ndarray[algos_t] values,
478+
def pad_inplace(algos_t[:] values,
479479
ndarray[uint8_t, cast=True] mask,
480+
# TODO: What does the cast=True mean? If unneeded, use bint[:]?
480481
limit=None):
481482
cdef:
482483
Py_ssize_t i, N
@@ -595,7 +596,7 @@ D
595596

596597
@cython.boundscheck(False)
597598
@cython.wraparound(False)
598-
def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
599+
def backfill(algos_t[:] old, algos_t[:] new, limit=None):
599600
cdef:
600601
Py_ssize_t i, j, nleft, nright
601602
ndarray[int64_t, ndim=1] indexer
@@ -674,7 +675,7 @@ backfill_bool = backfill["uint8_t"]
674675

675676
@cython.boundscheck(False)
676677
@cython.wraparound(False)
677-
def backfill_inplace(ndarray[algos_t] values,
678+
def backfill_inplace(algos_t[:] values,
678679
ndarray[uint8_t, cast=True] mask,
679680
limit=None):
680681
cdef:
@@ -768,7 +769,7 @@ backfill_2d_inplace_bool = backfill_2d_inplace["uint8_t"]
768769

769770
@cython.wraparound(False)
770771
@cython.boundscheck(False)
771-
def arrmap(ndarray[algos_t] index, object func):
772+
def arrmap(algos_t[:] index, object func):
772773
cdef:
773774
Py_ssize_t length = index.shape[0]
774775
Py_ssize_t i = 0
@@ -793,7 +794,7 @@ arrmap_bool = arrmap["uint8_t"]
793794

794795
@cython.boundscheck(False)
795796
@cython.wraparound(False)
796-
def is_monotonic(ndarray[algos_t] arr, bint timelike):
797+
def is_monotonic(algos_t[:] arr, bint timelike):
797798
"""
798799
Returns
799800
-------

pandas/_libs/lib.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ def maybe_convert_numeric(ndarray[object] values, set na_values,
19091909

19101910
@cython.boundscheck(False)
19111911
@cython.wraparound(False)
1912-
def maybe_convert_objects(ndarray[object] objects, bint try_float=0,
1912+
def maybe_convert_objects(ndarray[object, ndim=1] objects, bint try_float=0,
19131913
bint safe=0, bint convert_datetime=0,
19141914
bint convert_timedelta=0):
19151915
"""

pandas/_libs/reduction.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ cdef inline _extract_result(object res):
438438
res = res[0]
439439
return res
440440

441+
441442
cdef class Slider:
442443
"""
443444
Only handles contiguous data for now

pandas/_libs/sparse.pyx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ cpdef get_blocks(ndarray[int32_t, ndim=1] indices):
315315
lens = lens[:result_indexer]
316316
return locs, lens
317317

318+
318319
# -----------------------------------------------------------------------------
319320
# BlockIndex
320321

@@ -805,10 +806,11 @@ include "sparse_op_helper.pxi"
805806
# Indexing operations
806807

807808
def get_reindexer(ndarray[object, ndim=1] values, dict index_map):
808-
cdef object idx
809-
cdef Py_ssize_t i
810-
cdef Py_ssize_t new_length = len(values)
811-
cdef ndarray[int32_t, ndim=1] indexer
809+
cdef:
810+
object idx
811+
Py_ssize_t i
812+
Py_ssize_t new_length = len(values)
813+
ndarray[int32_t, ndim=1] indexer
812814

813815
indexer = np.empty(new_length, dtype=np.int32)
814816

@@ -861,10 +863,11 @@ def reindex_integer(ndarray[float64_t, ndim=1] values,
861863
# SparseArray mask create operations
862864

863865
def make_mask_object_ndarray(ndarray[object, ndim=1] arr, object fill_value):
864-
cdef object value
865-
cdef Py_ssize_t i
866-
cdef Py_ssize_t new_length = len(arr)
867-
cdef ndarray[int8_t, ndim=1] mask
866+
cdef:
867+
object value
868+
Py_ssize_t i
869+
Py_ssize_t new_length = len(arr)
870+
ndarray[int8_t, ndim=1] mask
868871

869872
mask = np.ones(new_length, dtype=np.int8)
870873

pandas/_libs/tslibs/conversion.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ TD_DTYPE = np.dtype('m8[ns]')
4949

5050
UTC = pytz.UTC
5151

52+
5253
# ----------------------------------------------------------------------
5354
# Misc Helpers
5455

55-
# TODO: How to declare np.datetime64 as the input type?
5656
cdef inline int64_t get_datetime64_nanos(object val) except? -1:
5757
"""
5858
Extract the value and unit from a np.datetime64 object, then convert the

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ cdef inline _npdivmod(x1, x2):
107107
try:
108108
from numpy import divmod as npdivmod
109109
except ImportError:
110+
# numpy < 1.13
110111
npdivmod = _npdivmod
111112

112113

0 commit comments

Comments
 (0)