Skip to content

fix(card): Don't write a units field for undefined values - #43

Merged
barrettp merged 1 commit into
JuliaAstro:mainfrom
icweaver:undef
Jul 13, 2026
Merged

fix(card): Don't write a units field for undefined values#43
barrettp merged 1 commit into
JuliaAstro:mainfrom
icweaver:undef

Conversation

@icweaver

Copy link
Copy Markdown
Member

Hi Paul, I ran into this edge case while integrating FITSFiles.jl with AstroImages.jl. Would it make sense to drop the [] that sneaks into the comments section when the field is undefined?

Before

julia> Card("UNDEF", missing, "a comment")
UNDEF   =                      / [] a comment

After

julia> Card("UNDEF", missing, "a comment")
UNDEF   =                      / a comment

This makes handling empty fields easier downstream

@icweaver
icweaver requested a review from barrettp as a code owner July 13, 2026 08:10
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.35%. Comparing base (8b68009) to head (2c31e5b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #43      +/-   ##
==========================================
+ Coverage   46.15%   46.35%   +0.19%     
==========================================
  Files          17       17              
  Lines        2550     2550              
==========================================
+ Hits         1177     1182       +5     
+ Misses       1373     1368       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@barrettp

Copy link
Copy Markdown
Member

Do the brackets occur when reading (or parsing) a Card or when writing (or instantiating) a Card?

If the former, then the brackets are in the original FITS file and will not be modified. A basic requirement of FITSFiles is to maintain the original card format so that the written file is byte-for-byte as close to the read file as possible.

If the latter, then I'll take a look at it. Although that behaviour seems very unusual as I have not yet included support for units.

@icweaver

Copy link
Copy Markdown
Member Author

It looks to be when writing, which then gets picked up again on read:

main

julia> using FITSFiles

julia> data = ones(Int32, (3,3));

julia> cards = [Card("KEY1", 3), Card("KEY2", missing)]
2-element Vector{Card}:
 KEY1    =                    3
 KEY2    =                      / []

julia> hdu = HDU(data, cards)
      Primary                               1       7     Int32   3 × 3

julia> write("output.fits", hdu)
2844

julia> fits("output.fits")[1].cards
7-element Vector{Card{<:Any}}:
 SIMPLE  =                    T
 BITPIX  =                   32
 NAXIS   =                    2
 NAXIS1  =                    3
 NAXIS2  =                    3
 KEY1    =                    3
 KEY2    =                      / []

This PR

julia> using FITSFiles

julia> data = ones(Int32, (3,3));

julia> cards = [Card("KEY1", 3), Card("KEY2", missing)]
2-element Vector{Card}:
 KEY1    =                    3
 KEY2    =

julia> hdu = HDU(data, cards)
      Primary                               1       7     Int32   3 × 3

julia> write("output.fits", hdu)
2844

julia> fits("output.fits")[1].cards
7-element Vector{Card{<:Any}}:
 SIMPLE  =                    T
 BITPIX  =                   32
 NAXIS   =                    2
 NAXIS1  =                    3
 NAXIS2  =                    3
 KEY1    =                    3
 KEY2    =

@barrettp barrettp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The error would probably be found once units are implemented properly.

@barrettp
barrettp merged commit 870e4ee into JuliaAstro:main Jul 13, 2026
5 checks passed
@icweaver
icweaver deleted the undef branch July 14, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants