| 9 | |
| 10 | |
| 11 | def _array_expr_enabled() -> builtins.bool: |
| 12 | import dask |
| 13 | |
| 14 | global ARRAY_EXPR_ENABLED |
| 15 | |
| 16 | use_array_expr: builtins.bool | None = dask.config.get("array.query-planning") |
| 17 | if use_array_expr is None: |
| 18 | use_array_expr = False # Eventually, this default will flip to True |
| 19 | if not isinstance(use_array_expr, builtins.bool): |
| 20 | # Guard against "false" string in YAML config, which would evaluate to True |
| 21 | raise TypeError( # pragma: no cover |
| 22 | "The 'array.query-planning' config must be True, False, or None" |
| 23 | ) |
| 24 | |
| 25 | if ARRAY_EXPR_ENABLED is None: |
| 26 | ARRAY_EXPR_ENABLED = use_array_expr |
| 27 | return use_array_expr |
| 28 | |
| 29 | if use_array_expr != ARRAY_EXPR_ENABLED: |
| 30 | warnings.warn( |
| 31 | "The 'array.query-planning' config is now set to " |
| 32 | f"{use_array_expr}, but query planning is already " |
| 33 | f"{'enabled' if ARRAY_EXPR_ENABLED else 'disabled'}. " |
| 34 | "The query-planning config can only be changed before " |
| 35 | "`dask.array` is first imported!", |
| 36 | RuntimeWarning, |
| 37 | ) |
| 38 | return ARRAY_EXPR_ENABLED |
| 39 | |
| 40 | |
| 41 | def array_expr_enabled() -> builtins.bool: |