Reshaping lost when accessing FITS_rec by field name
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 74
Description
Please consider the code below and its output. The behaviour of `FITS_rec` does not match the one of `recarray`, which feels like the correct one.
When reshaping `FITS_rec`, of initial shape `(5,)`, the new shape `(5, 1)` is properly reported. However, when accessing a field, it behaves like the reshape never happened.
Maybe a proper fix would be that reshaping a `FITS_rec` should return a `recarray`.
``` python
from os import path
from astropy.io import fits
import numpy as np
with fits.open(path.join(fits.__path__[0], 'tests', 'data', 'stddata.fits')) as hdulist:
# As FITS_rec
data = hdulist[2].data
print(type(data))
print(data.shape)
print(data['PSFFLUX'].shape)
data = data.reshape((5,1))
print(data.shape)
print(data['PSFFLUX'].shape)
# As recarray
data = np.array(hdulist[2].data.copy())
print(type(data))
print(data.shape)
print(data['PSFFLUX'].shape)
data = data.reshape((5,1))
print(data.shape)
print(data['PSFFLUX'].shape)
```
``` python
(5,)
(5, 5)
(5, 1)
(5, 5)
(5,)
(5, 5)
(5, 1)
(5, 1, 5)
```
Contributor guide
Research direction
Start by running the supplied reproduction with astropy.io.fits against stddata.fits, comparing FITS_rec and the NumPy recarray behavior after reshape. Then inspect the FITS_rec reshape and field-access paths; done means field access preserves the reshaped dimensions consistently with recarray.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100