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/4995#issuecomment-1110101560,https://api.github.com/repos/pydata/xarray/issues/4995,1110101560,IC_kwDOAMm_X85CKs44,8699967,2022-04-26T18:09:18Z,2022-04-26T18:12:14Z,CONTRIBUTOR,"Example using `nearest` & `tolerance` with `reindex` & `sel` when dims don't match based on the example in `sel`:
```python
import numpy
import xarray
da = xarray.DataArray(
numpy.arange(25).reshape(5, 5),
coords={""x"": numpy.arange(5), ""y"": numpy.arange(5)},
dims=(""x"", ""y""),
)
tgt_x = numpy.linspace(0, 4, num=5) + 0.5
tgt_y = numpy.linspace(0, 4, num=5) + 0.5
da = da.reindex(
x=tgt_x, y=tgt_y, method=""nearest"", tolerance=0.2, fill_value=numpy.nan
).sel(
x=xarray.DataArray(tgt_x, dims=""points""),
y=xarray.DataArray(tgt_y, dims=""points""),
)
```
Output:
```
array([nan, nan, nan, nan, nan])
Coordinates:
x (points) float64 0.5 1.5 2.5 3.5 4.5
y (points) float64 0.5 1.5 2.5 3.5 4.5
Dimensions without coordinates: points
```
Side note: I don't think it makes sense to add `fill_value` to `sel` as it would require adding new coordinates that didn't exist previously. Calling `reindex` first makes that more clear in my opinion.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,822320976
https://github.com/pydata/xarray/issues/4995#issuecomment-799047819,https://api.github.com/repos/pydata/xarray/issues/4995,799047819,MDEyOklzc3VlQ29tbWVudDc5OTA0NzgxOQ==,43613877,2021-03-15T02:28:51Z,2021-03-15T02:28:51Z,CONTRIBUTOR,"Thanks @dcherian, this is doing the job. I'll close this issue as there seems to be no need to implement this into the `sel` method.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,822320976
https://github.com/pydata/xarray/issues/4995#issuecomment-791019238,https://api.github.com/repos/pydata/xarray/issues/4995,791019238,MDEyOklzc3VlQ29tbWVudDc5MTAxOTIzOA==,43613877,2021-03-04T23:10:11Z,2021-03-04T23:10:11Z,CONTRIBUTOR,"Introducing a `fill_value` seems like a good idea, such that the size of the output does not change compared to the intended selection.
Choosing the original/requested coordinate as a label for the missing datapoint seems to be a valid choice because this position has been checked for valid data nearby without success.
I would suggest, that the `fill_value` should then be automatically determined from the `_FillValue`, the datatype and only at last requires the `fill_value` to be set.
However, the shortcoming that I see in using a `fill_value` is that the indexing has to modify the data ( insert e.g. `-999`) and also 'invent' a new coordinate point ( here `40`). This gets reasonably complex, when applying to a dataset with DataArrays of different types, e.g.
```python
import numpy as np
import xarray as xr
ds = xr.Dataset()
ds['data1'] = xr.DataArray(np.array([1,2,3,4,5], dtype=int), dims=[""lat""], coords={'lat':[10,20,30,50,60]})
ds['data2'] = xr.DataArray(np.array([1,2,3,4,5], dtype=float), dims=[""lat""], coords={'lat':[10,20,30,50,60]})
```
One `fill_value` might not fit to all data arrays being it because of the datatype or the actual data. E.g. `-999` might be a good `fill_value` for one DataArray but a valid datapoint in another one.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,822320976