Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: raise more informative error message for xr.open_dataset(list_of_paths) #6510

Open
aaronspring opened this issue Apr 25, 2022 · 4 comments

Comments

@aaronspring
Copy link
Contributor

Is your feature request related to a problem?

I sometimes use xr.open_dataset instead of xr.open_mfdataset on multiple paths. I propose to raise a more informative error message than ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'h5netcdf', 'scipy', 'cfgrib']. 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.

import xarray as xr

xr.__version__ # '2022.3.0'

ds = xr.tutorial.load_dataset("air_temperature")

ds.isel(time=slice(None,1500)).to_netcdf("file1.nc")
ds.isel(time=slice(1500,None)).to_netcdf("file2.nc")

xr.open_mfdataset(["file1.nc","file2.nc"]) # works
xr.open_mfdataset("file?.nc") # works

# I understand what I need to do here
xr.open_dataset("file?.nc") # fails FileNotFoundError: No such file or directory: b'/dir/file?.nc'

# I dont here; I also first try to check whether one of these files is corrupt
xr.open_dataset(["file1.nc","file2.nc"]) # fails ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'h5netcdf', 'scipy', 'cfgrib']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see: links

Describe the solution you'd like

directing the user towards the solution, i.e. "found path as list, please use open_mfdataset"

Describe alternatives you've considered

No response

Additional context

No response

@dcherian
Copy link
Contributor

Sounds good to me. PR welcome!

@aaronspring
Copy link
Contributor Author

To be implemented here

def guess_engine(store_spec):

@smartlixx
Copy link
Contributor

More generally, when the specified file(s) can't be found (e.g., a wrong file name is given), a more precise error message like 'file(s) specified can't be found' instead of currently 'ValueError: did not find a match in any of xarray's currently installed IO backends'.

@aaronspring aaronspring changed the title Frature request: raise more informative error message for xr.open_dataset(list_of_paths) Feature request: raise more informative error message for xr.open_dataset(list_of_paths) Apr 29, 2022
@dcherian
Copy link
Contributor

For wrong file name, we have this issue: #5329 and this PR: #5351

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants