We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a54d5b3 commit 3d428f7Copy full SHA for 3d428f7
xarray/coding/times.py
@@ -669,8 +669,10 @@ def encode_cf_datetime(
669
time_deltas = dates_as_index - ref_date
670
671
# Use floor division if time_delta evenly divides all differences
672
- # to preserve integer dtype if possible (GH 4045).
673
- if np.all(time_deltas % time_delta == np.timedelta64(0, "ns")):
+ # to preserve integer dtype if possible (GH 4045)
+ # NaT prevents us from using datetime64 directly, but we can safely coerce
674
+ # to int64 in presence of NaT, so we just dropna before check.
675
+ if np.all(time_deltas.dropna() % time_delta == np.timedelta64(0, "ns")):
676
num = time_deltas // time_delta
677
else:
678
num = time_deltas / time_delta
0 commit comments