Skip to content

Suggesting specific IO backends to install when open_dataset() fails #5302

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

Closed
shoyer opened this issue May 13, 2021 · 3 comments · Fixed by #5455
Closed

Suggesting specific IO backends to install when open_dataset() fails #5302

shoyer opened this issue May 13, 2021 · 3 comments · Fixed by #5455

Comments

@shoyer
Copy link
Member

shoyer commented May 13, 2021

Currently, Xarray's internal backends don't get registered unless the necessary dependencies are installed:

if has_netcdf4:
BACKEND_ENTRYPOINTS["netcdf4"] = NetCDF4BackendEntrypoint

In order to facilitating suggesting a specific backend to install (e.g., to improve error messages from opening tutorial datasets #5291), I would suggest that Xarray always registers its own backend entrypoints. Then we make the following changes to the plugin protocol:

  • guess_can_open() should work regardless of whether the underlying backend is installed
  • installed() returns a boolean reporting whether backend is installed. The default method in the base class would return True, for backwards compatibility.
  • open_dataset() of course should error if the backend is not installed.

This will let us leverage the existing guess_can_open() functionality to suggest specific optional dependencies to install. E.g., if you supply a netCDF3 file: Xarray cannot find a matching installed backend for this file in the installed backends ["h5netcdf"]. Consider installing one of the following backends which reports a match: ["scipy", "netcdf4"]

Does this reasonable and worthwhile?

CC @aurghs @alexamici

@aurghs
Copy link
Collaborator

aurghs commented May 13, 2021

Me too, I was thinking about something like that to fix the error message.
Let me try to implement it. But I have really no time this week and the next one, sorry. I can do it after 23th if for you is ok.

@shoyer
Copy link
Member Author

shoyer commented May 13, 2021

Sounds good, I'll make a short-term fix for the tutorial data

@shoyer
Copy link
Member Author

shoyer commented May 13, 2021

Another advantage of "always registering" backends is that I think it will make for a better user-experience when installing a new dependency for IO via pip, because they won't have to restart their Python session: #5291 (comment)

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

Successfully merging a pull request may close this issue.

2 participants