Skip to content

Commit

Permalink
compat: Dask 2025.1 (#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Jan 21, 2025
1 parent 2928aa2 commit f9b5aa4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
23 changes: 14 additions & 9 deletions holoviews/tests/core/data/test_daskinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
from holoviews.core.util import PANDAS_VERSION
from holoviews.util.transform import dim

from ...utils import dask_switcher
from ...utils import DASK_VERSION, dask_setup, dask_switcher
from .test_pandasinterface import BasePandasInterfaceTests

try:
import dask_expr
except ImportError:
dask_expr = None
classic, expr = dask_setup()


class _DaskDatasetTest(BasePandasInterfaceTests):
Expand Down Expand Up @@ -136,9 +133,11 @@ def test_select_expression_lazy(self):

class DaskClassicDatasetTest(_DaskDatasetTest):

data_type = dd.core.DataFrame
# No longer supported from Dask 2025.1

__test__ = True
data_type = getattr(dd.core, "DataFrame", None)

__test__ = classic

@dask_switcher(query=False)
def setUp(self):
Expand All @@ -147,11 +146,17 @@ def setUp(self):

class DaskExprDatasetTest(_DaskDatasetTest):

__test__ = bool(dask_expr)
__test__ = expr

@property
def data_type(self):
return dask_expr.DataFrame
# Only available from 2025.1 and forward
if DASK_VERSION >= (2025, 1, 0):
return dd.DataFrame
else:
import dask_expr

return dask_expr.DataFrame

@dask_switcher(query=True)
def setUp(self):
Expand Down
48 changes: 43 additions & 5 deletions holoviews/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import logging
import os
import sys
from contextlib import contextmanager
from contextlib import contextmanager, suppress
from functools import lru_cache
from importlib import reload
from importlib.util import find_spec

import param
import pytest

from holoviews.core.util import _no_import_version
from holoviews.element.comparison import ComparisonTestCase

cwd = os.path.abspath(os.path.split(__file__)[0])
Expand Down Expand Up @@ -118,25 +120,61 @@ def tearDown(self):


DASK_UNAVAILABLE = find_spec("dask") is None
EXPR_UNAVAILABLE = find_spec("dask_expr") is None
DASK_VERSION = _no_import_version("dask")


@lru_cache
def dask_setup():
"""
Set-up both dask dataframes, using lru_cahce to only do it once
"""
from datashader.data_libraries.dask import bypixel, dask_pipeline

classic, expr = False, False

# Removed in Dask 2025.1, and will raise AttributeError
if DASK_VERSION < (2025, 1, 0):
import dask.dataframe as dd

bypixel.pipeline.register(dd.core.DataFrame)(dask_pipeline)
classic = True
else:
# dask_expr import below will now fail with:
# cannot import name '_Frame' from 'dask.dataframe.core'
expr = True

with suppress(ImportError):
import dask_expr

bypixel.pipeline.register(dask_expr.DataFrame)(dask_pipeline)
expr = True

return classic, expr


@contextmanager
def dask_switcher(*, query=False, extras=()):
def dask_switcher(*, query=False, extras=None):
"""
Context manager to switch on/off dask-expr query planning.
Using a context manager as it is an easy way to
change the function to a decorator.
"""
if DASK_UNAVAILABLE:
pytest.skip("dask is not available")
if query and EXPR_UNAVAILABLE:

classic, expr = dask_setup()

if not query and not classic:
pytest.skip("Classic DataFrame no longer supported by dask")
if query and not expr:
pytest.skip("dask-expr is not available")

import dask

dask.config.set(**{"dataframe.query-planning": query})
for module in ("dask.dataframe", *extras):
for module in ("dask.dataframe", *(extras or ())):
if module in sys.modules:
reload(sys.modules[module])
yield
3 changes: 1 addition & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pytest-xdist = "*"
test-unit = 'pytest holoviews/tests -n logical --dist loadgroup'

[feature.test-example.tasks]
test-example = { cmd = 'pytest -n logical --dist loadscope --nbval-lax examples', env = { DASK_DATAFRAME__QUERY_PLANNING = "False" } }
test-example = 'pytest -n logical --dist loadscope --nbval-lax examples'

[feature.test-example.dependencies]
nbval = "*"
Expand Down Expand Up @@ -206,7 +206,6 @@ python-kaleido = "*"
selenium = "*"

[feature.doc.activation.env]
DASK_DATAFRAME__QUERY_PLANNING = "False"
MOZ_HEADLESS = "1"
MPLBACKEND = "Agg"
PANEL_EMBED = "true"
Expand Down

0 comments on commit f9b5aa4

Please sign in to comment.