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 1624560934,I_kwDOAMm_X85g1NUm,7630,.loc[] cannot find a value that .sel() can find without problem,90059220,closed,0,,,6,2023-03-15T01:26:32Z,2023-04-28T13:09:22Z,2023-04-28T13:09:22Z,NONE,,,,"### What is your issue? Hi all, Given the minimal working example bellow: ``` python import pandas as pd import xarray as xr nc = xr.DataArray([[0]], dims=[""x"", ""y""], coords=dict( lon=([""x""], [1]), lat=([""y""], [1]))) times_ = pd.date_range('2020-01-01', '2022-01-01', freq='1d') dt = times_[0] nc = nc.expand_dims(time=times_) nc.sel(time=dt) nc.loc['time' == dt] ``` The `nc.sel()` part works like a charm, but the `nc.loc[]` return `KeyError: ""not all values found in index 'time'. Try setting the 'method' keyword argument (example: method='nearest').""`. Any idea what is happening there ? Considering I want to be able to edit the values of `nc` for certain sets of `[x,y,time]`, my understanding is that I have to use `loc[]`. But it does not find the value `dt` whereas `sel()` does. How can I solve that ?","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/7630/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1391699976,I_kwDOAMm_X85S86gI,7108,.sel return errors when using floats for no apparent reason,90059220,closed,0,,,10,2022-09-30T01:45:44Z,2022-10-05T02:21:16Z,2022-10-05T02:21:15Z,NONE,,,,"### What happened? Using floats `.sel()` on different datasets from the same provider trigger an error. Despite the fact that the concerned `dims` are all in `float32` type (see log). Attempts with default `float`, `numpy.float32()` and `numpy.float64()` gave the same output. ### What did you expect to happen? Normal behavior of `.sel()`. ### Minimal Complete Verifiable Example ```Python import xarray as xr nc_ok = xr.open_dataset('H08_20220929_0000_1H_ROC010_FLDK.02401_02401.nc').load() sub = nc_ok.sel(longitude = slice(161.001, 162.001)) nc_bug = xr.open_dataset('20220925000000-JAXA-L3C_GHRSST-SSTskin-H08_AHI-v2.0_daily-v02.0-fv01.0.nc').load() sub = nc_bug.sel(lon = slice(161.001, 162.001)) ``` ### MVCE confirmation - [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray. - [ ] Complete example — the example is self-contained, including all data and the text of any traceback. - [ ] Verifiable example — the example copy & pastes into an IPython prompt or [Binder notebook](https://mybinder.org/v2/gh/pydata/xarray/main?urlpath=lab/tree/doc/examples/blank_template.ipynb), returning the result. - [ ] New issue — a search of GitHub Issues suggests this is not a duplicate. ### Relevant log output ```Python nc_ok = xr.open_dataset('H08_20220929_0000_1H_ROC010_FLDK.02401_02401.nc').load() nc_ok.longitude Out[12]: array([ 80. , 80.05 , 80.1 , ..., 199.9 , 199.95001, 200. ], dtype=float32) Coordinates: * longitude (longitude) float32 80.0 80.05 80.1 80.15 ... 199.9 200.0 200.0 Attributes: long_name: longitude units: degrees_east nc_bug = xr.open_dataset('20220925000000-JAXA-L3C_GHRSST-SSTskin-H08_AHI-v2.0_daily-v02.0-fv01.0.nc').load() nc_bug.lon Out[14]: array([ 80. , 80.02 , 80.04 , ..., -160.04001, -160.02 , -160. ], dtype=float32) Coordinates: * lon (lon) float32 80.0 80.02 80.04 80.06 ... -160.0 -160.0 -160.0 Attributes: long_name: longitude standard_name: longitude axis: X units: degrees_east valid_min: -180.0 valid_max: 180.0 grid_mapping: Equirectangular comment: geographical coordinates, WGS84 projection sub = nc_ok.sel(longitude = slice(161.001, 162.001)) sub = nc_bug.sel(lon = slice(161.001, 162.001)) Traceback (most recent call last): File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:3800 in get_loc return self._engine.get_loc(casted_key) File pandas\_libs\index.pyx:138 in pandas._libs.index.IndexEngine.get_loc File pandas\_libs\index.pyx:165 in pandas._libs.index.IndexEngine.get_loc File pandas\_libs\hashtable_class_helper.pxi:1577 in pandas._libs.hashtable.Float64HashTable.get_item File pandas\_libs\hashtable_class_helper.pxi:1587 in pandas._libs.hashtable.Float64HashTable.get_item KeyError: 161.001 The above exception was the direct cause of the following exception: Traceback (most recent call last): Cell In [16], line 1 sub = nc_bug.sel(lon = slice(161.001, 162.001)) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\dataset.py:2533 in sel query_results = map_index_queries( File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\indexing.py:183 in map_index_queries results.append(index.sel(labels, **options)) # type: ignore[call-arg] File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\indexes.py:377 in sel indexer = _query_slice(self.index, label, coord_name, method, tolerance) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\indexes.py:150 in _query_slice indexer = index.slice_indexer( File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:6597 in slice_indexer start_slice, end_slice = self.slice_locs(start, end, step=step) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:6805 in slice_locs start_slice = self.get_slice_bound(start, ""left"") File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:6724 in get_slice_bound raise err File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:6718 in get_slice_bound slc = self.get_loc(label) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:3802 in get_loc raise KeyError(key) from err KeyError: 161.001 sub = nc_bug.sel(lon = slice(np.float64(161.001), 162.001)) Traceback (most recent call last): File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\pandas\core\indexes\base.py:3800 in get_loc return self._engine.get_loc(casted_key) File pandas\_libs\index.pyx:138 in pandas._libs.index.IndexEngine.get_loc File pandas\_libs\index.pyx:165 in pandas._libs.index.IndexEngine.get_loc File pandas\_libs\hashtable_class_helper.pxi:1577 in pandas._libs.hashtable.Float64HashTable.get_item File pandas\_libs\hashtable_class_helper.pxi:1587 in pandas._libs.hashtable.Float64HashTable.get_item KeyError: 161.001 ``` ### Anything else we need to know? The data are provided by JAXA P-Tree. ### Environment
INSTALLED VERSIONS ------------------ commit: None python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 140 Stepping 1, GenuineIntel byteorder: little LC_ALL: None LANG: en LOCALE: ('English_New Zealand', '1252') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 2022.6.0 pandas: 1.5.0 numpy: 1.23.3 scipy: 1.9.1 netCDF4: 1.6.0 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2022.9.1 distributed: None matplotlib: 3.5.2 cartopy: 0.20.2 seaborn: None numbagg: None fsspec: 2022.8.2 cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 65.3.0 pip: 22.2.2 conda: None pytest: None IPython: 8.5.0 sphinx: 5.2.1
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/7108/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1296475783,I_kwDOAMm_X85NRqaH,6759,DataArray.rolling.reduce() does not apply correctly numpy.nanpercentile,90059220,closed,0,,,2,2022-07-06T21:10:59Z,2022-07-07T02:05:47Z,2022-07-07T02:05:47Z,NONE,,,,"### What is your issue? I stumbled upon the issue of not having a simple `DataArray.rolling.quantile()` or `Dataset.rolling.quantile()`, so I tried using the `rolling.reduce()` alternative, which seems to alter the normal functioning of functions like `numpy.nanpercentile`. Namely, `nanpercentile` act like `percentile` i.e create huge missing chunks the size of `rolling` as soon as `nan` are found within the window. Is there a fix to that ? Here is the code I used to test it out: ``` python import xarray as xr, numpy as np m,n = 30,56 tab = np.random.uniform(0, 100, size=(m,n)) ds = xr.DataArray(tab) ds.plot.imshow(center=False) nb_nan = 8 tab.ravel()[np.random.choice(tab.size, nb_nan, replace=False)] = np.nan ds_nan = xr.DataArray(tab) ds_nan.plot.imshow(center=False) w = 4 roll = ds_nan.rolling({name: w for name in ['dim_0', 'dim_1']}, center = True) roll_perc = roll.reduce(np.percentile, q=90) roll_perc.plot.imshow(center=False) roll_perc_nan = roll.reduce(np.nanpercentile, q=90) roll_perc_nan.plot.imshow(center=False)","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6759/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1268821199,I_kwDOAMm_X85LoKzP,6691,Rolling.argmin() and Rolling.argmax() over multiple dimensions does not work,90059220,open,0,,,2,2022-06-13T02:42:14Z,2022-06-17T02:54:27Z,,NONE,,,,"### What is your issue? I am working with `xarray.core.rolling.DataArrayRolling` objects and for some obscure reason, they raise the following error when the `.argmin()` and `.argmax()` methods are used: ``` window_size = {name: n for name in ['lat', 'lon']} window = data_nc.rolling(window_size, center=True) peak_min = window.argmin() peak_max = window.argmax() Traceback (most recent call last): Input In [48] in File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\rolling.py:122 in method return self._numpy_or_bottleneck_reduce( File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\rolling.py:541 in _numpy_or_bottleneck_reduce return self.reduce(array_agg_func, keep_attrs=keep_attrs, **kwargs) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\rolling.py:428 in reduce result = windows.reduce( File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\dataarray.py:2696 in reduce var = self.variable.reduce(func, dim, axis, keep_attrs, keepdims, **kwargs) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\variable.py:1804 in reduce data = func(self.data, axis=axis, **kwargs) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\xarray\core\duck_array_ops.py:335 in f return func(values, axis=axis, **kwargs) File <__array_function__ internals>:180 in argmax File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\numpy\core\fromnumeric.py:1216 in argmax return _wrapfunc(a, 'argmax', axis=axis, out=out, **kwds) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\numpy\core\fromnumeric.py:66 in _wrapfunc return _wrapit(obj, method, *args, **kwds) File ~\Installed_Programs\Anaconda3\envs\phd\lib\site-packages\numpy\core\fromnumeric.py:43 in _wrapit result = getattr(asarray(obj), method)(*args, **kwds) TypeError: 'tuple' object cannot be interpreted as an integer `````` As far as I understand, these methods are included based on the `xarray` documentation, so it should work as `.min()`, `.max()` or `.mean()` are working fine: [https://docs.xarray.dev/en/stable/generated/xarray.core.rolling.DataArrayRolling.argmax.html](url) Any insight on what I am doing wrong ?","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6691/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue