@@ -159,7 +159,10 @@ def _coerce_to_data_and_mask(
159159 return values , mask , dtype , inferred_type
160160
161161 original = values
162- values = np .array (values , copy = copy )
162+ if not copy :
163+ values = np .asarray (values )
164+ else :
165+ values = np .array (values , copy = copy )
163166 inferred_type = None
164167 if values .dtype == object or is_string_dtype (values .dtype ):
165168 inferred_type = lib .infer_dtype (values , skipna = True )
@@ -168,7 +171,10 @@ def _coerce_to_data_and_mask(
168171 raise TypeError (f"{ values .dtype } cannot be converted to { name } " )
169172
170173 elif values .dtype .kind == "b" and checker (dtype ):
171- values = np .array (values , dtype = default_dtype , copy = copy )
174+ if not copy :
175+ values = np .asarray (values , dtype = default_dtype )
176+ else :
177+ values = np .array (values , dtype = default_dtype , copy = copy )
172178
173179 elif values .dtype .kind not in "iuf" :
174180 name = dtype_cls .__name__ .strip ("_" )
@@ -207,9 +213,9 @@ def _coerce_to_data_and_mask(
207213 inferred_type not in ["floating" , "mixed-integer-float" ]
208214 and not mask .any ()
209215 ):
210- values = np .array (original , dtype = dtype , copy = False )
216+ values = np .asarray (original , dtype = dtype )
211217 else :
212- values = np .array (original , dtype = "object" , copy = False )
218+ values = np .asarray (original , dtype = "object" )
213219
214220 # we copy as need to coerce here
215221 if mask .any ():
0 commit comments