Skip to content
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

Use the correct chunktype for Dask arrays #5801

Merged
merged 10 commits into from
Apr 26, 2024

Conversation

bouweandela
Copy link
Member

@bouweandela bouweandela commented Mar 4, 2024

🚀 Pull Request

Description

Use the correct chunktype for Dask arrays. Closes #5800.


Consult Iris pull request check list


Add any of the below labels to trigger actions on this PR:

  • benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts

@pp-mo pp-mo self-assigned this Mar 28, 2024
@pp-mo pp-mo self-requested a review March 28, 2024 11:36
@pp-mo
Copy link
Member

pp-mo commented Mar 28, 2024

Hi @bouweandela
The existing test breakage is a fairly minor matter, but I think it indicates that removing line 287b is causing the da.from_array to do trial access on the data -- so I think it is probably better to continue to provide a meta key in this case.

However, I am also concerned that ideally we should also be addressing #5800 if possible (!)
In which case, I think this should have a meta of type np.ma.MaskedArray in place of np.ndarray, when appropriate.

From my reading of dask docs, I think it may also be better to pass a zero-shaped instance instead of a class, since the from_array docs don't actually mandate that usage.
Also, it actually doesn't work if I pass meta=np.ma.MaskedArray : This gives a TypeError: MaskedArray.__new__() got an unexpected keyword argument 'shape'.

So I think something like da.from_array(real, meta=real.__class__((), dtype=real.dtype)) works here, and is probably a better way.

Does this make sense to you ?

@bouweandela bouweandela marked this pull request as ready for review April 16, 2024 15:48
@bouweandela bouweandela changed the title Autodetect meta when creating lazy data Use the correct chunktype for Dask arrays Apr 17, 2024
Copy link

codecov bot commented Apr 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.78%. Comparing base (7c313ff) to head (00af67e).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5801      +/-   ##
==========================================
+ Coverage   89.76%   89.78%   +0.01%     
==========================================
  Files          93       93              
  Lines       22982    23004      +22     
  Branches     5006     5015       +9     
==========================================
+ Hits        20630    20654      +24     
+ Misses       1622     1620       -2     
  Partials      730      730              

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

@bouweandela
Copy link
Member Author

bouweandela commented Apr 25, 2024

@bouweandela I suspect that the pre-commit failure is unrelated to this pull request. When I run pre-commit run --all-files on the main branch I get the same error.

Yes, puzzling. We are looking into it...

@pp-mo
Copy link
Member

pp-mo commented Apr 25, 2024

@bouweandela I suspect that the pre-commit failure is unrelated to this pull request. When I run pre-commit run --all-files on the main branch I get the same error.

Yes, puzzling. We are looking into it...

Ok I think we know what this is now -- fix coming soon.
It's only "odd" because the flake8 error code is bugged !

UPDATE: see #5925 -- we think this fixes it

Copy link
Member

@pp-mo pp-mo left a comment

Choose a reason for hiding this comment

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

I think everything here is basically good, and it's a really nice touch to provide a fix for concatenate as well as stack.

However, I think we need to rethink the merge, since some changes from #5588 seem to have got lost.
I guess that means that merging back into this will cause problems
( I expect at least some tests ought then to fail, otherwise where is the testing of those new keywords ?? )
So I haven't updated with main, as you may want to resolve this in your own way.

From a quick search I also think that, unlike 'stack', there are multiple uses of 'concatenate' elsewhere in the Iris code that would benefit from using the new routine.
However, given how involved this is getting, it would make good sense to get this working + merged in first : then I can follow up with another to expand the use of _lazy.data.concatenate.

lib/iris/_lazy_data.py Show resolved Hide resolved
lib/iris/_lazy_data.py Show resolved Hide resolved
lib/iris/_lazy_data.py Show resolved Hide resolved
lib/iris/_lazy_data.py Show resolved Hide resolved
lib/iris/fileformats/netcdf/_thread_safe_nc.py Outdated Show resolved Hide resolved
lib/iris/fileformats/pp.py Outdated Show resolved Hide resolved
@bouweandela
Copy link
Member Author

Thank you for reviewing @pp-mo! I just merged the latest main into this branch and the pre-commit test is passing fine now 🥳

However, I think we need to rethink the merge, since some changes from #5588 seem to have got lost.
I guess that means that merging back into this will cause problems
( I expect at least some tests ought then to fail, otherwise where is the testing of those new keywords ?? )
So I haven't updated with main, as you may want to resolve this in your own way.

I refactored the as_lazy_data function a bit, but the functionality is still there (see #5801 (comment)). If you prefer, I can undo that?

@pp-mo
Copy link
Member

pp-mo commented Apr 26, 2024

If you prefer, I can undo that?

Thanks no, I just hadn't understood fully what you were doing. It's good !

lib/iris/_lazy_data.py Show resolved Hide resolved
@pp-mo pp-mo merged commit b33ccc1 into SciTools:main Apr 26, 2024
21 checks passed
@bouweandela bouweandela deleted the do-not-force-meta branch April 26, 2024 10:53
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.

iris.cube.Cube.lazy_data method results in wrong chunk array type for masked arrays
2 participants