Add a spec-only nanmedian fallback for Combiner.median_combine - #978
Open
mwcraig wants to merge 2 commits into
Open
Add a spec-only nanmedian fallback for Combiner.median_combine#978mwcraig wants to merge 2 commits into
mwcraig wants to merge 2 commits into
Conversation
Add ccdproc/_nanmedian.py, a NaN-aware median written purely in terms of the array API standard (sort, count non-NaN, gather the two middle elements), and use it from _default_median when the selected namespace has no nanmedian instead of raising RuntimeError. Works on numpy, jax, dask and array-api-strict. Fix the docs, which claimed a bottleneck -> numpy fallback that did not exist, and drop the numpy-median and pytest.skip workarounds in test_combiner.py now that a median is available on every backend. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #978 +/- ##
==========================================
+ Coverage 95.83% 95.84% +0.01%
==========================================
Files 8 9 +1
Lines 1631 1659 +28
==========================================
+ Hits 1563 1590 +27
- Misses 68 69 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
pre-commit.ci has been failing on main since the black 26.5.1 bump in astropy#919 because black now requires a blank line after the module docstring in ccdproc/__init__.py. This is the only formatting change it wants. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA
mwcraig
marked this pull request as ready for review
August 22, 2026 18:24
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.
Adds
ccdproc/_nanmedian.py, a NaN-aware median written only in terms of array-API-standard functions (sort the axis, count non-NaN entries, gather and average the two middle elements; all-NaN slices give NaN; integer input is promoted to float64).Combiner._default_mediannow returns this fallback (bound to the namespace viafunctools.partial) when the namespace has nonanmedian, instead of raisingRuntimeError. The fallback is O(n log n) along the combination axis; nativenanmedian/ bottleneck are still preferred when available.Also:
docs/array_api.rst: replace the claim of a bottleneck -> numpy fallback (which did not exist) with the real chain (bottleneck for numpy ->xp.nanmedian-> spec-only fallback).test_combiner.py: drop the numpy-median/.compute()workarounds and thepytest.skipfor namespaces withoutmedian;test_bottleneck_defaults_respect_array_namespacenow checks the fallback is returned whennanmedianis absent.ccdproc/tests/test_nanmedian.py(odd/even lengths, 1-D/2-D/3-D, partial and all-NaN columns, integer input, axis=1/-1, unsupported axis).Test matrix (
pytest ccdproc):CCDPROC_LOG_ARRAY_ESCAPES=1 CCDPROC_ENFORCE_ESCAPE_BASELINE=1): 383 passed, 15 skipped; no escapes outside the baselinetest_nanmedian.py: 13 passedtest_combiner.py: 75 failed / 12 passed before -> 74 failed / 13 passed after. All remainingmedian_combinefailures under strict hit theCombinerconstructor ("Nested Arrays are not allowed", being fixed in Build Combiner data and mask arrays with xp.stack #976) or other known strict bugs, not the median itself.Fixes #906
🤖 Generated with Claude Code
https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA