raise ImportError instead of ValueError when dask-expr cannot be imported#11007
Conversation
Contributor
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 15 files ±0 15 suites ±0 3h 16m 55s ⏱️ - 12m 34s For more details on these failures, see this check. Results for commit 1b7d29d. ± Comparison against base commit f9310c4. |
5 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
pandasexists in the environment"dataframe.query-planning"isTruedask_exprcannot 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
daskitself 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
ValueErrorinstead. 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.dataframebut aren't yet supportingdask-expr. It might help with dask/dask-expr#904, for example.I'm certain it would help
lightgbm.daskis an optional dependency of that library, but as ofdask==2024.3.1, this use ofValueErrorwould breakimport lightgbmeven if you do not intend to use any of LightGBM's Dask features.docker run \ --rm \ -v $(pwd):/opt/LightGBM \ -w /opt/LightGBM \ -it python:3.11 \ bash pip install \ 'dask==2024.3.1' \ 'lightgbm>=4.3.0' \ 'pandas==2.2.1' \ 'pyyaml' DASK_DATAFRAME__QUERY_PLANNING=true \ python -c "import lightgbm"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.