Skip to content

combine() does not normalise a raw module passed as array_package #982

Description

@mwcraig

In combine() (ccdproc/combiner.py:1055-1059) the requested array package is handled with

if array_package is not None:
    try:
        xp = array_api_compat.array_namespace(array_package)
    except TypeError:
        xp = array_package

array_api_compat.array_namespace() takes arrays, not modules, so for a module it always raises TypeError (module is not a supported array type — verified for numpy and dask.array) and the fallback hands the raw module through unchanged. The intent was clearly to normalise to the array-api-compat namespace; as written the normalisation never happens.

A raw module then reaches code that uses array-API-only features (xp.bool, the device= keyword in xp.asarray/xp.zeros, xp.astype, ...) and fails, e.g. combine(files, array_package=dask.array) dies with TypeError: from_array() got an unexpected keyword argument 'device' (on main before #976 it died one call later in clip_extrema with module 'dask.array' has no attribute 'argsort').

PR #976 fixed the same problem in Combiner.__init__ by normalising with

xp = array_api_compat.array_namespace(xp.asarray(0))

combine() should do the same so the two entry points agree on what array_package / xp may be, and the array_package docstring should say a plain module is accepted and converted.

Regression test: combine([...numpy CCDData...], array_package=np) and, ideally, array_package=dask.array on a FITS-file input so the CCDData.read branch that converts data/mask/uncertainty into xp is exercised.

Follow-up from the review of #976.

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