home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 686324285

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
686324285 MDU6SXNzdWU2ODYzMjQyODU= 4377 Value based indexing using .sel is broken on datetime coords 1550771 closed 0     1 2020-08-26T13:32:18Z 2020-08-26T13:46:57Z 2020-08-26T13:46:57Z NONE      

What happened:

Value based indexing using .sel on a datetime coordinate is broken.

Minimal Complete Verifiable Example:

```python import numpy as np import pandas import xarray as xr

a = xr.DataArray(np.arange(27).reshape(3,3,3), dims=["x", "y", "time"], coords=dict(x=[1,2,3], y=[1,2,3], time=pd.date_range("2020-01-01", freq="1d", periods=3)))

a.sel(time=a.time.values[0]) ```

```

KeyError Traceback (most recent call last) <ipython-input-10-b52cbbe5c7df> in <module> ----> 1 a.sel(time=a.time.values[0])

~/miniconda3/envs/gv_dev/lib/python3.7/site-packages/xarray/core/dataarray.py in sel(self, indexers, method, tolerance, drop, indexers_kwargs) 1059 method=method, 1060 tolerance=tolerance, -> 1061 indexers_kwargs, 1062 ) 1063 return self._from_temp_dataset(ds)

~/miniconda3/envs/gv_dev/lib/python3.7/site-packages/xarray/core/dataset.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs) 2064 indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel") 2065 pos_indexers, new_indexes = remap_label_indexers( -> 2066 self, indexers=indexers, method=method, tolerance=tolerance 2067 ) 2068 result = self.isel(indexers=pos_indexers, drop=drop)

~/miniconda3/envs/gv_dev/lib/python3.7/site-packages/xarray/core/coordinates.py in remap_label_indexers(obj, indexers, method, tolerance, **indexers_kwargs) 395 396 pos_indexers, new_indexes = indexing.remap_label_indexers( --> 397 obj, v_indexers, method=method, tolerance=tolerance 398 ) 399 # attach indexer's coordinate to pos_indexers

~/miniconda3/envs/gv_dev/lib/python3.7/site-packages/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance) 268 coords_dtype = data_obj.coords[dim].dtype 269 label = maybe_cast_to_coords_dtype(label, coords_dtype) --> 270 idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance) 271 pos_indexers[dim] = idxr 272 if new_idx is not None:

~/miniconda3/envs/gv_dev/lib/python3.7/site-packages/xarray/core/indexing.py in convert_label_indexer(index, label, index_name, method, tolerance) 188 else: 189 indexer = index.get_loc( --> 190 label.item(), method=method, tolerance=tolerance 191 ) 192 elif label.dtype.kind == "b":

~/miniconda3/envs/gv_dev/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in get_loc(self, key, method, tolerance) 620 else: 621 # unrecognized type --> 622 raise KeyError(key) 623 624 try:

KeyError: 1577836800000000000 ```

Anything else we need to know?:

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.7.5 (default, Oct 25 2019, 10:52:18) [Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 18.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.2 xarray: 0.16.0 pandas: 1.1.1 numpy: 1.17.3 scipy: 1.4.1 netCDF4: 1.5.1.2 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: 2.3.2 cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.4 cfgrib: None iris: None bottleneck: None dask: 2.9.0 distributed: 2.9.0 matplotlib: 3.1.2 cartopy: 0.17.0 seaborn: 0.10.0 numbagg: None pint: None setuptools: 46.1.3.post20200330 pip: 19.3.1 conda: 4.8.3 pytest: 5.3.2 IPython: 7.10.2 sphinx: 2.3.1
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4377/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

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