@@ -1309,10 +1309,14 @@ cdef class Seen:
1309
1309
@property
1310
1310
def is_bool (self ):
1311
1311
# i.e. not (anything but bool)
1312
- return not (
1313
- self .datetime_ or self .datetimetz_ or self .timedelta_ or self .nat_
1314
- or self .period_ or self .interval_
1315
- or self .numeric_ or self .nan_ or self .null_ or self .object_
1312
+ return self .is_bool_or_na and not (self .nan_ or self .null_)
1313
+
1314
+ @property
1315
+ def is_bool_or_na (self ):
1316
+ # i.e. not (anything but bool or missing values)
1317
+ return self .bool_ and not (
1318
+ self .datetime_ or self .datetimetz_ or self .nat_ or self .timedelta_
1319
+ or self .period_ or self .interval_ or self .numeric_ or self .object_
1316
1320
)
1317
1321
1318
1322
@@ -2335,7 +2339,7 @@ def maybe_convert_objects(ndarray[object] objects,
2335
2339
bint convert_timedelta = False ,
2336
2340
bint convert_period = False ,
2337
2341
bint convert_interval = False ,
2338
- bint convert_to_nullable_integer = False ,
2342
+ bint convert_to_nullable_dtype = False ,
2339
2343
object dtype_if_all_nat = None ) -> "ArrayLike":
2340
2344
"""
2341
2345
Type inference function-- convert object array to proper dtype
@@ -2362,9 +2366,9 @@ def maybe_convert_objects(ndarray[object] objects,
2362
2366
convert_interval : bool , default False
2363
2367
If an array-like object contains only Interval objects (with matching
2364
2368
dtypes and closedness ) or NaN , whether to convert to IntervalArray.
2365
- convert_to_nullable_integer : bool , default False
2366
- If an array-like object contains only integer values (and NaN ) is
2367
- encountered , whether to convert and return an IntegerArray.
2369
+ convert_to_nullable_dtype : bool , default False
2370
+ If an array-like object contains only integer or boolean values (and NaN ) is
2371
+ encountered , whether to convert and return an Boolean/ IntegerArray.
2368
2372
dtype_if_all_nat : np.dtype , ExtensionDtype , or None , default None
2369
2373
Dtype to cast to if we have all-NaT.
2370
2374
@@ -2446,7 +2450,7 @@ def maybe_convert_objects(ndarray[object] objects,
2446
2450
seen.int_ = True
2447
2451
floats[i] = < float64_t> val
2448
2452
complexes[i] = < double complex > val
2449
- if not seen.null_ or convert_to_nullable_integer :
2453
+ if not seen.null_ or convert_to_nullable_dtype :
2450
2454
seen.saw_int(val)
2451
2455
2452
2456
if ((seen.uint_ and seen.sint_) or
@@ -2606,6 +2610,9 @@ def maybe_convert_objects(ndarray[object] objects,
2606
2610
if seen.is_bool:
2607
2611
# is_bool property rules out everything else
2608
2612
return bools.view(np.bool_)
2613
+ elif convert_to_nullable_dtype and seen.is_bool_or_na:
2614
+ from pandas.core.arrays import BooleanArray
2615
+ return BooleanArray(bools.view(np.bool_), mask)
2609
2616
seen.object_ = True
2610
2617
2611
2618
if not seen.object_:
@@ -2617,7 +2624,7 @@ def maybe_convert_objects(ndarray[object] objects,
2617
2624
elif seen.float_:
2618
2625
result = floats
2619
2626
elif seen.int_ or seen.uint_:
2620
- if convert_to_nullable_integer :
2627
+ if convert_to_nullable_dtype :
2621
2628
from pandas.core.arrays import IntegerArray
2622
2629
if seen.uint_:
2623
2630
result = IntegerArray(uints, mask)
0 commit comments