Skip to content

TST: add test for Dask keys in lazy_apply #190

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

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Changes from all 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
21 changes: 21 additions & 0 deletions tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ def f(x: Array) -> Array:
xp_assert_equal(y.compute(), x_cp + 1) # type: ignore[attr-defined] # pyright: ignore[reportUnknownArgumentType,reportAttributeAccessIssue]


def test_dask_key(da: ModuleType):
"""Test that the function name is visible on the Dask dashboard and in metrics."""

def helloworld(x: Array) -> Array:
return x + 1

x = da.asarray([1, 2])
# Use full namespace to bypass monkey-patching by lazy_xp_function,
# which calls persist() to materialize exceptions and warnings and in
# doing so squashes the graph.
y = xpx.lazy_apply(helloworld, x)

prefixes = set()
for key in y.__dask_graph__(): # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
name = key[0] if isinstance(key, tuple) else key
assert isinstance(name, str)
prefixes.add(name.split("-")[0])

assert "helloworld" in prefixes


def test_lazy_apply_none_shape_in_args(xp: ModuleType, library: Backend):
x = xp.asarray([1, 1, 2, 2, 2])

Expand Down