Skip to content

Cast mask to data dtype in create_deviation for strict array API - #972

Merged
mwcraig merged 2 commits into
astropy:mainfrom
mwcraig:fix-968-create-deviation-mask
Aug 22, 2026
Merged

Cast mask to data dtype in create_deviation for strict array API#972
mwcraig merged 2 commits into
astropy:mainfrom
mwcraig:fix-968-create-deviation-mask

Conversation

@mwcraig

@mwcraig mwcraig commented Aug 22, 2026

Copy link
Copy Markdown
Member

create_deviation(..., disregard_nan=True) multiplied a float array by a boolean mask (data * ~mask). The Array API standard only allows arithmetic between numeric dtypes, so array-api-strict raised TypeError: Only numeric dtypes are allowed in __mul__. This casts the inverted mask to the data dtype first; the double-sqrt NaN trick that follows is unchanged.

test_create_deviation_from_negative_2 used the same idiom and also added a numpy.float64 scalar to a strict array, so the test is adjusted the same way. No backend_xfail markers existed on the create_deviation tests, so none needed removing.

Test matrix

backend pytest ccdproc
numpy 380 passed, 5 skipped
jax (JAX_ENABLE_X64=True) 366 passed, 10 skipped, 2 xfailed, 7 xpassed (all pre-existing, in test_combiner / test_image_collection)
dask 370 passed, 15 skipped
dask + CCDPROC_LOG_ARRAY_ESCAPES=1 CCDPROC_ENFORCE_ESCAPE_BASELINE=1 370 passed, 15 skipped; "OK: no library escapes outside the baseline"

ccdproc/tests/test_ccdproc.py under array-api-strict: 32 failed / 31 passed / 10 xfailed before, 31 failed / 32 passed / 10 xfailed after. All 11 create_deviation tests pass under strict.

Fixes #968

🤖 Generated with Claude Code

https://claude.ai/code/session_01DTN9DnPnLKK2u7knnMJ2gA

``create_deviation(..., disregard_nan=True)`` multiplied a float array by
a boolean mask. array-api-strict (and the Array API standard) only allow
arithmetic between numeric dtypes, so this raised ``TypeError``. Cast the
inverted mask to the data dtype first. The double-sqrt NaN trick that
follows is unchanged.

``test_create_deviation_from_negative_2`` used the same idiom and also
added a ``numpy.float64`` scalar to a strict array; cast both explicitly.

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 (b58717a).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #972   +/-   ##
=======================================
  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 49382df into astropy:main Aug 22, 2026
19 checks passed
@mwcraig
mwcraig deleted the fix-968-create-deviation-mask branch August 22, 2026 21:21
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.

create_deviation: float * bool-mask multiplication rejected by array-api-strict (core.py:459)

1 participant