I have an interesting case with WRF model files, and using the xWRF Python package (https://xwrf.readthedocs.io/en/latest/).
I'll use some toy code to demonstrate:
import xarray as xr
ds = xr.open_dataset('/glade/u/home/dadriaan/DOES_NOT_EXIST.nc')
The above code returns this:
FileNotFoundError: [Errno 2] No such file or directory: '/glade/u/home/dadriaan/DOES_NOT_EXIST.nc'
Now, another example (also for a file that DOES NOT EXIST):
import xarray as xr
import xwrf
ds = xr.open_dataset('/glade/u/home/wrfout_d01_2021-02-10_10:30:00').xwrf.postprocess()
The above code returns:
ValueError: did not find a match in any of xarray's currently installed IO backends ['scipy']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
https://docs.xarray.dev/en/stable/user-guide/io.html
The tricky part here, is that the file I tried to read also DOES NOT EXIST, however the error returned to me is not helpful as a user and misleads me into thinking I have environment problems or engine issues, or something to that effect, rather than a file that's missing.
I am wondering if it's worthwhile to make sure the os.PathLike
object passed to guess_engine
(https://github.com/pydata/xarray/blob/92c8b33eb464b09d6f8277265b16cae039ab57ee/xarray/backends/plugins.py#L147) exists before attempting the engine guess? If not, return the error similar to what's spit out from the file_manager.py
?
It might also make sense to move it up into api.py
in open_dataset
: https://github.com/pydata/xarray/blob/92c8b33eb464b09d6f8277265b16cae039ab57ee/xarray/backends/api.py#L550-L551
Last updated: May 16 2025 at 17:14 UTC