Skip to content

Commit 45f5baa

Browse files
committed
✅: dask
Signed-off-by: nstarman <[email protected]>
1 parent d4078d7 commit 45f5baa

File tree

4 files changed

+249
-1
lines changed

4 files changed

+249
-1
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,47 @@ jobs:
144144
145145
# TODO: (based)pyright
146146

147+
test_integration_dask:
148+
name: integration tests (dask)
149+
runs-on: ubuntu-latest
150+
strategy:
151+
fail-fast: false
152+
matrix:
153+
dask-version: ["2025.7.0"]
154+
155+
steps:
156+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
157+
158+
- uses: astral-sh/setup-uv@d9e0f98d3fc6adb07d1e3d37f3043649ddad06a1 # v6.5.0
159+
with:
160+
python-version: "3.11"
161+
activate-environment: true
162+
163+
# NOTE: `uv run --with=...` will be ignored by mypy (and `--isolated` does not help)
164+
- name: mypy
165+
run: |
166+
uv sync --no-editable --group=mypy
167+
uv pip install dask==${{ matrix.dask-version }}
168+
uv run --no-sync --active \
169+
mypy --tb --no-incremental --cache-dir=/dev/null \
170+
tests/integration/test_dask.pyi
171+
172+
- name: basedmypy
173+
run: |
174+
uv sync --no-editable --group=basedmypy
175+
uv pip install dask==${{ matrix.dask-version }}
176+
uv run --no-sync --active \
177+
mypy --tb --no-incremental --cache-dir=/dev/null \
178+
tests/integration/test_dask.pyi
179+
180+
- name: pyright
181+
run: |
182+
uv sync --no-editable --group=pyright
183+
uv pip install dask==${{ matrix.dask-version }}
184+
uv run --no-sync --active \
185+
tests/integration/test_dask.pyi
186+
187+
# TODO: (based)pyright
188+
147189
# TODO: integration tests for array-api-strict
148-
# TODO: integration tests for 3rd party libs such as cupy, pytorch, tensorflow, dask, etc.
190+
# TODO: integration tests for 3rd party libs such as cupy, pytorch, tensorflow, etc.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ pyright = [
6868
basedmypy = [
6969
"basedmypy>=2.10.0",
7070
]
71+
test-dask = [
72+
"dask>=2025.7.0",
73+
]
7174

7275
[tool.hatch]
7376
version.source = "vcs"

tests/integration/test_dask.pyi

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# mypy: disable-error-code="no-redef, explicit-any"
2+
3+
from types import ModuleType
4+
from typing import Any, TypeAlias
5+
6+
import dask.array as da
7+
import numpy as np
8+
9+
import array_api_typing as xpt
10+
11+
# DType aliases
12+
F32: TypeAlias = np.float32
13+
I32: TypeAlias = np.int32
14+
15+
# Define Dask Arrays against which we can test the protocols
16+
# (Dask's Array type is not parametrized by dtype at type level.)
17+
darr: da.Array
18+
darr_i32: da.Array
19+
darr_f32: da.Array
20+
darr_b: da.Array
21+
22+
# =========================================================
23+
# `xpt.HasArrayNamespace`
24+
25+
# Check assignment
26+
_001: xpt.HasArrayNamespace[ModuleType] = darr
27+
_002: xpt.HasArrayNamespace[ModuleType] = darr_i32
28+
_003: xpt.HasArrayNamespace[ModuleType] = darr_f32
29+
_004: xpt.HasArrayNamespace[ModuleType] = darr_b
30+
31+
# Check `__array_namespace__` method
32+
a_ns: xpt.HasArrayNamespace[ModuleType] = darr
33+
ns: ModuleType = a_ns.__array_namespace__()
34+
35+
# =========================================================
36+
# `xpt.HasDType`
37+
38+
# Check DTypeT_co assignment
39+
_005: xpt.HasDType[Any] = darr
40+
_006: xpt.HasDType[np.dtype[I32]] = darr_i32
41+
_007: xpt.HasDType[np.dtype[F32]] = darr_f32
42+
_008: xpt.HasDType[np.dtype[np.bool_]] = darr_b
43+
44+
# =========================================================
45+
# `xpt.Array`
46+
47+
# Check NamespaceT_co assignment
48+
x_ns: xpt.Array[Any, ModuleType] = darr
49+
50+
# Check DTypeT_co assignment
51+
_009: xpt.Array[Any] = darr
52+
_010: xpt.Array[np.dtype[I32]] = darr_i32
53+
_011: xpt.Array[np.dtype[F32]] = darr_f32
54+
_012: xpt.Array[np.dtype[np.bool_]] = darr_b

0 commit comments

Comments
 (0)