Skip to content

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

Description

@mwcraig

Under CCDPROC_ARRAY_LIBRARY=array-api-strict, ccdproc/tests/test_ccdproc.py::test_create_deviation_from_negative_2 fails because create_deviation multiplies a float array by a bool mask array. (The #941 table estimated ~2 failures for this site; at branch tip d329ac5 the dedupe report shows exactly 1.)

ccdproc/core.py:459: in create_deviation
    data = data * ~mask
array_api_strict/_array_object.py:842: in __mul__
    other = self._check_allowed_dtypes(other, "numeric", "__mul__")
E   TypeError: Only numeric dtypes are allowed in __mul__

Offending codeccdproc/core.py (branch array-api-strict-triage-tooling), inside create_deviation:

data = gain_value * ccd_data.data
mask = data < 0            # bool-dtype Array

if disregard_nan:
    data = data * ~mask    # line 459: float64 * bool -> TypeError

Root cause: the Array API spec treats bool as a dtype category disjoint from numeric, and arithmetic dunders reject non-numeric operands — there is no implicit bool→int promotion the way numpy does it. So the numpy idiom of multiplying by a boolean mask to zero out values is not portable.

Suggested fix: use xp.where(mask, xp.asarray(0.0, dtype=data.dtype, device=...), data), or cast explicitly with xp.astype(~mask, data.dtype) before multiplying.

Note this does not overlap the _arithmetic_wrapper row of the #941 table (possibly related to #927) — this is a direct escape via the plain * operator inside create_deviation and dedupes separately.

Part of the array-API triage in #941; found with the array-api-strict tooling from #937/#939. Verified at branch tip d329ac5 (2026-08-01).

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions