@@ -18,7 +18,7 @@ PyDateTime_IMPORT
18
18
19
19
import numpy as np
20
20
cimport numpy as cnp
21
- from numpy cimport (ndarray, PyArray_NDIM, PyArray_GETITEM,
21
+ from numpy cimport (ndarray, PyArray_GETITEM,
22
22
PyArray_ITER_DATA, PyArray_ITER_NEXT, PyArray_IterNew,
23
23
flatiter, NPY_OBJECT,
24
24
int64_t,
@@ -74,9 +74,9 @@ cdef bint PY2 = sys.version_info[0] == 2
74
74
cdef double nan = < double > np.NaN
75
75
76
76
77
- def values_from_object (object obj ):
77
+ def values_from_object (obj: object ):
78
78
""" 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
80
80
81
81
func = getattr (obj, ' get_values' , None )
82
82
if func is not None :
@@ -170,7 +170,7 @@ def item_from_zerodim(val: object) -> object:
170
170
@ cython.boundscheck (False )
171
171
def fast_unique_multiple (list arrays ):
172
172
cdef:
173
- ndarray[ object ] buf
173
+ object [: ] buf
174
174
Py_ssize_t k = len (arrays)
175
175
Py_ssize_t i, j, n
176
176
list uniques = []
@@ -586,7 +586,7 @@ def clean_index_list(list obj):
586
586
return np.asarray(obj, dtype = object ), 0
587
587
elif inferred in [' integer' ]:
588
588
589
- # TODO: we infer an integer but it *could* be a unint64
589
+ # TODO: we infer an integer but it *could* be a uint64
590
590
try :
591
591
return np.asarray(obj, dtype = ' int64' ), 0
592
592
except OverflowError :
@@ -688,13 +688,13 @@ def row_bool_subset(ndarray[float64_t, ndim=2] values,
688
688
689
689
@ cython.boundscheck (False )
690
690
@ cython.wraparound (False )
691
- def row_bool_subset_object (ndarray[ object , ndim = 2 ] values,
691
+ def row_bool_subset_object (object[:, : ] values ,
692
692
ndarray[uint8_t , cast = True ] mask):
693
693
cdef:
694
694
Py_ssize_t i, j, n, k, pos = 0
695
695
ndarray[object , ndim= 2 ] out
696
696
697
- n, k = (< object > values).shape
697
+ n, k = (< object > values).shape
698
698
assert (n == len (mask))
699
699
700
700
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):
2129
2129
result = np.empty(n, dtype = object )
2130
2130
for i in range (n):
2131
2131
if mask[i]:
2132
- val = util.get_value_at( arr, i)
2132
+ val = arr[i]
2133
2133
else :
2134
- val = f(util.get_value_at( arr, i) )
2134
+ val = f(arr[i] )
2135
2135
2136
- if util.is_array (val) and PyArray_NDIM(val) == 0 :
2136
+ if cnp.PyArray_IsZeroDim (val):
2137
2137
# unbox 0-dim arrays, GH#690
2138
2138
# TODO: is there a faster way to unbox?
2139
2139
# item_from_zerodim?
@@ -2165,15 +2165,15 @@ def map_infer(ndarray arr, object f, bint convert=1):
2165
2165
"""
2166
2166
cdef:
2167
2167
Py_ssize_t i, n
2168
- ndarray[ object ] result
2168
+ object [: ] result
2169
2169
object val
2170
2170
2171
2171
n = len (arr)
2172
2172
result = np.empty(n, dtype = object )
2173
2173
for i in range (n):
2174
- val = f(util.get_value_at( arr, i) )
2174
+ val = f(arr[i] )
2175
2175
2176
- if util.is_array (val) and PyArray_NDIM(val) == 0 :
2176
+ if cnp.PyArray_IsZeroDim (val):
2177
2177
# unbox 0-dim arrays, GH#690
2178
2178
# TODO: is there a faster way to unbox?
2179
2179
# item_from_zerodim?
@@ -2187,7 +2187,7 @@ def map_infer(ndarray arr, object f, bint convert=1):
2187
2187
convert_datetime = 0 ,
2188
2188
convert_timedelta = 0 )
2189
2189
2190
- return result
2190
+ return result.base # `.base` to access underlying np.ndarray
2191
2191
2192
2192
2193
2193
def to_object_array (list rows , int min_width = 0 ):
@@ -2284,7 +2284,7 @@ def fast_multiget(dict mapping, ndarray keys, default=np.nan):
2284
2284
cdef:
2285
2285
Py_ssize_t i, n = len (keys)
2286
2286
object val
2287
- ndarray[ object ] output = np.empty(n, dtype = ' O' )
2287
+ object [: ] output = np.empty(n, dtype = ' O' )
2288
2288
2289
2289
if n == 0 :
2290
2290
# kludge, for Series
0 commit comments