Skip to content

CDF metadata: alphabetize attribute keys in *_attrs.yaml#3116

Merged
sapols merged 3 commits into
IMAP-Science-Operations-Center:devfrom
sapols:claude/issue-2892
May 5, 2026
Merged

CDF metadata: alphabetize attribute keys in *_attrs.yaml#3116
sapols merged 3 commits into
IMAP-Science-Operations-Center:devfrom
sapols:claude/issue-2892

Conversation

@sapols
Copy link
Copy Markdown
Contributor

@sapols sapols commented Apr 30, 2026

Summary

Closes #2892.

Alphabetizes the nested attribute mappings in imap_processing/cdf/config/*_attrs.yaml across all instruments, so attribute keys (e.g. CATDESC, DEPEND_0, FILLVAL, FORMAT, LABLAXIS, UNITS, VALIDMIN, VALIDMAX, VAR_TYPE, ...) appear in a consistent order. Top-level product/variable ordering is unchanged; only each entry's attribute list is sorted. Some instruments were already alphabetized and were left untouched.

The YAML diff is purely a reorder: 3,298 insertions and 3,298 deletions, perfectly balanced across 49 files. yaml.safe_load of every modified file matches dev, so no values were changed.

A couple of small incidental fixes that came along: missing trailing newlines were added to imap_mag_global_cdf_attrs.yaml and imap_idex_global_cdf_attrs.yaml.

New test

A new regression test, imap_processing/tests/cdf/test_metadata_yaml_order.py, fails if any nested attribute mapping drifts out of alphabetical order.

It lives in its own new file because it's a structural-hygiene check on the YAML files themselves, not a test of ImapCdfAttributes or cdf.utils. Happy to fold it into test_imap_cdf_manager.py if reviewers prefer, but that felt wrong to me.

Out of scope / open question

imap_default_global_cdf_attrs.yaml was left untouched. Its keys (Project, Source_name, Discipline, Mission_group, ...) sit at the top level rather than being nested under a product/variable, and they aren't alphabetical today (likely following ISTP conventional order). Happy to alphabetize that file too if reviewers feel it's in scope for #2892.

Test plan

  • pre-commit run --all-files passes
  • pytest imap_processing/tests/cdf -q passes (14 passed, including the new regression test)
  • Independent audit: 0 unsorted blocks remain across all *_attrs.yaml (recursive walk of nested mappings)
  • Semantic check: 0 yaml.safe_load mismatches vs dev
  • CI green

Sort the nested attribute mappings alphabetically across the CDF metadata
config files in imap_processing/cdf/config/. Top-level product/variable
order is unchanged; only each entry's attribute list is reordered. Adds a
regression test (test_metadata_yaml_order.py) that fails if any nested
attribute mapping drifts out of alphabetical order.

Closes IMAP-Science-Operations-Center#2892
@sapols
Copy link
Copy Markdown
Contributor Author

sapols commented Apr 30, 2026

From Claude:

To pre-empt review concerns about whether anything beyond key reordering changed: I ran a layered byte-level audit comparing every modified file against dev. All 52 *_attrs.yaml files (49 modified + 3 already-sorted) pass:

Check Result
yaml.safe_load equality (canonical-JSON, sorted keys) 0 mismatches
Path-aware leaf comparison — every (key-path, value) pair identical 0 mismatches
Comment preservation (#... lines) 0 mismatches
YAML anchors (&name) preserved 0 mismatches
YAML aliases (*name) preserved 0 mismatches
Multiset-of-lines: every line in old = every line in new 0 mismatches

The last check is the strongest — taking the bag of lines in each file before and after, they're identical sets, just reordered. That means no quoting changed, no indentation changed, no whitespace within any line changed, and no value changed. The diff stat (3,298+ / 3,298−, perfectly balanced) corroborates pure reordering.

Two small non-reorder changes worth flagging:

  • imap_mag_global_cdf_attrs.yaml and imap_idex_global_cdf_attrs.yaml previously had no trailing newline — that's now fixed (POSIX-correct, no semantic effect).
  • One open scope question already in the PR description: imap_default_global_cdf_attrs.yaml (top-level global ISTP attrs, not nested) was left in its existing conventional order. Happy to alphabetize that file too if reviewers feel it's in scope for Metadata: update all yaml key to be in alphebetic order #2892.

Removes the `if not isinstance(doc, MappingNode): continue` outer check.
Every imap_processing/cdf/config/*_attrs.yaml is a top-level mapping, so
this branch was never exercised. Codecov was flagging it as uncovered,
pulling the patch under the 90% target.
@sapols sapols marked this pull request as ready for review April 30, 2026 23:17
@sapols sapols requested a review from tech3371 April 30, 2026 23:18
@sapols
Copy link
Copy Markdown
Contributor Author

sapols commented Apr 30, 2026

@tech3371 does this look good for #2892? Happy with the new test location/excluding imap_default_global_cdf_attrs.yaml?

Copy link
Copy Markdown
Contributor

@tech3371 tech3371 left a comment

Choose a reason for hiding this comment

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

I looked through first 20 files and I didn't see any typo mistakes. That's why I skimmed later files. The alphabetic order work looks great!! Thank you!

Regarding excluding imap_default_global_cdf_attrs.yaml, I am indifferent. Since you added test for checking that everyone follow same convention, I want to say go ahead and update that as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! This is why alphabetic order helps in code tracking. As we can see, it can be hard to trace code at times because everything is in different places!


assert not unsorted_blocks, (
"CDF metadata attribute keys must be in alphabetical order:\n"
+ "\n".join(unsorted_blocks)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for adding this check! This will keep keep this work and convention going forward! I am glad to see you added filename and key that was out of order for user debugging purposes.

- Resolve conflicts in imap_idex_l1a_variable_attrs.yaml: incorporate
  new elsec_evtpkt/elssec_evtpkt variables and shfine UNITS fix from
  dev (IMAP-Science-Operations-Center#3111), with keys alphabetized
- Resolve conflicts in imap_lo_l1a_variable_attrs.yaml: drop DEPEND_1
  from esa_step_coord, azimuth_6, azimuth_60, and spin per dev (IMAP-Science-Operations-Center#3075)
- Alphabetize top-level keys in imap_default_global_cdf_attrs.yaml
- Alphabetize keys in ultra event_id variable (added by auto-merge)
@sapols
Copy link
Copy Markdown
Contributor Author

sapols commented May 5, 2026

Just pushed a commit that alphabetized imap_default_global_cdf_attrs.yaml (and resolved merge conflicts).

Merging now!

@sapols sapols merged commit e814a8e into IMAP-Science-Operations-Center:dev May 5, 2026
14 checks passed
@sapols sapols deleted the claude/issue-2892 branch May 5, 2026 18:21
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.

Metadata: update all yaml key to be in alphebetic order

2 participants