Fix background_deviation_box discarding the xpx.at result on immutable backends - #977
Merged
Merged
Conversation
xpx.at(barr)[...].set(...) returns a new array; the result was never rebound, so on immutable backends (JAX, array-api-strict) every box was silently left at the global standard deviation. Rebind the result. Add a regression test with different noise scales in different boxes so the per-box values are actually checked; the existing test only checked the mean, which passed by accident. Also make that existing test use xp.mean() so it runs on array-api-strict. Fixes astropy#963 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #977 +/- ##
=======================================
Coverage 95.83% 95.83%
=======================================
Files 8 8
Lines 1631 1631
=======================================
Hits 1563 1563
Misses 68 68 ☔ 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
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes background_deviation_box for immutable Array API backends (e.g., JAX) by correctly rebinding the result of a functional array update, and strengthens regression coverage to ensure per-box values are actually written.
Changes:
- Rebind
xpx.at(...).set(...)result inbackground_deviation_boxso updates take effect on immutable backends. - Improve/extend tests to validate per-box deviations (and adjust existing mean check to be Array API compatible).
- Add a changelog entry describing the bug and fix.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
ccdproc/core.py |
Rebinds functional update result to make per-box writes effective on immutable backends. |
ccdproc/tests/test_cosmicray.py |
Updates existing test for backend compatibility and adds per-box regression test for #963. |
CHANGES.rst |
Documents the bug fix in the unreleased changelog. |
ccdproc/__init__.py |
Adds a blank line after the module docstring (formatting only). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
mwcraig
commented
Aug 22, 2026
Address review on astropy#977: the box std bounds were ~7x wider than the sampling spread, and the test comment did not explain that setbox never fills the final row/column of the image. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA
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.
background_deviation_boxcalledxpx.at(barr)[y1:y2, x1:x2].set(...)without rebinding the result.xpx.at(...).set()returns a new array, so on immutable backends (JAX, array-api-strict) every box was silently left at the global standard deviation. This rebinds the result.The existing
test_background_deviation_boxonly checked the mean of the output, which happens to pass on JAX even when the per-box values are never written. A new regression test (test_background_deviation_box_per_box_values) uses different noise scales in different boxes and checks the per-box values; it fails on JAX before the fix and passes after. The existing test now usesxp.mean()so it also runs on array-api-strict.Test matrix (full suite unless noted):
test_cosmicray.pyonlyFixes #963
🤖 Generated with Claude Code
https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA