Skip to content

Commit 825591a

Browse files
committed
Revert "Move all-NA handling logic to maybe_convert_objects"
This reverts commit d5c6cfb.
1 parent 8dd5ac2 commit 825591a

File tree

3 files changed

+3
-19
lines changed

3 files changed

+3
-19
lines changed

pandas/_libs/lib.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def maybe_convert_objects(
9494
convert_numeric: bool = ...,
9595
convert_non_numeric: Literal[False] = ...,
9696
convert_to_nullable_dtype: Literal[False] = ...,
97-
dtype_if_all_na: DtypeObj | None = ...,
9897
dtype_if_all_nat: DtypeObj | None = ...,
9998
) -> npt.NDArray[np.object_ | np.number]: ...
10099
@overload
@@ -106,7 +105,6 @@ def maybe_convert_objects(
106105
convert_numeric: bool = ...,
107106
convert_non_numeric: bool = ...,
108107
convert_to_nullable_dtype: Literal[True] = ...,
109-
dtype_if_all_na: DtypeObj | None = ...,
110108
dtype_if_all_nat: DtypeObj | None = ...,
111109
) -> ArrayLike: ...
112110
@overload
@@ -118,7 +116,6 @@ def maybe_convert_objects(
118116
convert_numeric: bool = ...,
119117
convert_non_numeric: bool = ...,
120118
convert_to_nullable_dtype: bool = ...,
121-
dtype_if_all_na: DtypeObj | None = ...,
122119
dtype_if_all_nat: DtypeObj | None = ...,
123120
) -> ArrayLike: ...
124121
@overload

pandas/_libs/lib.pyx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,6 @@ def maybe_convert_objects(ndarray[object] objects,
25452545
bint convert_numeric=True, # NB: different default!
25462546
bint convert_to_nullable_dtype=False,
25472547
bint convert_non_numeric=False,
2548-
object dtype_if_all_na=None,
25492548
object dtype_if_all_nat=None) -> "ArrayLike":
25502549
"""
25512550
Type inference function-- convert object array to proper dtype
@@ -2567,8 +2566,6 @@ def maybe_convert_objects(ndarray[object] objects,
25672566
encountered, whether to convert and return an Boolean/IntegerArray.
25682567
convert_non_numeric : bool, default False
25692568
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.
25722569
dtype_if_all_nat : np.dtype, ExtensionDtype, or None, default None
25732570
Dtype to cast to if we have all-NaT.
25742571

@@ -2841,16 +2838,6 @@ def maybe_convert_objects(ndarray[object] objects,
28412838
else:
28422839
seen.object_ = True
28432840

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-
28542841
if not convert_numeric:
28552842
# Note: we count "bool" as numeric here. This is because
28562843
# np.array(list_of_items) will convert bools just like it will numeric

pandas/core/arrays/masked.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self:
149149
return cls(values, mask)
150150

151151
def _cast_pointwise_result(self, values) -> ArrayLike:
152+
if isna(values).all():
153+
return type(self)._from_sequence(values, dtype=self.dtype)
152154
values = np.asarray(values, dtype=object)
153-
result = lib.maybe_convert_objects(
154-
values, convert_to_nullable_dtype=True, dtype_if_all_na=self.dtype
155-
)
155+
result = lib.maybe_convert_objects(values, convert_to_nullable_dtype=True)
156156
lkind = self.dtype.kind
157157
rkind = result.dtype.kind
158158
if (lkind in "iu" and rkind in "iu") or (lkind == rkind == "f"):

0 commit comments

Comments
 (0)