@@ -68,9 +68,6 @@ cdef extern from "numpy/arrayobject.h":
68
68
object fields
69
69
tuple names
70
70
71
- cdef extern from " numpy/ndarrayobject.h" :
72
- bint PyArray_CheckScalar(obj) nogil
73
-
74
71
75
72
cdef extern from " src/parse_helper.h" :
76
73
int floatify(object , float64_t * result, int * maybe_int) except - 1
@@ -212,24 +209,6 @@ def is_scalar(val: object) -> bool:
212
209
or is_offset_object(val))
213
210
214
211
215
- cdef inline int64_t get_itemsize(object val):
216
- """
217
- Get the itemsize of a NumPy scalar, -1 if not a NumPy scalar.
218
-
219
- Parameters
220
- ----------
221
- val : object
222
-
223
- Returns
224
- -------
225
- is_ndarray : bool
226
- """
227
- if PyArray_CheckScalar(val):
228
- return cnp.PyArray_DescrFromScalar(val).itemsize
229
- else :
230
- return - 1
231
-
232
-
233
212
def is_iterator (obj: object ) -> bool:
234
213
"""
235
214
Check if the object is an iterator.
@@ -2209,7 +2188,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False,
2209
2188
2210
2189
Parameters
2211
2190
----------
2212
- objects : ndarray[object]
2191
+ values : ndarray[object]
2213
2192
Array of object elements to convert.
2214
2193
try_float : bool , default False
2215
2194
If an array-like object contains only float or NaN values is
@@ -2233,7 +2212,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False,
2233
2212
Array of converted object values to more specific dtypes if applicable.
2234
2213
"""
2235
2214
cdef:
2236
- Py_ssize_t i , n , itemsize_max = 0
2215
+ Py_ssize_t i , n
2237
2216
ndarray[float64_t] floats
2238
2217
ndarray[complex128_t] complexes
2239
2218
ndarray[int64_t] ints
@@ -2266,10 +2245,6 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False,
2266
2245
2267
2246
for i in range(n ):
2268
2247
val = objects[i]
2269
- if itemsize_max != - 1 :
2270
- itemsize = get_itemsize(val)
2271
- if itemsize > itemsize_max or itemsize == - 1 :
2272
- itemsize_max = itemsize
2273
2248
2274
2249
if val is None :
2275
2250
seen.null_ = True
@@ -2371,101 +2346,92 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False,
2371
2346
seen.object_ = True
2372
2347
2373
2348
if not seen.object_:
2374
- result = None
2375
2349
if not safe:
2376
2350
if seen.null_ or seen.nan_:
2377
2351
if seen.is_float_or_complex:
2378
2352
if seen.complex_:
2379
- result = complexes
2353
+ return complexes
2380
2354
elif seen.float_:
2381
- result = floats
2355
+ return floats
2382
2356
elif seen.int_:
2383
2357
if convert_to_nullable_integer:
2384
2358
from pandas.core.arrays import IntegerArray
2385
- result = IntegerArray(ints, mask)
2359
+ return IntegerArray(ints, mask)
2386
2360
else :
2387
- result = floats
2361
+ return floats
2388
2362
elif seen.nan_:
2389
- result = floats
2363
+ return floats
2390
2364
else :
2391
2365
if not seen.bool_:
2392
2366
if seen.datetime_:
2393
2367
if not seen.numeric_ and not seen.timedelta_:
2394
- result = datetimes
2368
+ return datetimes
2395
2369
elif seen.timedelta_:
2396
2370
if not seen.numeric_:
2397
- result = timedeltas
2371
+ return timedeltas
2398
2372
elif seen.nat_:
2399
2373
if not seen.numeric_:
2400
2374
if convert_datetime and convert_timedelta:
2401
2375
# TODO: array full of NaT ambiguity resolve here needed
2402
2376
pass
2403
2377
elif convert_datetime:
2404
- result = datetimes
2378
+ return datetimes
2405
2379
elif convert_timedelta:
2406
- result = timedeltas
2380
+ return timedeltas
2407
2381
else :
2408
2382
if seen.complex_:
2409
- result = complexes
2383
+ return complexes
2410
2384
elif seen.float_:
2411
- result = floats
2385
+ return floats
2412
2386
elif seen.int_:
2413
2387
if seen.uint_:
2414
- result = uints
2388
+ return uints
2415
2389
else :
2416
- result = ints
2390
+ return ints
2417
2391
elif seen.is_bool:
2418
- result = bools.view(np.bool_)
2392
+ return bools.view(np.bool_)
2419
2393
2420
2394
else :
2421
2395
# don't cast int to float, etc.
2422
2396
if seen.null_:
2423
2397
if seen.is_float_or_complex:
2424
2398
if seen.complex_:
2425
2399
if not seen.int_:
2426
- result = complexes
2400
+ return complexes
2427
2401
elif seen.float_ or seen.nan_:
2428
2402
if not seen.int_:
2429
- result = floats
2403
+ return floats
2430
2404
else :
2431
2405
if not seen.bool_:
2432
2406
if seen.datetime_:
2433
2407
if not seen.numeric_ and not seen.timedelta_:
2434
- result = datetimes
2408
+ return datetimes
2435
2409
elif seen.timedelta_:
2436
2410
if not seen.numeric_:
2437
- result = timedeltas
2411
+ return timedeltas
2438
2412
elif seen.nat_:
2439
2413
if not seen.numeric_:
2440
2414
if convert_datetime and convert_timedelta:
2441
2415
# TODO: array full of NaT ambiguity resolve here needed
2442
2416
pass
2443
2417
elif convert_datetime:
2444
- result = datetimes
2418
+ return datetimes
2445
2419
elif convert_timedelta:
2446
- result = timedeltas
2420
+ return timedeltas
2447
2421
else :
2448
2422
if seen.complex_:
2449
2423
if not seen.int_:
2450
- result = complexes
2424
+ return complexes
2451
2425
elif seen.float_ or seen.nan_:
2452
2426
if not seen.int_:
2453
- result = floats
2427
+ return floats
2454
2428
elif seen.int_:
2455
2429
if seen.uint_:
2456
- result = uints
2430
+ return uints
2457
2431
else :
2458
- result = ints
2432
+ return ints
2459
2433
elif seen.is_bool and not seen.nan_:
2460
- result = bools.view(np.bool_)
2461
-
2462
- if result is uints or result is ints or result is floats or result is complexes:
2463
- # cast to the largest itemsize when all values are NumPy scalars
2464
- if itemsize_max > 0 and itemsize_max != result.dtype.itemsize:
2465
- result = result.astype(result.dtype.kind + str (itemsize_max))
2466
- return result
2467
- elif result is not None :
2468
- return result
2434
+ return bools.view(np.bool_)
2469
2435
2470
2436
return objects
2471
2437
@@ -2488,7 +2454,7 @@ no_default = NoDefault.no_default # Sentinel indicating the default value.
2488
2454
@cython.wraparound(False )
2489
2455
def map_infer_mask(ndarray arr , object f , const uint8_t[:] mask , bint convert = True ,
2490
2456
object na_value = no_default, cnp.dtype dtype = np.dtype(object )
2491
- ) -> np.ndarray :
2457
+ ) -> "ArrayLike" :
2492
2458
"""
2493
2459
Substitute for np.vectorize with pandas-friendly dtype inference.
2494
2460
@@ -2508,7 +2474,7 @@ def map_infer_mask(ndarray arr, object f, const uint8_t[:] mask, bint convert=Tr
2508
2474
2509
2475
Returns
2510
2476
-------
2511
- np.ndarray
2477
+ np.ndarray or ExtensionArray
2512
2478
"""
2513
2479
cdef:
2514
2480
Py_ssize_t i , n
@@ -2545,7 +2511,7 @@ def map_infer_mask(ndarray arr, object f, const uint8_t[:] mask, bint convert=Tr
2545
2511
@ cython.wraparound (False )
2546
2512
def map_infer (
2547
2513
ndarray arr , object f , bint convert = True , bint ignore_na = False
2548
- ) -> np.ndarray :
2514
+ ) -> "ArrayLike" :
2549
2515
"""
2550
2516
Substitute for np.vectorize with pandas-friendly dtype inference.
2551
2517
@@ -2559,7 +2525,7 @@ def map_infer(
2559
2525
2560
2526
Returns
2561
2527
-------
2562
- np.ndarray
2528
+ np.ndarray or ExtensionArray
2563
2529
"""
2564
2530
cdef:
2565
2531
Py_ssize_t i , n
@@ -2697,7 +2663,7 @@ def to_object_array_tuples(rows: object) -> np.ndarray:
2697
2663
2698
2664
@ cython.wraparound (False )
2699
2665
@ cython.boundscheck (False )
2700
- def fast_multiget (dict mapping , ndarray keys , default = np.nan) -> np.ndarray :
2666
+ def fast_multiget (dict mapping , ndarray keys , default = np.nan) -> "ArrayLike" :
2701
2667
cdef:
2702
2668
Py_ssize_t i , n = len (keys)
2703
2669
object val
0 commit comments