-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
ENH: Throw informative error if missing optional dependency #9554
Comments
Thanks for opening your first issue here at xarray! Be sure to follow the issue template! |
Yes this sounds like a really nice contribution! |
I'm totally supporting this idea. Just to get this into the discussion: in one of the packages I maintain this was extended to allow such scheme for global imports: |
Found this while researching other options |
I think that lazy loading and optional dependency handling are separate issues, at least as far as how it is implemented in For what it's worth MNE-Python is trying out |
This ticket proposes two separate but overlapping ideas.
1. When trying to write/read Zarr files, throw an informative error if the user does not have
zarr
installedjust as Xarray does for other optional dependencies like Matplotlib.
Reproducible Code
Assuming you only have the base Xarray deps installed:
2. Create a utility function to handle optional dependency imports across the Xarray code base.
Doing
git grep "raise ImportError"
orgit grep "raise ModuleNotFoundError"
reveals that currently there is a piecemeal approach to handling optional dependencies. It would probably be helpful to have a dedicated function to handle soft dependencies across the code base, and I would be happy to add this If I am going to be adding a PR for point 1 anyways.Describe the solution you'd like
I work on an applied neuroscience package named MNE-Python, where we have a lot of optional dependencies that are only needed for specific MNE functionalities. So borrowing from MNE, I think something like this would be nice:
Then, for example, here, we can instead do:
And if we don't have
zarr
installed we'd get:ImportError: for writing zarr files, the zarr package is required. Please install it via pip or conda.
Describe alternatives you've considered
Open to any ideas 🙂
Additional context
What do folks think about this idea? Is a PR welcome?
The text was updated successfully, but these errors were encountered: