[ESSREDUCE] Avoid thread-unsafe warning suppression in unwrap _polygon_intersections#657
Merged
Merged
Conversation
nanmin/nanmax emit an "All-NaN slice encountered" RuntimeWarning for the expected case of a time bin no subframe covers. Suppressing it required warnings.catch_warnings, whose process-global filter state is not thread-safe and races when the unwrap pipeline runs under a multi-threaded scheduler, intermittently leaking the warning (a flaky failure for downstream projects that treat warnings as errors). Reduce with the fmin/fmax ufuncs directly instead: they ignore NaNs and yield NaN only for fully-NaN columns, which is what nanmin/nanmax compute internally minus the all-NaN check that emits the warning. No suppression needed, and it is 2-5x faster as it drops nanmin's NaN-masking copy. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9c24017 to
2a883e1
Compare
nvaytet
approved these changes
Jun 30, 2026
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.
Fixes #656.
_polygon_intersectionsreduces the per-bound interpolated wavelengths withnp.nanmin/np.nanmax. An all-NaN column is the expected case of a time bin that no subframe covers, so those reductions legitimately emit numpy's "All-NaN slice encountered"RuntimeWarning. Suppressing it requiredwarnings.catch_warnings, whose process-global filter state is not thread-safe; under sciline's default dask threaded scheduler, concurrent providers reaching this function race on that state and the warning intermittently leaks. Downstream projects that treat warnings as errors (e.g. esslivedata's wavelength-LUT workflow) then fail flakily.Reducing with the
fmin/fmaxufuncs directly avoids the problem: they ignore NaNs and yield NaN only for fully-NaN columns — exactly whatnanmin/nanmaxcompute internally, minus the all-NaN check that emits the warning. No suppression is needed (thewarningsimport is dropped), and it is 2-5x faster as it skipsnanmin's NaN-masking copy.Benchmark (
yof shape bounds×x, ~20% scattered NaNs + ~15% all-NaN columns):nanmin/nanmax(+catch_warnings)fmin.reduce/fmax.reduceResults are identical to the previous code (NaN for all-NaN columns, NaN-ignoring min/max otherwise).
Test plan
_polygon_intersectionsover uncovered (all-NaN) columns underwarnings.simplefilter("error").tests/unwrappasses (141 tests).