Skip to content

Commit 6598797

Browse files
Handle NaN in array_with_unit_to_datetime (#48705)
* Handle NaN in array_with_unit_to_datetime Missing values in arrays can either be NaT (for integer types) or NaN (for floating types). Make sure to also handle the latter. This fixes all failing tests. * Update pandas/_libs/tslib.pyx Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 1d5f05c commit 6598797

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pandas/_libs/tslib.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def array_with_unit_to_datetime(
300300
iresult = values.astype("i8", copy=False)
301301
# fill missing values by comparing to NPY_NAT
302302
mask = iresult == NPY_NAT
303+
# Trying to Convert NaN to integer results in undefined
304+
# behaviour, so handle it explicitly (see GH #48705)
305+
if values.dtype.kind == "f":
306+
mask |= values != values
303307
iresult[mask] = 0
304308
fvalues = iresult.astype("f8") * mult
305309
need_to_iterate = False

0 commit comments

Comments
 (0)