@@ -1284,13 +1284,12 @@ cdef class Seen:
1284
1284
1285
1285
@property
1286
1286
def is_bool (self ):
1287
- return not (self .datetime_ or self .numeric_ or self .timedelta_
1288
- or self .nat_)
1289
-
1290
- @property
1291
- def is_float_or_complex (self ):
1292
- return not (self .bool_ or self .datetime_ or self .timedelta_
1293
- or self .nat_)
1287
+ # i.e. not (anything but bool)
1288
+ return not (
1289
+ self .datetime_ or self .datetimetz_ or self .timedelta_ or self .nat_
1290
+ or self .period_ or self .interval_
1291
+ or self .numeric_ or self .nan_ or self .null_ or self .object_
1292
+ )
1294
1293
1295
1294
1296
1295
cdef object _try_infer_map(object dtype):
@@ -2671,62 +2670,53 @@ def maybe_convert_objects(ndarray[object] objects,
2671
2670
return result
2672
2671
return result
2673
2672
2673
+ if seen.bool_:
2674
+ if seen.is_bool:
2675
+ # is_bool property rules out everything else
2676
+ return bools.view(np.bool_)
2677
+ seen.object_ = True
2678
+
2674
2679
if not seen.object_:
2675
2680
result = None
2676
2681
if not safe:
2677
- if seen.null_ or seen.nan_:
2678
- if seen.is_float_or_complex:
2679
- if seen.complex_:
2680
- result = complexes
2681
- elif seen.float_:
2682
- result = floats
2683
- elif seen.int_:
2684
- if convert_to_nullable_integer:
2685
- from pandas.core.arrays import IntegerArray
2686
- result = IntegerArray(ints, mask)
2687
- else :
2688
- result = floats
2689
- elif seen.nan_:
2682
+ if seen.complex_:
2683
+ result = complexes
2684
+ elif seen.float_:
2685
+ result = floats
2686
+ elif seen.null_ or seen.nan_:
2687
+ if seen.int_:
2688
+ if convert_to_nullable_integer:
2689
+ from pandas.core.arrays import IntegerArray
2690
+ result = IntegerArray(ints, mask)
2691
+ else :
2690
2692
result = floats
2693
+ elif seen.nan_:
2694
+ result = floats
2691
2695
else :
2692
- if not seen.bool_:
2693
- if seen.complex_:
2694
- result = complexes
2695
- elif seen.float_:
2696
- result = floats
2697
- elif seen.int_:
2698
- if seen.uint_:
2699
- result = uints
2700
- else :
2701
- result = ints
2702
- elif seen.is_bool:
2703
- result = bools.view(np.bool_)
2696
+ if seen.int_:
2697
+ if seen.uint_:
2698
+ result = uints
2699
+ else :
2700
+ result = ints
2704
2701
2705
2702
else :
2706
2703
# don't cast int to float, etc.
2707
- if seen.null_:
2708
- if seen.is_float_or_complex:
2709
- if seen.complex_:
2710
- if not seen.int_:
2711
- result = complexes
2712
- elif seen.float_ or seen.nan_:
2713
- if not seen.int_:
2714
- result = floats
2704
+ if seen.int_:
2705
+ if seen.null_ or seen.nan_ or seen.float_ or seen.complex_:
2706
+ # we have seen something other than int, so we do not
2707
+ # convert with safe=True.
2708
+ pass
2709
+ else :
2710
+ if seen.uint_:
2711
+ result = uints
2712
+ else :
2713
+ result = ints
2714
+
2715
2715
else :
2716
- if not seen.bool_:
2717
- if seen.complex_:
2718
- if not seen.int_:
2719
- result = complexes
2720
- elif seen.float_ or seen.nan_:
2721
- if not seen.int_:
2722
- result = floats
2723
- elif seen.int_:
2724
- if seen.uint_:
2725
- result = uints
2726
- else :
2727
- result = ints
2728
- elif seen.is_bool and not seen.nan_:
2729
- result = bools.view(np.bool_)
2716
+ if seen.complex_:
2717
+ result = complexes
2718
+ elif seen.float_ or seen.nan_:
2719
+ result = floats
2730
2720
2731
2721
if result is uints or result is ints or result is floats or result is complexes:
2732
2722
# cast to the largest itemsize when all values are NumPy scalars
0 commit comments