Skip to content

Preserve complex values in nonsparse EPOCH16 writes - #347

Merged
bryan-harter merged 2 commits into
lasp:mainfrom
vera-rubin:fix/epoch16-records
Nov 13, 2026
Merged

bryan-harter merged 2 commits into
lasp:mainfrom
vera-rubin:fix/epoch16-records

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

When we write one CDF_EPOCH16 timestamp to a nonsparse variable, it becomes two records with zero picoseconds. For complex(63871286400, 123456789012), we get [63871286400+0j, 123456789012+0j] and Last_Rec=1, instead of one complex value and Last_Rec=0, as the documented representation requires.

from cdflib import CDF, cdfwrite

with cdfwrite.CDF("epoch16.cdf") as writer:
    writer.write_var(
        {"Variable": "Epoch", "Data_Type": writer.CDF_EPOCH16,
         "Num_Elements": 1, "Rec_Vary": True, "Dim_Sizes": []},
        var_data=[complex(63871286400, 123456789012)],
    )
with CDF("epoch16.cdf") as reader:
    print(reader.varget("Epoch"), reader.varinq("Epoch").Last_Rec)

We now pass EPOCH16 values directly to the shared converter, as sparse writes already do, preserving both components and the record count.

We added a regression test and ran the existing reader/writer tests.

— ChipLab

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Removing EPOCH16 conversion validation allows invalid timestamp strings to be silently written as raw-text records instead of raising ValueError.

1 open issue
What changed in this PR

This PR fixes nonsparse CDF_EPOCH16 writes so each complex timestamp preserves its seconds and picoseconds components as one record.

Changes:

  • Pass EPOCH16 values directly to the shared converter instead of splitting their components.
  • Add round-trip tests for scalar, list, and NumPy inputs, checking values and record counts with compression enabled and disabled.
File Description
tests/​test_cdfwrite.py Adds parameterized EPOCH16 round-trip regression tests.
cdflib/​cdfwrite.py Removes component splitting before nonsparse data conversion.

Review effort: Max

Comment thread cdflib/cdfwrite.py Resolved
Add validation for EPOCH16 data type to ensure input can be cast to complex128.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@bryan-harter
bryan-harter merged commit 87f2980 into lasp:main Nov 13, 2026
12 of 13 checks passed
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.

3 participants