Skip to content

Commit 77fb53a

Browse files
committed
add values.dtype.kind==f branch to array_with_unit_datetime
1 parent 3e10b7c commit 77fb53a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pandas/_libs/tslib.pyx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def array_with_unit_to_datetime(
227227
m = cast_from_unit(None, unit)
228228

229229
if is_raise:
230-
231230
# try a quick conversion to i8
232231
# if we have nulls that are not type-compat
233232
# then need to iterate
@@ -240,9 +239,17 @@ def array_with_unit_to_datetime(
240239
fvalues = iresult.astype('f8') * m
241240
need_to_iterate = False
242241

242+
# GH20445
243+
if values.dtype.kind == "f":
244+
fresult = values.astype('f8', casting='same_kind', copy=False)
245+
# fill by comparing to NPY_NAT constant
246+
mask = fresult == NPY_NAT
247+
fresult[mask] = 0.0
248+
fvalues = fvalues.astype('f8') * m # FIXME: this line segfaults rn
249+
need_to_iterate = False
250+
243251
# check the bounds
244252
if not need_to_iterate:
245-
246253
if ((fvalues < Timestamp.min.value).any()
247254
or (fvalues > Timestamp.max.value).any()):
248255
raise OutOfBoundsDatetime(f"cannot convert input with unit '{unit}'")
@@ -410,7 +417,6 @@ cpdef array_to_datetime(
410417
float offset_seconds, tz_offset
411418
set out_tzoffset_vals = set()
412419
bint string_to_dts_failed
413-
414420
# specify error conditions
415421
assert is_raise or is_ignore or is_coerce
416422

0 commit comments

Comments
 (0)