home / github / issues

Menu
  • Search all tables
  • GraphQL API

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) python print(ds.sel(time=seltime).time) python <xarray.DataArray 'time' ()> array('2015-01-01T00:00:00.000000000', dtype='datetime64[ns]') Coordinates: time datetime64[ns] 2015-01-01 python print(seltime) python <xarray.DataArray 'time' ()> array('2014-11-01T00:00:00.000000000', dtype='datetime64[ns]') Coordinates: time datetime64[ns] 2014-11-01 ```

Expected Output

Expected output is that seltime and ds.sel(time=seltime).time are the same

Output of xr.show_versions()

# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.7.3 (default, Apr 3 2019, 19:16:38) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] python-bits: 64 OS: Linux OS-release: 4.15.0-58-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.0 libnetcdf: 4.6.0 xarray: 0.14.0 pandas: 0.25.2 numpy: 1.17.3 scipy: 1.3.1 netCDF4: 1.4.0 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: 1.1.0 PseudoNetCDF: None rasterio: 1.0.26 cfgrib: None iris: None bottleneck: 1.2.1 dask: 2.3.0 distributed: None matplotlib: 3.1.1 cartopy: 0.17.0 seaborn: 0.9.0 numbagg: None setuptools: 41.2.0 pip: 9.0.1 conda: None pytest: None IPython: 7.7.0 sphinx: None
{
    "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

Links from other tables

  • 1 row from issues_id in issues_labels
  • 7 rows from issue in issue_comments
Powered by Datasette · Queries took 0.817ms · About: xarray-datasette