Skip to content

Fix failing test with Dask 2025.2: ours issue not theirs#2663

Merged
sloosvel merged 5 commits intomainfrom
dask_2025.2
Feb 17, 2025
Merged

Fix failing test with Dask 2025.2: ours issue not theirs#2663
sloosvel merged 5 commits intomainfrom
dask_2025.2

Conversation

@valeriupredoi
Copy link
Copy Markdown
Contributor

@valeriupredoi valeriupredoi commented Feb 14, 2025

Description

@sloosvel and I found a failing test with Dask==2025.2 in conda-forge/esmvalcore-feedstock#83 while we were trying to release RC1. @schlunma looked into it here, and concluded the test (ours) needs be fixed, so he's applied the fix - many thanks, Manu!


Before you get started

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


To help with the number pull requests:

@valeriupredoi valeriupredoi added testing dask related to improvements using Dask labels Feb 14, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.07%. Comparing base (dd1e29c) to head (c3561d7).
Report is 48 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2663      +/-   ##
==========================================
- Coverage   95.08%   95.07%   -0.01%     
==========================================
  Files         255      255              
  Lines       14884    14884              
==========================================
- Hits        14152    14151       -1     
- Misses        732      733       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@schlunma
Copy link
Copy Markdown
Contributor

schlunma commented Feb 17, 2025

I don't think this is bug in Dask, but rather a problem with our test.

We have the following setup:

mask = np.ma.masked_array(np.arange(2), mask=[1, 0])  # [-- 1]
array = da.arange(2)  # [0, 1]

Applying this mask to the array gives [-- --] in Dask 2025.1.0 AND Dask 2025.2.0. Using numpy also gives the same result. However, the expected array is

expected = da.ma.masked_array(np.ones(2), np.arange(2))  # [1.0, --]

which is clearly different to the actual result.

So, I think we should adapt our test, not pin Dask. I have no idea why this wasn't a test fail before. Most likely Dask fixed a bug in v2025.2.0...

Test code (gives always the same result, regardless of Dask version; also gives same result for pure-numpy code):

import dask.array as da
import numpy as np

mask = np.ma.masked_array(np.arange(2), mask=[1, 0])
array = da.arange(2)

x = da.ma.masked_where(mask, array)

print("mask", mask)
print("array", array.compute())
print("result", x.compute())
print("result data", x.compute().data)
print("result mask", x.compute().mask)

@schlunma
Copy link
Copy Markdown
Contributor

Test ran successful with Dask 2025.2.0 here and with 2025.1.0 locally 🎉

@valeriupredoi
Copy link
Copy Markdown
Contributor Author

very many thanks for looking into this, Manu! The test is failing with dask==2025.2 but not with dask==2025.1 so we have to be a wee bit careful about it. Let me test your MRE myself, and thanks for including it!

@schlunma
Copy link
Copy Markdown
Contributor

Yes, but with this PR it runs in both Dask versions. As I mentioned above, it rather seems that there was a bug in <=2025.1.0 which let the test pass even though the expected result was clearly wrong (looks like a typo to me). This PR here fixes the expected result of our test.

Copy link
Copy Markdown
Contributor Author

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

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

many thanks, Manu! Indeed - sanity checks all good:

dask==2025.1

mask [-- 1]
array [0 1]
result [-- --]
result data [0 1]
result mask [ True  True]

dask==2025.2

mask [-- 1]
array [0 1]
result [-- --]
result data [0 1]
result mask [ True  True]

dask 2024.8.0

mask [-- 1]
array [0 1]
result [-- --]
result data [0 1]
result mask [ True  True]

@valeriupredoi valeriupredoi changed the title Catch and fix bugs from Dask 2025.2 Fix failing test with Dask 2025.2: ours issue not theirs Feb 17, 2025
@valeriupredoi
Copy link
Copy Markdown
Contributor Author

fixed PR title, and description, @schlunma cheers muchly for your detective work here, pls merge at will 🍺

Copy link
Copy Markdown
Contributor

@schlunma schlunma left a comment

Choose a reason for hiding this comment

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

Cheers! 🍻

@schlunma schlunma added this to the v2.12.0 milestone Feb 17, 2025
@schlunma schlunma removed the dask related to improvements using Dask label Feb 17, 2025
@schlunma schlunma requested a review from sloosvel February 17, 2025 13:22
@sloosvel sloosvel merged commit 6a8406b into main Feb 17, 2025
4 checks passed
@sloosvel sloosvel deleted the dask_2025.2 branch February 17, 2025 13:44
sloosvel pushed a commit that referenced this pull request Feb 19, 2025
Co-authored-by: Manuel Schlund <manuel.schlund@dlr.de>
rhaegar325 pushed a commit that referenced this pull request Feb 26, 2025
Co-authored-by: Manuel Schlund <manuel.schlund@dlr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants