Repository navigation
Fix time-lag UnitConversionError under dask.distributed process workers - #350
Open
CharlesXmf wants to merge 4 commits into
Open
CharlesXmf wants to merge 4 commits into
CharlesXmf wants to merge 4 commits into
Conversation
Keep lag selection unitless in the Dask graph and re-attach the time unit after client-side compute. Multiplying by a unit inside the lazy graph put Quantity chunks on distributed workers, which dropped units and raised UnitConversionError from dask v2025.4.0. Co-authored-by: Charles <CharlesXmf@users.noreply.github.com>
Hook __dask_postcompute__ so array.compute() and dask.compute() both return a Quantity. On distributed process workers, Quantity is serialized as a bare ndarray, so finalize returns a pickle proxy that rehydrates the unit on the client instead of putting Quantity chunks in the graph. Co-authored-by: Charles <CharlesXmf@users.noreply.github.com>
Only use the pickle proxy when finalize runs on a process worker whose address is not inproc://. Inproc workers share the result by reference, so multiplying by the unit in finalize already yields a Quantity. Cover Client(processes=False) in the regression. Co-authored-by: Charles <CharlesXmf@users.noreply.github.com>
Rename the changelog fragment to 350.bugfix.rst. Quote dask.distributed as a literal so the docs build does not warn under -W. Add an in-process pickle round-trip for the unit proxy that distributed process workers return from finalize. Co-authored-by: Charles <CharlesXmf@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
time_lagused to multiply the selected lags by their time unit inside the lazy Dask graph. With the default scheduler that works. With process-baseddask.distributedworkers (dask v2025.4.0 and later), some chunks come back dimensionless, and concatenating mixed dimensionless/schunks raisesUnitConversionError. A thread-based / inproc client does not reproduce the failure. See #276.This keeps the Dask graph unitless and re-attaches the unit through
__dask_postcompute__, so botharray.compute()anddask.compute()still return aQuantity, whiletime_lag(...)itself remains adask.array.Array. BecauseHLGFinalizeComputeruns finalize on the worker, aQuantitywould be stripped by distributed's numpy serializer on the way back to the client. Finalize therefore returns a small pickle proxy only on process workers (addresses that are notinproc://); inproc workers and the default scheduler multiply by the unit in-process and return a realQuantity.The regression covers
Client(processes=True)andClient(processes=False), and asserts both compute paths. The tests extra now depends ondask[distributed]so that case is actually installed.Fixes #276
AI Assistance Disclosure
AI tools were used for:
A Cursor cloud agent (Grok 4.6) was used to implement the change, write the regression tests, and draft the changelog fragment. The resulting patch was reviewed before this pull request was opened.