New error in uvfits writer with astropy 8.0.3

Open Beginner friendly
#1,751 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
numpy, python
Domain
data

Research direction

The traceback points to src/pyuvdata/uvdata/uvfits.py:1200, where fits.GroupData is built; start there and trace the column names with trailing spaces to their definitions. Compare them with the numpy recarray names after astropy strips whitespace (failing key 'UU '). Read write_uvfits and run the uvfits write/round-trip tests under astropy 8.0.3. Done means the KeyError is gone, tests pass, and you note whether to strip whitespace locally or report upstream.

Written by the indexing model from the issue text.

Description

bug

A change in astropy 8.0.3 (related PR: https://github.com/astropy/astropy/pull/20514) is causing a new error in our uvfits reader.

I am not sure if this is more a case of exposing an issue we had vs their change being a bug. The error is triggered because we have been carrying the field names with extra white space to match what is actually written in a uvfits file. Internally, astropy converts to a numpy rec array which strips the white space. But the new code that was introduced in the PR noted above breaks because the numpy rec array field names do not match the parameter names passed to the group constructor.

I can confirm that removing the whitespace in our code prevents the error, not sure if I should report this to astropy or not -- kind of depends if we think this is an error on our side vs theirs.

src/pyuvdata/uvdata/uvdata.py:11318: in write_uvfits
    uvfits_obj.write_uvfits(filename, **kwargs)
src/pyuvdata/uvdata/uvfits.py:1200: in write_uvfits
    hdu = fits.GroupData(
../../../miniforge3/envs/rasg/lib/python3.14/site-packages/astropy/io/fits/hdu/groups.py:219: in __new__
    coldefs._arrays[idx] = self.field(idx)
                           ^^^^^^^^^^^^^^^
../../../miniforge3/envs/rasg/lib/python3.14/site-packages/astropy/io/fits/fitsrec.py:769: in field
    field = _get_recarray_field(base, name)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../miniforge3/envs/rasg/lib/python3.14/site-packages/astropy/io/fits/fitsrec.py:1519: in _get_recarray_field
    field = np.recarray.field(array, key)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = rec.array([( 0.00000000e+00,  0.00000000e+00,  0.00000000e+00, 0.75333333,  257., 1., 1., 1., 1., 2.00071335, 0.065323...8'), ('ANTENNA2', '<f8'), ('SUBARRAY', '<f8'), ('INTTIM', '<f8'), ('LST', '<f8'), ('DATA', '<f8', (1, 1, 1, 3, 2, 3))])
attr = 'UU      ', val = None

    def field(self, attr, val=None):
        if isinstance(attr, int):
            names = ndarray.__getattribute__(self, 'dtype').names
            attr = names[attr]
    
        fielddict = ndarray.__getattribute__(self, 'dtype').fields
    
>       res = fielddict[attr][:2]
              ^^^^^^^^^^^^^^^
E       KeyError: 'UU      '

../../../miniforge3/envs/rasg/lib/python3.14/site-packages/numpy/_core/records.py:545: KeyError
Dominant language
Python
Stars
103
Forks
40
Avg merge
4d 11h
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RadioAstronomySoftwareGroup/pyuvdata

All issues in RadioAstronomySoftwareGroup/pyuvdata

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.