How to search for the nearest non nan value in 2d xarray dataset I have a 2d xarray dataset and I am having several nan values in the dataset. These nan values need to be filled with the nearest non-nan values in the 2d array. How do I do this? 

I am trying to make my data consistent with the grid_spec file that the earth system model reads. And there are inconsistencies on what the land points are in the forcing data and grid_spec file leading to the blowing up of model.
If I were you, I would exclude the NaN values and then perform gridding on the resulting irregularly spaced data.

There are already the tools to perform this in Python and using the library SciPy

https://scipy-cookbook.readthedocs.io/items/Matplotlib_Gridding_irregularly_spaced_data.html

But please document exactly what step you are doing and why. Excluding data is always ... interpreting the data.