Skip to content

Commit f4de9cd

Browse files
committed
add values.dtype.kind==f branch to array_with_unit_datetime
1 parent ca63e8d commit f4de9cd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pandas/_libs/tslib.pyx

+9-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def array_with_unit_to_datetime(
234234
m = cast_from_unit(None, unit)
235235

236236
if is_raise:
237-
238237
# try a quick conversion to i8
239238
# if we have nulls that are not type-compat
240239
# then need to iterate
@@ -247,9 +246,17 @@ def array_with_unit_to_datetime(
247246
fvalues = iresult.astype('f8') * m
248247
need_to_iterate = False
249248

249+
# GH20445
250+
if values.dtype.kind == "f":
251+
fresult = values.astype('f8', casting='same_kind', copy=False)
252+
# fill by comparing to NPY_NAT constant
253+
mask = fresult == NPY_NAT
254+
fresult[mask] = 0.0
255+
fvalues = fvalues.astype('f8') * m # FIXME: this line segfaults rn
256+
need_to_iterate = False
257+
250258
# check the bounds
251259
if not need_to_iterate:
252-
253260
if ((fvalues < Timestamp.min.value).any()
254261
or (fvalues > Timestamp.max.value).any()):
255262
raise OutOfBoundsDatetime(f"cannot convert input with unit '{unit}'")
@@ -417,7 +424,6 @@ cpdef array_to_datetime(
417424
float offset_seconds, tz_offset
418425
set out_tzoffset_vals = set()
419426
bint string_to_dts_failed
420-
421427
# specify error conditions
422428
assert is_raise or is_ignore or is_coerce
423429

0 commit comments

Comments
 (0)