Skip to content

Array API: dead code in cosmicray_median clobbers masked-input handling #932

Description

@mwcraig

Problem

In the array branch of cosmicray_median, the masked-input handling is dead code — data = ccd.data is immediately overwritten by the unconditional data = xp.asarray(ccd) on the next statement:

ccdproc/ccdproc/core.py

Lines 2030 to 2045 in 9d25eee

# Only look at the data array, guessing that if there is a .mask then
# there is also a .data.
if hasattr(ccd, "mask"):
data = ccd.data
data = xp.asarray(ccd)
if error_image is None:
error_image = xp.std(data)
elif not isinstance(error_image, float):
if not _is_array(error_image):
raise TypeError("error_image is not a float or ndarray.")
# create the median image
marr = ndimage.median_filter(data, size=(mbox, mbox))

So a masked array passed in is not handled the way the comment describes, and what xp.asarray does with an np.ma.MaskedArray (silently dropping the mask) is backend-dependent.

Notes


Found during a review of the array API implementation from #885; follow-up to #909 / #912.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions