Skip to content

Commit

Permalink
fix scalar handling for timedelta based indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Jan 7, 2025
1 parent b32b02c commit a2c46b1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,10 @@ def _convert_scalar(self, item):
# (for now)
item = np.datetime64("NaT", "ns")
elif isinstance(item, timedelta):
item = np.timedelta64(getattr(item, "value", item), "ns")
# from xarray 2025.01.1 xarray allows non-nanosecond resolution
# so we just convert to_numpy if possible
if hasattr(item, "to_numpy"):
item = item.to_numpy()
elif isinstance(item, pd.Timestamp):
# Work around for GH: pydata/xarray#1932 and numpy/numpy#10668
# numpy fails to convert pd.Timestamp to np.datetime64[ns]
Expand Down

0 comments on commit a2c46b1

Please sign in to comment.