@@ -139,10 +139,9 @@ def _safe_cast(cls, values: np.ndarray, dtype: np.dtype, copy: bool) -> np.ndarr
139139 raise AbstractMethodError (cls )
140140
141141
142- def _coerce_to_data_and_mask (
143- values , dtype , copy : bool , dtype_cls : type [NumericDtype ], default_dtype : np .dtype
144- ):
142+ def _coerce_to_data_and_mask (values , dtype , copy : bool , dtype_cls : type [NumericDtype ]):
145143 checker = dtype_cls ._checker
144+ default_dtype = dtype_cls ._default_np_dtype
146145
147146 mask = None
148147 inferred_type = None
@@ -163,17 +162,22 @@ def _coerce_to_data_and_mask(
163162 if copy :
164163 values = values .copy ()
165164 mask = mask .copy ()
166- return values , mask , dtype , inferred_type
165+ return values , mask
167166
168167 original = values
169168 if not copy :
170169 values = np .asarray (values )
171170 else :
172171 values = np .array (values , copy = copy )
173- inferred_type = None
174172 if values .dtype == object or is_string_dtype (values .dtype ):
175- inferred_type = lib .infer_dtype (values , skipna = True )
176- if inferred_type == "boolean" and dtype is None :
173+ if is_string_dtype (values .dtype ):
174+ inferred_type = "string"
175+ if (
176+ dtype is None
177+ and values .dtype == object
178+ and lib .is_bool_array (values , skipna = True )
179+ ):
180+ # object dtype array of bools
177181 name = dtype_cls .__name__ .strip ("_" )
178182 raise TypeError (f"{ values .dtype } cannot be converted to { name } " )
179183
@@ -252,7 +256,7 @@ def _coerce_to_data_and_mask(
252256 values = values .astype (dtype , copy = copy )
253257 else :
254258 values = dtype_cls ._safe_cast (values , dtype , copy = False )
255- return values , mask , dtype , inferred_type
259+ return values , mask
256260
257261
258262class NumericArray (BaseMaskedArray ):
@@ -296,10 +300,7 @@ def _coerce_to_array(
296300 cls , value , * , dtype : DtypeObj , copy : bool = False
297301 ) -> tuple [np .ndarray , np .ndarray ]:
298302 dtype_cls = cls ._dtype_cls
299- default_dtype = dtype_cls ._default_np_dtype
300- values , mask , _ , _ = _coerce_to_data_and_mask (
301- value , dtype , copy , dtype_cls , default_dtype
302- )
303+ values , mask = _coerce_to_data_and_mask (value , dtype , copy , dtype_cls )
303304 return values , mask
304305
305306 @classmethod
0 commit comments