Array API: units/Quantity handling with non-numpy arrays
- Dominant language
- Python
- Stars
- 93
- Forks
- 92
- Avg merge
- 14h 44m
- Merged PRs (30d)
- 30
Description
### 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:
https://github.com/astropy/ccdproc/blob/9d25eeefda8a38fc442c1a18e79ca2fa8ca40559/ccdproc/core.py#L991
- #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:
https://github.com/astropy/ccdproc/blob/9d25eeefda8a38fc442c1a18e79ca2fa8ca40559/ccdproc/core.py#L1016
### 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.
Contributor guide
Research direction
Start in ccdproc/core.py at flat_correct and _CCDDataWrapperForArrayAPI, then inspect the combiner scaling paths and other Quantity constructions from image data. Run the scaling-related combiner tests associated with #911 and check behavior with non-numpy arrays. Done means the same units-beside-data strategy covers these paths without coercing the user's array library.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100