Skip to content

Commit

Permalink
introduce pd.Timestamp instance check
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Jan 9, 2025
1 parent e619a4c commit 700e78d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,11 +1753,10 @@ def _convert_scalar(self, item):
# pd.Timestamp rather np.than datetime64 but this is easier
# (for now)
item = np.datetime64("NaT", "ns")
elif isinstance(item, pd.Timedelta):
item = item.to_numpy()
elif isinstance(item, timedelta):
# 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()
item = np.timedelta64(item)
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 700e78d

Please sign in to comment.