Fixes #877, #876, #884: prevent OOM and unknown chunks in classify.py dask paths#895
Merged
brendancol merged 3 commits intomasterfrom Feb 25, 2026
Merged
Conversation
…ify.py natural_breaks and maximum_breaks dask code paths called .ravel().compute() on the full array, materialising the entire dataset into RAM. Replace with capped sampling via _generate_sample_indices() + indexed access so only the sample is ever computed. Add num_sample parameter to maximum_breaks (default 20_000, matching natural_breaks).
…path quantile() and percentiles() used data[module.isfinite(data)] on dask arrays, which creates unknown chunk sizes that degrade scheduling and can force unexpected materialisations. Replace with dedicated dask functions that use da.where to clean inf→nan (preserving known chunks), compute to numpy, then use np.nanpercentile + np.unique.
…aths The previous commit eliminated unknown dask chunks but still materialised the full array via .ravel().compute(). Now both functions accept num_sample (default 20_000, matching natural_breaks/maximum_breaks) and use _generate_sample_indices() + indexed access so only the sample is ever computed on dask backends.
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
All four classification functions in
classify.pyhad dask code paths thatcould materialise the entire array into RAM or create unknown chunk sizes.
This PR fixes them all with the same pattern: lazy sampling via
_generate_sample_indices()+ indexed access, andda.whereinstead ofboolean fancy indexing.
natural_breaks (classify.natural_breaks: fallback
.ravel().compute()when no sampling #877): Removed theelsebranch in_run_dask_natural_breakand_run_dask_cupy_natural_breakthat calleddata.ravel().compute()whennum_sample is Noneor>= data.size.Now caps
num_sampletodata.sizeand always uses indexed access(
data.ravel()[sample_idx].compute()).maximum_breaks (classify.maximum_breaks: unconditional
.ravel().compute()on dask #876): Addednum_sampleparameter (default20_000,matching
natural_breaks). Both dask functions now use_generate_sample_indices()+ indexed access instead of unconditional.ravel().compute().quantile & percentiles (classify.quantile: boolean fancy indexing on dask creates unknown chunks #884): Replaced boolean fancy indexing
(
data[da.isfinite(data)]) — which creates unknown dask chunk sizes —with dedicated
_run_dask_*functions that useda.whereto cleaninf→nan (preserving known chunks), then sample lazily via indexed access
and compute percentiles with
np.percentile+np.unique. Addednum_sampleparameter (default20_000) to bothquantile()andpercentiles(). The numpy/cupy in-memory paths accept and ignorenum_sample.Test plan
test_classify.pypass