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 993563624,MDU6SXNzdWU5OTM1NjM2MjQ=,5786,Unexpected behavior when using slice in a sel() statement,89942016,closed,0,,,13,2021-09-10T20:13:26Z,2021-09-17T18:13:04Z,2021-09-15T19:56:41Z,NONE,,,,"While working with one of our datasets we discovered some unexpected behavior while using `slice`. When selecting data points across a dataset using `slice`, we found the data returned to be inconsistent depending on what your `slice` parameters were. **What you expected to happen**: In this code snippet below, we noticed what appears to be some floating point math impacting the input values. The exercise involved slicing across the latitude of a MUR-SST data set to compare values, while keeping longitude constant. In `ex_1`, the code behaves as expected - the values returned are between `[10.47, 10.52)`. In `ex_2` the code does not behave as expected - instead of including the values `[10.45, 10.52)` we instead get the values `[10.46, 10.52)` (or `(10.45, 10.52)`). In `ex_3`, the code behaves as we would expect it in `ex_2`, which leads us to believe it involves some floating point math behavior. **Minimal Complete Verifiable Example**: ```python import xarray as xr longitude = -68.0 data = xr.open_dataset('https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/JPL/MUR/' 'v4.1/2018/030/20180130090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc') ex_1 = data['analysed_sst'].sel(lat=slice(10.47, 10.52), lon=longitude).values[0] ex_2 = data['analysed_sst'].sel(lat=slice(10.45, 10.52), lon=longitude).values[0] ex_3 = data['analysed_sst'].sel(lat=slice(10.449, 10.52), lon=longitude).values[0] print(ex_1) print(ex_2) print(ex_3) ``` **Anything else we need to know?**: From the perspective of a SWE, we were able to figure out a workaround for this relatively quickly. Our biggest concern is, users who aren't necessarily experienced programmers getting tripped up by this because it's not the expected outcome. We don't really know if this is coming from within xarray or somewhere else, so we'd greatly appreciate someone more experienced in this area taking a look. **Environment**: MacOS 10.15.7 Python version 3.9.5
Output of xr.show_versions() ``` INSTALLED VERSIONS ------------------ commit: None python: 3.9.5 (default, May 26 2021, 16:52:23) [Clang 12.0.0 (clang-1200.0.32.29)] python-bits: 64 OS: Darwin OS-release: 19.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.12.0 libnetcdf: 4.7.4 xarray: 0.18.0 pandas: 1.2.4 numpy: 1.20.2 scipy: None netCDF4: 1.5.6 pydap: None h5netcdf: None h5py: None Nio: None zarr: 2.8.3 cftime: 1.4.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.4.3 cartopy: None seaborn: None numbagg: None pint: None setuptools: 56.0.0 pip: 21.1.1 conda: None pytest: None IPython: 7.25.0 sphinx: None ```
Thanks so much! ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5786/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue