Skip to content

Commit 757de8c

Browse files
committed
add fast path in _coerce_to_data_and_mask
1 parent e3a3a4a commit 757de8c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pandas/core/arrays/numeric.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def _coerce_to_data_and_mask(
174174
raise TypeError(f"{values.dtype} cannot be converted to {name}")
175175

176176
elif values.dtype.kind == "b" and checker(dtype):
177+
# fastpath
178+
mask = np.zeros(len(values), dtype=np.bool_)
177179
if not copy:
178180
values = np.asarray(values, dtype=default_dtype)
179181
else:
@@ -190,6 +192,10 @@ def _coerce_to_data_and_mask(
190192
if values.dtype.kind in "iu":
191193
# fastpath
192194
mask = np.zeros(len(values), dtype=np.bool_)
195+
elif values.dtype.kind == "f":
196+
# np.isnan is faster than is_numeric_na() for floats
197+
# github issue: #60066
198+
mask = np.isnan(values)
193199
else:
194200
mask = libmissing.is_numeric_na(values)
195201
else:

0 commit comments

Comments
 (0)