home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 298839307

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
298839307 MDU6SXNzdWUyOTg4MzkzMDc= 1932 Not able to slice dataset using its own coordinate value 7799184 closed 0     2 2018-02-21T04:35:01Z 2018-02-27T01:13:45Z 2018-02-27T01:13:45Z CONTRIBUTOR      

Code Sample, a copy-pastable example if possible

python In [1]: import xarray as xr In [2]: ds = xr.open_dataset('test.nc') In [3]: ds.sel(time=ds.time[0]) #works In [4]: ds.sel(time=ds.time[1], method='nearest') #works In [5]: ds.sel(time=ds.time[1]) #does not work

```python In [6]: ds.time[0] Out[6]: <xarray.DataArray 'time' ()> array('2018-02-12T06:00:00.000000000', dtype='datetime64[ns]') Coordinates: time datetime64[ns] 2018-02-12T06:00:00 site float64 ... Attributes: standard_name: time

In [7]: ds.time[1] Out[7]: <xarray.DataArray 'time' ()> array('2018-02-12T06:59:59.999986000', dtype='datetime64[ns]') Coordinates: time datetime64[ns] 2018-02-12T06:59:59.999986 site float64 ... Attributes: standard_name: time ```

Problem description

xarray sometimes fails to slice using its own coordinate values. It looks like it may have to do with precision. Traceback below, test file attached.

```python In [7]: ds.sel(time=ds.time[1])


KeyError Traceback (most recent call last) <ipython-input-7-371d2f896b4a> in <module>() ----> 1 ds.sel(time=ds.time[1])

/usr/lib/python2.7/site-packages/xarray/core/dataset.pyc in sel(self, method, tolerance, drop, **indexers) 1444 1445 pos_indexers, new_indexes = indexing.remap_label_indexers( -> 1446 self, v_indexers, method=method, tolerance=tolerance 1447 ) 1448 # attach indexer's coordinate to pos_indexers

/usr/lib/python2.7/site-packages/xarray/core/indexing.pyc in remap_label_indexers(data_obj, indexers, method, tolerance) 234 else: 235 idxr, new_idx = convert_label_indexer(index, label, --> 236 dim, method, tolerance) 237 pos_indexers[dim] = idxr 238 if new_idx is not None:

/usr/lib/python2.7/site-packages/xarray/core/indexing.pyc in convert_label_indexer(index, label, index_name, method, tolerance) 163 indexer, new_index = index.get_loc_level(label.item(), level=0) 164 else: --> 165 indexer = get_loc(index, label.item(), method, tolerance) 166 elif label.dtype.kind == 'b': 167 indexer = label

/usr/lib/python2.7/site-packages/xarray/core/indexing.pyc in get_loc(index, label, method, tolerance) 93 def get_loc(index, label, method=None, tolerance=None): 94 kwargs = _index_method_kwargs(method, tolerance) ---> 95 return index.get_loc(label, **kwargs) 96 97

/usr/lib/python2.7/site-packages/pandas/core/indexes/datetimes.pyc in get_loc(self, key, method, tolerance) 1444 return Index.get_loc(self, stamp, method, tolerance) 1445 except KeyError: -> 1446 raise KeyError(key) 1447 except ValueError as e: 1448 # list-like tolerance size must match target index size

KeyError: 1518418799999986000L ```

Expected Output

Output of xr.show_versions()

```python In [9]: xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 2.7.14.final.0 python-bits: 64 OS: Linux OS-release: 4.14.15-1-ARCH machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_NZ.UTF-8 LOCALE: en_NZ.UTF-8 xarray: 0.10.0 pandas: 0.22.0 numpy: 1.14.0 scipy: 0.17.1 netCDF4: 1.2.9 h5netcdf: None Nio: None bottleneck: None cyordereddict: None dask: 0.11.1 matplotlib: 2.1.0 cartopy: 0.14.2 seaborn: None setuptools: 34.2.0 pip: 9.0.1 conda: None pytest: 3.3.1 IPython: 5.2.2 sphinx: None ``` [test.zip](https://github.com/pydata/xarray/files/1742872/test.zip)
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1932/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
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.533ms · About: xarray-datasette