Skip to content

BUG: io.fits: improve error for FITS tables with more than 999 columns#19545

Open
FazeelUsmani wants to merge 3 commits into
astropy:mainfrom
FazeelUsmani:19236-fits-too-many-cols-error
Open

BUG: io.fits: improve error for FITS tables with more than 999 columns#19545
FazeelUsmani wants to merge 3 commits into
astropy:mainfrom
FazeelUsmani:19236-fits-too-many-cols-error

Conversation

@FazeelUsmani
Copy link
Copy Markdown
Contributor

Fixes #19236.

Description

This PR improves the error raised for FITS tables with more than 999 columns.

Previously, this surfaced late as a cryptic VerifyError during write. This change adds ColDefs._validate_column_count, called at the end of ColDefs.__init__ and before mutation in ColDefs.add_col, so the failure happens earlier with a clear ValueError.

Because the check lives in ColDefs, it applies across the main construction paths, including Table.write(format="fits"), BinTableHDU.from_columns, direct ColDefs(...), coldefs + col, and ColDefs.add_col. The add_col path validates before mutation, so a failed addition leaves the original ColDefs unchanged.

Tests

  • added regression coverage for Table.write(format="fits")
  • added lower-level tests for BinTableHDU.from_columns, direct ColDefs(...), coldefs + col, and ColDefs.add_col
  • verified that 999 columns still succeeds
  • verified that 1000 columns fails before any file is written

…olumns

FITS tables cap at 999 columns by the FITS standard: indexed per-column
keywords like TTYPEn / TFORMn must fit within the 8-character keyword
limit, so n is restricted to 1-3 digits. Previously this surfaced as a
cryptic late-stage VerifyError on the TFIELDS card at write time.

The check now lives in ColDefs._validate_column_count, called at the end
of ColDefs.__init__ and before any mutation in ColDefs.add_col, so the
failure fires at column-definition time across every construction path:
Table.write(format='fits'), BinTableHDU.from_columns, raw ColDefs,
coldefs + col, and add_col. The pre-mutation guard in add_col leaves
the ColDefs untouched on failure rather than half-mutated.

Fixes astropy#19236.
@FazeelUsmani FazeelUsmani requested a review from saimn as a code owner April 9, 2026 09:09
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@FazeelUsmani FazeelUsmani marked this pull request as draft April 9, 2026 09:10
@FazeelUsmani FazeelUsmani marked this pull request as ready for review April 9, 2026 09:34
@pllim pllim added this to the v8.1.0 milestone Apr 30, 2026
@pllim pllim added the Bug label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error message for FITS table with too many columns

2 participants