Closed
Description
What happened:
In [1]: import xarray as xr
In [2]: xr.__version__
Out[2]: '0.18.2'
In [3]: xr.open_dataset('/not-a-real-file')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-4cc5243e5a90> in <module>
----> 1 xr.open_dataset('/not-a-real-file')
~/miniconda3/envs/ana38/lib/python3.8/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, backend_kwargs, *args, **kwargs)
478
479 if engine is None:
--> 480 engine = plugins.guess_engine(filename_or_obj)
481
482 backend = plugins.get_backend(engine)
~/miniconda3/envs/ana38/lib/python3.8/site-packages/xarray/backends/plugins.py in guess_engine(store_spec)
109 installed = [k for k in engines if k != "store"]
110 if installed:
--> 111 raise ValueError(
112 "did not find a match in any of xarray's currently installed IO "
113 f"backends {installed}. Consider explicitly selecting one of the "
ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'scipy']. Consider explicitly selecting one of the installed backends via the ``engine`` parameter to xarray.open_dataset(), or installing additional IO dependencies:
http://xarray.pydata.org/en/stable/getting-started-guide/installing.html
http://xarray.pydata.org/en/stable/user-guide/io.html
What you expected to happen:
Should produce a "FileNotFound" error first.
Engine hunting on a non-existent file is pointless, and the error message is pretty wordy, so my skim-reading originally misinterpreted it to think that for some reason my netcdf4 library wasn't installed, which lead me on to a 4-hour environment rebuild, with a sudden realisation that I'm an idiot at the end of it...
Possible solution:
assert(os.path.isfile(path))
before anything else.