Skip to content

Commit ca7fb48

Browse files
committed
memoryviews, avoid built-in names
1 parent 9a5d635 commit ca7fb48

File tree

4 files changed

+134
-130
lines changed

4 files changed

+134
-130
lines changed

pandas/_libs/algos.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def arrmap(algos_t[:] index, object func):
764764
cdef:
765765
Py_ssize_t length = index.shape[0]
766766
Py_ssize_t i = 0
767-
ndarray[object] result = np.empty(length, dtype=np.object_)
767+
object[:] result = np.empty(length, dtype=np.object_)
768768

769769
from pandas._libs.lib import maybe_convert_objects
770770

@@ -785,7 +785,7 @@ arrmap_bool = arrmap["uint8_t"]
785785

786786
@cython.boundscheck(False)
787787
@cython.wraparound(False)
788-
def is_monotonic(algos_t[:] arr, bint timelike):
788+
def is_monotonic(ndarray[algos_t, ndim=1] arr, bint timelike):
789789
"""
790790
Returns
791791
-------

pandas/_libs/algos_common_helper.pxi.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def diff_2d_{{name}}(ndarray[{{c_type}}, ndim=2] arr,
7272

7373

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

pandas/_libs/lib.pyx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PyDateTime_IMPORT
1818

1919
import numpy as np
2020
cimport numpy as cnp
21-
from numpy cimport (ndarray, PyArray_NDIM, PyArray_GETITEM,
21+
from numpy cimport (ndarray, PyArray_GETITEM,
2222
PyArray_ITER_DATA, PyArray_ITER_NEXT, PyArray_IterNew,
2323
flatiter, NPY_OBJECT,
2424
int64_t,
@@ -74,9 +74,9 @@ cdef bint PY2 = sys.version_info[0] == 2
7474
cdef double nan = <double>np.NaN
7575

7676

77-
def values_from_object(object obj):
77+
def values_from_object(obj: object):
7878
""" return my values or the object if we are say an ndarray """
79-
cdef func # TODO: Does declaring this without a type accomplish anything?
79+
func: object
8080

8181
func = getattr(obj, 'get_values', None)
8282
if func is not None:
@@ -170,7 +170,7 @@ def item_from_zerodim(val: object) -> object:
170170
@cython.boundscheck(False)
171171
def fast_unique_multiple(list arrays):
172172
cdef:
173-
ndarray[object] buf
173+
object[:] buf
174174
Py_ssize_t k = len(arrays)
175175
Py_ssize_t i, j, n
176176
list uniques = []
@@ -586,7 +586,7 @@ def clean_index_list(list obj):
586586
return np.asarray(obj, dtype=object), 0
587587
elif inferred in ['integer']:
588588

589-
# TODO: we infer an integer but it *could* be a unint64
589+
# TODO: we infer an integer but it *could* be a uint64
590590
try:
591591
return np.asarray(obj, dtype='int64'), 0
592592
except OverflowError:
@@ -688,13 +688,13 @@ def row_bool_subset(ndarray[float64_t, ndim=2] values,
688688

689689
@cython.boundscheck(False)
690690
@cython.wraparound(False)
691-
def row_bool_subset_object(ndarray[object, ndim=2] values,
691+
def row_bool_subset_object(object[:, :] values,
692692
ndarray[uint8_t, cast=True] mask):
693693
cdef:
694694
Py_ssize_t i, j, n, k, pos = 0
695695
ndarray[object, ndim=2] out
696696

697-
n, k = (<object> values).shape
697+
n, k = (<object>values).shape
698698
assert (n == len(mask))
699699

700700
out = np.empty((mask.sum(), k), dtype=object)
@@ -2129,11 +2129,11 @@ def map_infer_mask(ndarray arr, object f, uint8_t[:] mask, bint convert=1):
21292129
result = np.empty(n, dtype=object)
21302130
for i in range(n):
21312131
if mask[i]:
2132-
val = util.get_value_at(arr, i)
2132+
val = arr[i]
21332133
else:
2134-
val = f(util.get_value_at(arr, i))
2134+
val = f(arr[i])
21352135

2136-
if util.is_array(val) and PyArray_NDIM(val) == 0:
2136+
if cnp.PyArray_IsZeroDim(val):
21372137
# unbox 0-dim arrays, GH#690
21382138
# TODO: is there a faster way to unbox?
21392139
# item_from_zerodim?
@@ -2165,15 +2165,15 @@ def map_infer(ndarray arr, object f, bint convert=1):
21652165
"""
21662166
cdef:
21672167
Py_ssize_t i, n
2168-
ndarray[object] result
2168+
object[:] result
21692169
object val
21702170

21712171
n = len(arr)
21722172
result = np.empty(n, dtype=object)
21732173
for i in range(n):
2174-
val = f(util.get_value_at(arr, i))
2174+
val = f(arr[i])
21752175

2176-
if util.is_array(val) and PyArray_NDIM(val) == 0:
2176+
if cnp.PyArray_IsZeroDim(val):
21772177
# unbox 0-dim arrays, GH#690
21782178
# TODO: is there a faster way to unbox?
21792179
# item_from_zerodim?
@@ -2187,7 +2187,7 @@ def map_infer(ndarray arr, object f, bint convert=1):
21872187
convert_datetime=0,
21882188
convert_timedelta=0)
21892189

2190-
return result
2190+
return result.base # `.base` to access underlying np.ndarray
21912191

21922192

21932193
def to_object_array(list rows, int min_width=0):
@@ -2284,7 +2284,7 @@ def fast_multiget(dict mapping, ndarray keys, default=np.nan):
22842284
cdef:
22852285
Py_ssize_t i, n = len(keys)
22862286
object val
2287-
ndarray[object] output = np.empty(n, dtype='O')
2287+
object[:] output = np.empty(n, dtype='O')
22882288

22892289
if n == 0:
22902290
# kludge, for Series

0 commit comments

Comments
 (0)