Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compat: Dask 2025.1 #6494

Merged
merged 7 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 2 additions & 1 deletion 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 @@ -204,6 +204,7 @@ nbsite = ">=0.8.4,<0.9.0"
pooch = "*"
python-kaleido = "*"
selenium = "*"
dask-core = "<2025.1" # Spatialpandas does not support the new dask-expr DataFrame
hoxbro marked this conversation as resolved.
Show resolved Hide resolved

[feature.doc.activation.env]
DASK_DATAFRAME__QUERY_PLANNING = "False"
Expand Down
Loading