issues: 514792972
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
514792972 | MDU6SXNzdWU1MTQ3OTI5NzI= | 3470 | warn when updating coord.values : indexes are not updated | 35295222 | closed | 0 | 7 | 2019-10-30T16:05:14Z | 2020-03-23T13:42:50Z | 2020-03-23T13:42:50Z | NONE | Hi, I've recently come across what it seems to be a bit annoying bug. After adding an offset to the time dimension using pd.add_offset(), the wrong times are selected when using .sel(). I've come across this behavior in recent versions of xarray, starting from 0.12. I've now worked around it by using ds.assign_coords(time = ...). I'm not sure however if this is a possible bug in Xarray or Pandas. Below a minimum working example. MCVE Code Sample```python import xarray as xr import pandas as pd import numpy as np temp = 15 + 8 * np.random.randn(2, 2, 3) lon = [[-99.83, -99.32], [-99.79, -99.23]] lat = [[42.25, 42.21], [42.63, 42.59]] ds = xr.Dataset({'temperature': (['x', 'y', 'time'], temp)}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': pd.date_range('2014-09-01', periods=3,freq='MS'), }) seltime = ds.time[2]
ds.time.values = pd.to_datetime(ds.time.values) + pd.DateOffset(months=2)
Expected OutputExpected output is that seltime and ds.sel(time=seltime).time are the same Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/3470/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |