@@ -263,10 +263,10 @@ def fast_unique_multiple_list_gen(object gen, bint sort=True):
263
263
264
264
@ cython.wraparound (False )
265
265
@ cython.boundscheck (False )
266
- def dicts_to_array (list dicts , list columns ):
266
+ def dicts_to_array (dicts: list , columns: list ):
267
267
cdef:
268
268
Py_ssize_t i, j, k, n
269
- ndarray[ object , ndim = 2 ] result
269
+ object [:, : ] result
270
270
dict row
271
271
object col, onan = np.nan
272
272
@@ -284,7 +284,7 @@ def dicts_to_array(list dicts, list columns):
284
284
else :
285
285
result[i, j] = onan
286
286
287
- return result
287
+ return result.base # `.base` to access underlying np.ndarray
288
288
289
289
290
290
def fast_zip (list ndarrays ):
@@ -343,17 +343,17 @@ def get_reverse_indexer(int64_t[:] indexer, Py_ssize_t length):
343
343
344
344
cdef:
345
345
Py_ssize_t i, n = len (indexer)
346
- ndarray[ int64_t] rev_indexer
346
+ int64_t[: ] rev_indexer
347
347
int64_t idx
348
348
349
349
rev_indexer = np.empty(length, dtype = np.int64)
350
- rev_indexer.fill( - 1 )
350
+ rev_indexer[:] = - 1
351
351
for i in range (n):
352
352
idx = indexer[i]
353
353
if idx != - 1 :
354
354
rev_indexer[idx] = i
355
355
356
- return rev_indexer
356
+ return rev_indexer.base # `.base` to access underlying np.ndarray
357
357
358
358
359
359
@ cython.wraparound (False )
@@ -460,7 +460,7 @@ def maybe_booleans_to_slice(ndarray[uint8_t] mask):
460
460
461
461
@ cython.wraparound (False )
462
462
@ cython.boundscheck (False )
463
- def array_equivalent_object (left: object[:], right: object[:]) -> bint :
463
+ def array_equivalent_object (left: object[:], right: object[:]) -> bool :
464
464
""" perform an element by element comparion on 1-d object arrays
465
465
taking into account nan positions """
466
466
cdef:
@@ -484,7 +484,7 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bint:
484
484
def astype_intsafe (object[:] arr , new_dtype ):
485
485
cdef:
486
486
Py_ssize_t i, n = len (arr)
487
- object v
487
+ object val
488
488
bint is_datelike
489
489
ndarray result
490
490
@@ -493,11 +493,11 @@ def astype_intsafe(object[:] arr, new_dtype):
493
493
494
494
result = np.empty(n, dtype = new_dtype)
495
495
for i in range (n):
496
- v = arr[i]
497
- if is_datelike and checknull(v ):
496
+ val = arr[i]
497
+ if is_datelike and checknull(val ):
498
498
result[i] = NPY_NAT
499
499
else :
500
- result[i] = v
500
+ result[i] = val
501
501
502
502
return result
503
503
@@ -524,7 +524,7 @@ def astype_unicode(arr: ndarray, skipna: bool=False) -> ndarray[object]:
524
524
cdef:
525
525
object arr_i
526
526
Py_ssize_t i , n = arr.size
527
- ndarray[ object] result = np.empty(n, dtype = object )
527
+ object[: ] result = np.empty(n, dtype = object )
528
528
529
529
for i in range(n ):
530
530
arr_i = arr[i]
@@ -534,7 +534,7 @@ def astype_unicode(arr: ndarray, skipna: bool=False) -> ndarray[object]:
534
534
535
535
result[i] = arr_i
536
536
537
- return result
537
+ return result.base # `.base` to access underlying np.ndarray
538
538
539
539
540
540
@ cython.wraparound (False )
@@ -559,7 +559,7 @@ def astype_str(arr: ndarray, skipna: bool = False) -> ndarray[object]:
559
559
cdef:
560
560
object arr_i
561
561
Py_ssize_t i , n = arr.size
562
- ndarray[ object] result = np.empty(n, dtype = object )
562
+ object[: ] result = np.empty(n, dtype = object )
563
563
564
564
for i in range(n ):
565
565
arr_i = arr[i]
@@ -569,24 +569,24 @@ def astype_str(arr: ndarray, skipna: bool = False) -> ndarray[object]:
569
569
570
570
result[i] = arr_i
571
571
572
- return result
572
+ return result.base # `.base` to access underlying np.ndarray
573
573
574
574
575
575
@ cython.wraparound (False )
576
576
@ cython.boundscheck (False )
577
- def clean_index_list (list obj ):
577
+ def clean_index_list (obj: list ):
578
578
"""
579
579
Utility used in pandas.core.index.ensure_index
580
580
"""
581
581
cdef:
582
582
Py_ssize_t i, n = len (obj)
583
- object v
583
+ object val
584
584
bint all_arrays = 1
585
585
586
586
for i in range (n):
587
- v = obj[i]
588
- if not (isinstance (v , list ) or
589
- util.is_array(v ) or hasattr (v , ' _data' )):
587
+ val = obj[i]
588
+ if not (isinstance (val , list ) or
589
+ util.is_array(val ) or hasattr (val , ' _data' )):
590
590
all_arrays = 0
591
591
break
592
592
@@ -595,11 +595,9 @@ def clean_index_list(list obj):
595
595
596
596
# don't force numpy coerce with nan's
597
597
inferred = infer_dtype(obj)
598
- if inferred in [' string' , ' bytes' , ' unicode' ,
599
- ' mixed' , ' mixed-integer' ]:
598
+ if inferred in [' string' , ' bytes' , ' unicode' , ' mixed' , ' mixed-integer' ]:
600
599
return np.asarray(obj, dtype = object ), 0
601
600
elif inferred in [' integer' ]:
602
-
603
601
# TODO: we infer an integer but it *could* be a uint64
604
602
try :
605
603
return np.asarray(obj, dtype = ' int64' ), 0
@@ -680,13 +678,13 @@ def generate_bins_dt64(ndarray[int64_t] values, int64_t[:] binner,
680
678
681
679
@ cython.boundscheck (False )
682
680
@ cython.wraparound (False )
683
- def row_bool_subset (ndarray[ float64_t , ndim = 2 ] values,
681
+ def row_bool_subset (float64_t[:, : ] values ,
684
682
ndarray[uint8_t , cast = True ] mask):
685
683
cdef:
686
684
Py_ssize_t i, j, n, k, pos = 0
687
- ndarray[ float64_t, ndim = 2 ] out
685
+ float64_t[:, : ] out
688
686
689
- n, k = (< object > values).shape
687
+ n, k = (< object > values).shape
690
688
assert (n == len (mask))
691
689
692
690
out = np.empty((mask.sum(), k), dtype = np.float64)
@@ -697,7 +695,7 @@ def row_bool_subset(ndarray[float64_t, ndim=2] values,
697
695
out[pos, j] = values[i, j]
698
696
pos += 1
699
697
700
- return out
698
+ return out.base # `.base` to access underlying np.ndarray
701
699
702
700
703
701
@ cython.boundscheck (False )
@@ -706,7 +704,7 @@ def row_bool_subset_object(object[:, :] values,
706
704
ndarray[uint8_t , cast = True ] mask):
707
705
cdef:
708
706
Py_ssize_t i, j, n, k, pos = 0
709
- ndarray[ object , ndim = 2 ] out
707
+ object [:, : ] out
710
708
711
709
n, k = (< object > values).shape
712
710
assert (n == len (mask))
@@ -719,7 +717,7 @@ def row_bool_subset_object(object[:, :] values,
719
717
out[pos, j] = values[i, j]
720
718
pos += 1
721
719
722
- return out
720
+ return out.base # `.base` to access underlying np.ndarray
723
721
724
722
725
723
@ cython.boundscheck (False )
@@ -846,19 +844,19 @@ def indices_fast(object index, int64_t[:] labels, list keys,
846
844
847
845
# core.common import for fast inference checks
848
846
849
- def is_float (obj: object ) -> bint :
847
+ def is_float (obj: object ) -> bool :
850
848
return util.is_float_object(obj )
851
849
852
850
853
- def is_integer(obj: object ) -> bint :
851
+ def is_integer(obj: object ) -> bool :
854
852
return util.is_integer_object(obj )
855
853
856
854
857
- def is_bool(obj: object ) -> bint :
855
+ def is_bool(obj: object ) -> bool :
858
856
return util.is_bool_object(obj )
859
857
860
858
861
- def is_complex(obj: object ) -> bint :
859
+ def is_complex(obj: object ) -> bool :
862
860
return util.is_complex_object(obj )
863
861
864
862
@@ -870,7 +868,7 @@ cpdef bint is_interval(object obj):
870
868
return getattr (obj, ' _typ' , ' _typ' ) == ' interval'
871
869
872
870
873
- def is_period (val: object ) -> bint :
871
+ def is_period (val: object ) -> bool :
874
872
""" Return a boolean if this is a Period object """
875
873
return util.is_period_object(val )
876
874
@@ -1352,7 +1350,7 @@ def infer_datetimelike_array(arr: object) -> object:
1352
1350
seen_datetime = 1
1353
1351
elif PyDate_Check(v):
1354
1352
seen_date = 1
1355
- elif is_timedelta(v) or util.is_timedelta64_object(v) :
1353
+ elif is_timedelta(v):
1356
1354
# timedelta, or timedelta64
1357
1355
seen_timedelta = 1
1358
1356
else :
@@ -1633,7 +1631,7 @@ cpdef bint is_datetime64_array(ndarray values):
1633
1631
1634
1632
@ cython.wraparound (False )
1635
1633
@ cython.boundscheck (False )
1636
- def is_datetime_with_singletz_array (values: ndarray ) -> bint :
1634
+ def is_datetime_with_singletz_array (values: ndarray ) -> bool :
1637
1635
"""
1638
1636
Check values have the same tzinfo attribute.
1639
1637
Doesn't check values are datetime-like types.
@@ -2138,7 +2136,7 @@ def map_infer_mask(ndarray arr, object f, uint8_t[:] mask, bint convert=1):
2138
2136
"""
2139
2137
cdef:
2140
2138
Py_ssize_t i, n
2141
- ndarray[ object ] result
2139
+ object [: ] result
2142
2140
object val
2143
2141
2144
2142
n = len (arr)
@@ -2163,7 +2161,7 @@ def map_infer_mask(ndarray arr, object f, uint8_t[:] mask, bint convert=1):
2163
2161
convert_datetime = 0 ,
2164
2162
convert_timedelta = 0 )
2165
2163
2166
- return result
2164
+ return result.base # `.base` to access underlying np.ndarray
2167
2165
2168
2166
2169
2167
@ cython.wraparound (False )
@@ -2208,7 +2206,7 @@ def map_infer(ndarray arr, object f, bint convert=1):
2208
2206
return result.base # `.base` to access underlying np.ndarray
2209
2207
2210
2208
2211
- def to_object_array (list rows , int min_width = 0 ):
2209
+ def to_object_array (rows: list , min_width: int = 0 ):
2212
2210
"""
2213
2211
Convert a list of lists into an object array.
2214
2212
@@ -2228,7 +2226,7 @@ def to_object_array(list rows, int min_width=0):
2228
2226
"""
2229
2227
cdef:
2230
2228
Py_ssize_t i, j, n, k, tmp
2231
- ndarray[ object , ndim = 2 ] result
2229
+ object [:, : ] result
2232
2230
list row
2233
2231
2234
2232
n = len (rows)
@@ -2247,13 +2245,13 @@ def to_object_array(list rows, int min_width=0):
2247
2245
for j in range (len (row)):
2248
2246
result[i, j] = row[j]
2249
2247
2250
- return result
2248
+ return result.base # `.base` to access underlying np.ndarray
2251
2249
2252
2250
2253
2251
def tuples_to_object_array (ndarray[object] tuples ):
2254
2252
cdef:
2255
2253
Py_ssize_t i, j, n, k, tmp
2256
- ndarray[ object , ndim = 2 ] result
2254
+ object [:, : ] result
2257
2255
tuple tup
2258
2256
2259
2257
n = len (tuples)
@@ -2264,13 +2262,13 @@ def tuples_to_object_array(ndarray[object] tuples):
2264
2262
for j in range (k):
2265
2263
result[i, j] = tup[j]
2266
2264
2267
- return result
2265
+ return result.base # `.base` to access underlying np.ndarray
2268
2266
2269
2267
2270
- def to_object_array_tuples (list rows ):
2268
+ def to_object_array_tuples (rows: list ):
2271
2269
cdef:
2272
2270
Py_ssize_t i, j, n, k, tmp
2273
- ndarray[ object , ndim = 2 ] result
2271
+ object [:, : ] result
2274
2272
tuple row
2275
2273
2276
2274
n = len (rows)
@@ -2295,7 +2293,7 @@ def to_object_array_tuples(list rows):
2295
2293
for j in range (len (row)):
2296
2294
result[i, j] = row[j]
2297
2295
2298
- return result
2296
+ return result.base # `.base` to access underlying np.ndarray
2299
2297
2300
2298
2301
2299
@ cython.wraparound (False )
0 commit comments