raise ImportError instead of ValueError when dask-expr cannot be imported #11007
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#10634 introduced an import-time check that ensures that a statement like this:
will raise an exception under the following conditions:
pandas
exists in the environment"dataframe.query-planning"
isTrue
dask_expr
cannot be importedThat exception is currently a
ValueError
. This proposes changing it to anImportError
.Benefits of this change
Allows the use of this pattern to conditionally import
dask.dataframe
:That's the same pattern
dask
itself uses to conditionally import dependencies, for example:dask/dask/dataframe/__init__.py
Lines 83 to 86 in f9310c4
And I think it's common enough across other Python projects that Dask should support it unless there's a compelliing reason to use
ValueError
instead. Some examples:prefect
(code link)scikit-learn
(code link)xgboost
(code link)Notes for Reviewers
I think (but don't know with certainty) that this change would help other projects that rely on
dask.dataframe
but aren't yet supportingdask-expr
. It might help with dask/dask-expr#904, for example.I'm certain it would help
lightgbm
.dask
is an optional dependency of that library, but as ofdask==2024.3.1
, this use ofValueError
would breakimport lightgbm
even if you do not intend to use any of LightGBM's Dask features.traceback (click me)
Mentioning #10995 here as well, to link this to that issue that is collecting feedback on the dask-expr rollout.
Thanks very much for your time and consideration.