Skip to content

Add tests for the array assert_eq helper - #12441

Merged
crusaderky merged 5 commits into
dask:mainfrom
kyo5uke:dask-array-assert-eq-tests
Jun 9, 2026
Merged

crusaderky merged 5 commits into
dask:mainfrom
kyo5uke:dask-array-assert-eq-tests

Conversation

@kyo5uke

@kyo5uke kyo5uke commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

The array assert_eq testing helper only had a scalar test. This adds tests that cover the common behaviours:

  • a matching dask/numpy array pair
  • shape mismatch raising AssertionError
  • dtype mismatch (raising by default, passing with check_dtype=False)
  • NaN handling (equal_nan default vs equal_nan=False)

Closes #2682

@github-actions

github-actions Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     25 files  ± 0       25 suites  ±0   7h 0m 22s ⏱️ - 8m 57s
 18 643 tests + 4   17 454 ✅ + 4   1 189 💤 ±0  0 ❌ ±0 
379 089 runs  +88  331 841 ✅ +85  47 248 💤 +3  0 ❌ ±0 

Results for commit 174bee1. ± Comparison against base commit d0666ee.

♻️ This comment has been updated with latest results.

Comment thread dask/array/tests/test_testing.py Outdated
Comment on lines +27 to +29
assert assert_eq(d, x)
assert assert_eq(x, x)
assert assert_eq(d, d)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should not be an extra assert. There should also be a false-y use case.

Comment thread dask/array/tests/test_testing.py Outdated
@pytest.mark.skipif(bool(sys.flags.optimize), reason="Assertions disabled.")
def test_assert_eq_checks_shape():
with pytest.raises(AssertionError):
assert_eq(np.array([1, 2]), np.array([1, 2, 3]))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misses true-y use case

Comment thread dask/array/tests/test_testing.py Outdated
with pytest.raises(AssertionError):
assert_eq(a, b)
# values are equal, so disabling the dtype check should pass
assert assert_eq(a, b, check_dtype=False)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert assert_eq(a, b, check_dtype=False)
assert_eq(a, b, check_dtype=False)

Comment thread dask/array/tests/test_testing.py Outdated
a = np.array([1.0, np.nan])
b = np.array([1.0, np.nan])
# NaNs compare equal by default
assert assert_eq(a, b)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert assert_eq(a, b)
assert_eq(a, b)

Comment thread dask/array/tests/test_testing.py Outdated
Comment on lines +50 to +51
a = np.array([1.0, np.nan])
b = np.array([1.0, np.nan])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing two numpy arrays is not terribly useful for a dask-specific tool

@kyo5uke

kyo5uke commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @crusaderky! Addressed all the points: dropped the assert wrappers (assert_eq raises on failure), switched the cases to dask arrays, and each test now covers both a passing and a failing case.

@kyo5uke

kyo5uke commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @crusaderky! Addressed in 85e0e0c: removed the assert wrappers (assert_eq returns None), switched the inputs to dask arrays, and each test now exercises both a passing and a failing (pytest.raises) case. CI is green apart from the unrelated nightly upstream job. Ready for another look when you have a moment.

Comment thread dask/array/tests/test_testing.py Resolved
Comment thread dask/array/tests/test_testing.py Resolved
Comment thread dask/array/tests/test_testing.py Resolved
Comment thread dask/array/tests/test_testing.py Resolved
@crusaderky
crusaderky merged commit 2be4507 into dask:main Jun 9, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a tests for our tests helpers

2 participants