Fix #1308: Scope dask.config.set() to specific operations instead of module import#1309
Open
khushthecoder wants to merge 3 commits intomalariagen:masterfrom
Open
Fix #1308: Scope dask.config.set() to specific operations instead of module import#1309khushthecoder wants to merge 3 commits intomalariagen:masterfrom
khushthecoder wants to merge 3 commits intomalariagen:masterfrom
Conversation
added 3 commits
April 17, 2026 22:06
…nstead of module import Move the `split_native_chunks` config override from module-level in ag3.py to context managers within the specific methods that require it. This prevents importing malariagen_data from silently modifying global dask configuration, which could degrade performance for unrelated dask workloads in the same Python session. Affected operations: - util._da_compress(): wraps da.compress() call - snp_data.snp_genotypes(): wraps da.compress() and da.take() calls - snp_data._locate_site_class(): wraps da.take() call
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.
Summary
Fixes #1308
ag3.pyline 10 executesdask.config.set(**{"array.slicing.split_native_chunks": False})at module import time, which silently disables a dask performance optimization globally for the entire Python process — not justmalariagen_dataoperations.This PR scopes the config override to context managers (
with dask.config.set(...)) within the specific methods that require it, so the config is restored immediately after each operation completes.Changes
malariagen_data/ag3.py: Removed the module-leveldask.config.set()call and the now-unusedimport dask.malariagen_data/util.py: Added scopeddask.config.set()context manager aroundda.compress()in_da_compress().malariagen_data/anoph/snp_data.py: Added scopeddask.config.set()context managers around:da.compress()insnp_genotypes()(sample filtering)da.take()insnp_genotypes()(sample indexing)da.take()in_locate_site_class()(site annotation subsetting)Why This Matters
import malariagen_datano longer modifies global dask configuration.malariagen_datawith other dask tools won't see unexplained behavior changes.Related: #1305 (same class of issue — global state mutation that leaks beyond
malariagen_data's scope)Test Plan
ruff checkpasses on all changed filesruff formatpasses on all changed filesimport malariagen_datano longer modifiesdask.config