Skip to content

Fix device bug in subtract_dark(scale=True) misreported as unit mismatch - #973

Merged
mwcraig merged 2 commits into
astropy:mainfrom
mwcraig:fix-966-subtract-dark-device
Aug 22, 2026
Merged

Fix device bug in subtract_dark(scale=True) misreported as unit mismatch#973
mwcraig merged 2 commits into
astropy:mainfrom
mwcraig:fix-966-subtract-dark-device

Conversation

@mwcraig

@mwcraig mwcraig commented Aug 22, 2026

Copy link
Copy Markdown
Member

subtract_dark(scale=True) created the scale factor with a bare xp.asarray(scale_factor), which on a device-aware backend (array-api-strict on a non-default device, CuPy) lands on the default device and cannot be multiplied with the master dark. The resulting backend error was caught by the ValueError clause of the surrounding except and re-raised as a spurious UnitsError about mismatched units.

This PR creates the scale factor on the master dark's device (same pattern as gain_correct) and drops ValueError from the caught exceptions; the real unit check raises UnitsError from the CCDData wrapper, and test_subtract_dark_fails only relies on TypeError/UnitsError.

Test matrix (full pytest ccdproc):

backend result
numpy 380 passed, 5 skipped
jax 366 passed, 10 skipped, 2 xfailed, 7 xpassed (pre-existing combiner/image_collection xpasses, unrelated)
dask 370 passed, 15 skipped
dask + CCDPROC_ENFORCE_ESCAPE_BASELINE=1 370 passed, 15 skipped

ccdproc/tests/test_ccdproc.py under array-api-strict: before 32 failed / 31 passed / 10 xfailed; after 28 failed / 35 passed / 10 xfailed. The four test_subtract_dark[...scale=True] variants go from failing to passing; no backend_xfail marker was present on them.

Fixes #966

🤖 Generated with Claude Code

https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA

…unit error

The scale factor was created with a bare ``xp.asarray(scale_factor)``,
which on a device-aware backend (array-api-strict on a non-default
device, CuPy) lands on the default device and cannot be multiplied with
the master dark. The resulting backend error was then caught by the
``ValueError`` clause of the surrounding ``except`` and re-raised as a
spurious ``UnitsError`` about mismatched units.

Create the scale factor on the master dark's device and drop
``ValueError`` from the caught exceptions; the real unit check raises
``UnitsError`` from the CCDData wrapper.

Fixes astropy#966

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.83%. Comparing base (89e90f9) to head (d5cb7e1).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #973   +/-   ##
=======================================
  Coverage   95.83%   95.83%           
=======================================
  Files           8        8           
  Lines        1631     1631           
=======================================
  Hits         1563     1563           
  Misses         68       68           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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
mwcraig marked this pull request as ready for review August 22, 2026 18:24
@mwcraig
mwcraig merged commit 3897909 into astropy:main Aug 22, 2026
19 checks passed
@mwcraig
mwcraig deleted the fix-966-subtract-dark-device branch August 22, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

subtract_dark(scale=True): device-propagation bug misreported as a unit mismatch under array-api-strict

1 participant