Skip to content

Commit 8aa6983

Browse files
andreas-schwabkmuehlbauer
authored andcommitted
Don't cast NaN to integer
Do not try to convert NaN to integer type, as the operation is undefined and results in random values. This fixes all testsuite failures.
1 parent 4b3d74a commit 8aa6983

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

xarray/coding/times.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,11 @@ def _decode_datetime_with_pandas(
249249
if flat_num_dates.dtype.kind in "iu":
250250
flat_num_dates = flat_num_dates.astype(np.int64)
251251

252-
# Cast input ordinals to integers of nanoseconds because pd.to_timedelta
253-
# works much faster when dealing with integers (GH 1399).
254-
flat_num_dates_ns_int = (flat_num_dates * _NS_PER_TIME_DELTA[delta]).astype(
255-
np.int64
256-
)
257-
258252
# Use pd.to_timedelta to safely cast integer values to timedeltas,
259253
# and add those to a Timestamp to safely produce a DatetimeIndex. This
260254
# ensures that we do not encounter integer overflow at any point in the
261255
# process without raising OutOfBoundsDatetime.
262-
return (pd.to_timedelta(flat_num_dates_ns_int, "ns") + ref_date).values
256+
return (pd.to_timedelta(flat_num_dates, delta) + ref_date).values
263257

264258

265259
def decode_cf_datetime(

0 commit comments

Comments
 (0)