You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix indexing with datetime64[ns] with pandas=1.1 (#4292)
* Fix indexing with datetime64[ns] with pandas=1.1
Fixes#4283
The underlying issue is that calling `.item()` on a NumPy array with
`dtype=datetime64[ns]` returns an _integer_, rather than an `np.datetime64
scalar. This is somewhat baffling but works this way because `.item()`
returns native Python types, but `datetime.datetime` doesn't support
nanosecond precision.
`pandas.Index.get_loc` used to support these integers, but now is more strict.
Hence we get errors.
We can fix this by using `array[()]` to convert 0d arrays into NumPy scalars
instead of calling `array.item()`.
I've added a crude regression test. There may well be a better way to test this
but I haven't figured it out yet.
* lint fix
* add a test checking the datetime indexer
* use label.item() for non-datetime / timedelta labels
* unpin pandas in the docs
* ignore the future warning about deprecated arguments to pandas.Grouper
* Update xarray/core/indexing.py
Co-authored-by: keewis <[email protected]>
* Add whatsnew note
Co-authored-by: Keewis <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
Co-authored-by: keewis <[email protected]>
0 commit comments