@@ -160,7 +160,10 @@ def _coerce_to_data_and_mask(
160160 return values , mask , dtype , inferred_type
161161
162162 original = values
163- values = np .array (values , copy = copy )
163+ if not copy :
164+ values = np .asarray (values )
165+ else :
166+ values = np .array (values , copy = copy )
164167 inferred_type = None
165168 if values .dtype == object or is_string_dtype (values .dtype ):
166169 inferred_type = lib .infer_dtype (values , skipna = True )
@@ -169,7 +172,10 @@ def _coerce_to_data_and_mask(
169172 raise TypeError (f"{ values .dtype } cannot be converted to { name } " )
170173
171174 elif values .dtype .kind == "b" and checker (dtype ):
172- values = np .array (values , dtype = default_dtype , copy = copy )
175+ if not copy :
176+ values = np .asarray (values , dtype = default_dtype )
177+ else :
178+ values = np .array (values , dtype = default_dtype , copy = copy )
173179
174180 elif values .dtype .kind not in "iuf" :
175181 name = dtype_cls .__name__ .strip ("_" )
@@ -208,9 +214,9 @@ def _coerce_to_data_and_mask(
208214 inferred_type not in ["floating" , "mixed-integer-float" ]
209215 and not mask .any ()
210216 ):
211- values = np .array (original , dtype = dtype , copy = False )
217+ values = np .asarray (original , dtype = dtype )
212218 else :
213- values = np .array (original , dtype = "object" , copy = False )
219+ values = np .asarray (original , dtype = "object" )
214220
215221 # we copy as need to coerce here
216222 if mask .any ():
0 commit comments