Skip to content

Array API: units/Quantity handling with non-numpy arrays #936

Description

@mwcraig

Problem

astropy.units.Quantity is numpy-backed, so any path that attaches units to image data pulls the data out of the user's array library.

Evidence:

  • The workaround in flat_correct, which strips and re-applies units manually to avoid Quantity:

    # TODO: Fix this when astropy supports array namespaces

  • CuPy issues in test_combiner #911 failures of the form TypeError: unsupported operand type(s) for <<: 'ndarray' and 'IrreducibleUnit' in scaling-related combiner tests — a CuPy array being shifted into a Quantity.

  • The related TODO about CCDData arithmetic being numpy-based:

    # TODO: Workaround for the fact that CCDData currently uses numpy

Task

Define one strategy for units with non-numpy data — the current wrapper approach (_CCDDataWrapperForArrayAPI keeps units beside the data rather than wrapping it) seems right, but it needs to cover the combiner scaling paths too. Audit every place a Quantity is constructed from image data and route it through the same mechanism. Track astropy's own array-API plans for units in #940.


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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions