@@ -2545,6 +2545,7 @@ def maybe_convert_objects(ndarray[object] objects,
2545
2545
bint convert_numeric = True , # NB: different default!
2546
2546
bint convert_to_nullable_dtype = False ,
2547
2547
bint convert_non_numeric = False ,
2548
+ object dtype_if_all_na = None ,
2548
2549
object dtype_if_all_nat = None ) -> "ArrayLike":
2549
2550
"""
2550
2551
Type inference function-- convert object array to proper dtype
@@ -2566,6 +2567,8 @@ def maybe_convert_objects(ndarray[object] objects,
2566
2567
encountered , whether to convert and return an Boolean/IntegerArray.
2567
2568
convert_non_numeric : bool , default False
2568
2569
Whether to convert datetime , timedelta , period , interval types.
2570
+ dtype_if_all_na : np.dtype , ExtensionDtype , or None , default None
2571
+ Dtype to cast to if we have all-NA or all-None.
2569
2572
dtype_if_all_nat : np.dtype , ExtensionDtype , or None , default None
2570
2573
Dtype to cast to if we have all-NaT.
2571
2574
@@ -2838,6 +2841,16 @@ def maybe_convert_objects(ndarray[object] objects,
2838
2841
else :
2839
2842
seen.object_ = True
2840
2843
2844
+ elif seen.null_:
2845
+ if not seen.object_ and not seen.numeric_ and not seen.bool_:
2846
+ # all NaT, None, or nan (at least one NA or None)
2847
+ dtype = dtype_if_all_na
2848
+ if dtype is not None :
2849
+ cls = dtype.construct_array_type()
2850
+ obj = cls ._from_sequence([], dtype = dtype)
2851
+ taker = - np.ones((< object > objects).shape, dtype = np.intp)
2852
+ return obj.take(taker, allow_fill = True )
2853
+
2841
2854
if not convert_numeric:
2842
2855
# Note: we count "bool" as numeric here. This is because
2843
2856
# np.array(list_of_items) will convert bools just like it will numeric
0 commit comments