Skip to content

Commit 8d7e3a9

Browse files
authored
Merge pull request #190 from crusaderky/lazy_apply_dask_test
TST: add test for Dask keys in lazy_apply
2 parents 8beece3 + 76d6145 commit 8d7e3a9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_lazy.py

+21
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ def f(x: Array) -> Array:
186186
xp_assert_equal(y.compute(), x_cp + 1) # type: ignore[attr-defined] # pyright: ignore[reportUnknownArgumentType,reportAttributeAccessIssue]
187187

188188

189+
def test_dask_key(da: ModuleType):
190+
"""Test that the function name is visible on the Dask dashboard and in metrics."""
191+
192+
def helloworld(x: Array) -> Array:
193+
return x + 1
194+
195+
x = da.asarray([1, 2])
196+
# Use full namespace to bypass monkey-patching by lazy_xp_function,
197+
# which calls persist() to materialize exceptions and warnings and in
198+
# doing so squashes the graph.
199+
y = xpx.lazy_apply(helloworld, x)
200+
201+
prefixes = set()
202+
for key in y.__dask_graph__(): # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
203+
name = key[0] if isinstance(key, tuple) else key
204+
assert isinstance(name, str)
205+
prefixes.add(name.split("-")[0])
206+
207+
assert "helloworld" in prefixes
208+
209+
189210
def test_lazy_apply_none_shape_in_args(xp: ModuleType, library: Backend):
190211
x = xp.asarray([1, 1, 2, 2, 2])
191212

0 commit comments

Comments
 (0)