Skip to content

Commit

Permalink
raise error on bad query-planning config
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzamora committed Jun 13, 2024
1 parent 05b8d66 commit 7693267
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dask/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from dask.typing import no_default

_dataframe_query_planning: None | bool = None # noqa: F401


def _get_paths():
"""Get locations to search for YAML configuration files.
Expand Down
20 changes: 20 additions & 0 deletions dask/dataframe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@ def _dask_expr_enabled() -> bool:
import pandas as pd

import dask
from dask.config import _dataframe_query_planning

def _raise(new, old):
old_repr = "enabled" if old else "disabled"
raise ValueError(
f"The 'dataframe.query-planning' config is now set to {new}, "
"but `dask.dataframe` was first imported with query planning "
f"{old_repr}. Please make sure the query-planning config is "
"only set before `dask.dataframe` is first imported!"
)

use_dask_expr = dask.config.get("dataframe.query-planning")
if use_dask_expr is True and _dataframe_query_planning is False:
_raise(use_dask_expr, _dataframe_query_planning)
elif use_dask_expr is False and _dataframe_query_planning is True:
_raise(use_dask_expr, _dataframe_query_planning)
elif _dataframe_query_planning is not None:
return _dataframe_query_planning

if (
use_dask_expr is False
or use_dask_expr is None
and Version(pd.__version__).major < 2
):
_dataframe_query_planning = False
return False
try:
import dask_expr # noqa: F401
Expand All @@ -29,9 +47,11 @@ def _dask_expr_enabled() -> bool:
"""
if use_dask_expr is None:
warnings.warn(msg, FutureWarning)
_dataframe_query_planning = False
return False
else:
raise ImportError(msg)
_dataframe_query_planning = True
return True


Expand Down

0 comments on commit 7693267

Please sign in to comment.