html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/1240#issuecomment-682435326,https://api.github.com/repos/pydata/xarray/issues/1240,682435326,MDEyOklzc3VlQ29tbWVudDY4MjQzNTMyNg==,500246,2020-08-28T09:48:18Z,2020-08-28T09:48:56Z,CONTRIBUTOR,"I fixed my conda environment now (something was wrong as I appeared to have two xarray installations in parallel). I still get the `KeyError` with latest xarray master and latest pandas master:
```
$ conda list | egrep -w '(pandas|xarray)'
pandas 1.2.0.dev0+167.g1f35b0621 pypi_0 pypi
xarray 0.16.1.dev65+g13caf96e pypi_0 pypi
$ python mwe83.py
Traceback (most recent call last):
File ""mwe83.py"", line 5, in
da.sel(time=da.coords[""time""][0])
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/dataarray.py"", line 1142, in sel
ds = self._to_temp_dataset().sel(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/dataset.py"", line 2096, in sel
pos_indexers, new_indexes = remap_label_indexers(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/coordinates.py"", line 395, in remap_label_indexers
pos_indexers, new_indexes = indexing.remap_label_indexers(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/indexing.py"", line 270, in remap_label_indexers
idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/indexing.py"", line 189, in convert_label_indexer
indexer = index.get_loc(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py"", line 622, in get_loc
raise KeyError(key)
KeyError: 0
$ cat mwe83.py
import xarray as xr
import numpy as np
da = xr.DataArray([0, 1], dims=(""time"",), coords={""time"": np.array([0, 1], dtype=""M8[s]"")})
da.sel(time=slice(da.coords[""time""][0], da.coords[""time""][1]))
da.sel(time=da.coords[""time""][0])
```
Oops, by ""already have"" you meant it's already been reported, I thought you meant it had already been fixed. All clear then.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,204071440
https://github.com/pydata/xarray/issues/1240#issuecomment-682419176,https://api.github.com/repos/pydata/xarray/issues/1240,682419176,MDEyOklzc3VlQ29tbWVudDY4MjQxOTE3Ng==,14808389,2020-08-28T09:10:47Z,2020-08-28T09:10:47Z,MEMBER,"What's your `pandas` version? If it's `pandas>=1.1.0`, we already have #4283. Otherwise you might want to update your repository, we're at 13caf96efb3f121e232a35aafceed80c832a9876 right now (the latest release is `0.16.0`). ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,204071440
https://github.com/pydata/xarray/issues/1240#issuecomment-682393298,https://api.github.com/repos/pydata/xarray/issues/1240,682393298,MDEyOklzc3VlQ29tbWVudDY4MjM5MzI5OA==,500246,2020-08-28T08:14:26Z,2020-08-28T08:14:26Z,CONTRIBUTOR,"This was closed and was solved for slicing, but not for element indexing:
```python
import xarray as xr
import numpy as np
da = xr.DataArray([0, 1], dims=(""time"",), coords={""time"": np.array([0, 1], dtype=""M8[s]"")})
da.sel(time=da.coords[""time""][0])
```
results in
```
Traceback (most recent call last):
File ""mwe83.py"", line 4, in
da.sel(time=da.coords[""time""][0])
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/dataarray.py"", line 1142, in sel
ds = self._to_temp_dataset().sel(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/dataset.py"", line 2096, in sel
pos_indexers, new_indexes = remap_label_indexers(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/coordinates.py"", line 395, in remap_label_indexers
pos_indexers, new_indexes = indexing.remap_label_indexers(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/indexing.py"", line 270, in remap_label_indexers
idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/core/indexing.py"", line 189, in convert_label_indexer
indexer = index.get_loc(
File ""/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py"", line 622, in get_loc
raise KeyError(key)
KeyError: 0
```
using xarray 0.15.2.dev64+g2542a63f (latest master). I think it would be desirable that it works in both cases. Should we reopen this issue or should I open a new?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,204071440
https://github.com/pydata/xarray/issues/1240#issuecomment-346158815,https://api.github.com/repos/pydata/xarray/issues/1240,346158815,MDEyOklzc3VlQ29tbWVudDM0NjE1ODgxNQ==,1217238,2017-11-21T20:58:34Z,2017-11-21T20:58:34Z,MEMBER,"Sorry for letting this one linger for so long... I added the ""bug"" tag so we don't forget about it for the next release.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,204071440
https://github.com/pydata/xarray/issues/1240#issuecomment-346157283,https://api.github.com/repos/pydata/xarray/issues/1240,346157283,MDEyOklzc3VlQ29tbWVudDM0NjE1NzI4Mw==,13190237,2017-11-21T20:52:49Z,2017-11-21T20:52:49Z,CONTRIBUTOR,"@jhamman - thanks, this should be usefull...","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,204071440
https://github.com/pydata/xarray/issues/1240#issuecomment-346059153,https://api.github.com/repos/pydata/xarray/issues/1240,346059153,MDEyOklzc3VlQ29tbWVudDM0NjA1OTE1Mw==,2443309,2017-11-21T15:20:09Z,2017-11-21T15:20:09Z,MEMBER,"@ulijh - you should be able to use the time *index*:
```Python
In [11]: arr.loc[arr.indexes['time'][2]:arr.indexes['time'][5]]
Out[11]:
array([[ 0.422991, 0.513276, 0.762432],
[ 0.111123, 0.371109, 0.697921],
[ 0.029415, 0.215116, 0.451697],
[ 0.670181, 0.855551, 0.319134]])
Coordinates:
* time (time) datetime64[ns] 2000-01-03 2000-01-04 2000-01-05 2000-01-06
* space (space)