Skip to content

fre.cmor: harden branded-variable disambiguations#832

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/harden-branded-variable-disambiguations
Draft

fre.cmor: harden branded-variable disambiguations#832
Copilot wants to merge 3 commits intomainfrom
copilot/harden-branded-variable-disambiguations

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Describe your changes

Brand extraction used split('_') indexing, which breaks when target_var contains underscores and raises IndexError on non-branded MIP entries. Error messages on disambiguation failure were either empty (bare ValueError) or lacked the context needed to diagnose the problem.

Brand extraction (cmor_mixer.py):

  • Replace mip_var.split('_')[0] / [1] with startswith(target_var + '_') + prefix stripping
  • Guard against empty brand suffix (e.g. trailing _)
  • Bare ValueError → message with target var, dim count, available branded entries

Disambiguation errors (cmor_helpers.py filter_brands()):

  • "All eliminated" and "multiple remain" errors now include has_time_bnds, input_vert_dim, candidate brands, and actionable guidance
  • Add empty-brands-list guard at function entry
  • Log messages include the same contextual properties

Tests (test_cmor_helpers.py):

  • test_filter_brands_empty_brands_list
  • test_filter_brands_all_eliminated_message_contains_properties
  • test_filter_brands_multiple_remain_message_contains_properties

Issue ticket number and link (if applicable)

Checklist before requesting a review

  • I ran my code
  • I tried to make my code readable
  • I tried to comment my code
  • I wrote a new test, if applicable
  • I wrote new instructions/documentation, if applicable
  • I ran pytest and inspected it's output
  • I ran pylint and attempted to implement some of it's feedback
  • No print statements; all user-facing info uses logging module

Copilot AI and others added 2 commits April 3, 2026 05:08
…rors, input guard

- Replace fragile split('_') brand extraction with prefix-based startswith()
  matching in cmor_mixer.py to handle target variables containing underscores
  and prevent IndexError on non-branded MIP table entries
- Add informative ValueError message (was bare ValueError) when no brands
  match dimension count, including the target var, dim count, and available
  branded entries
- Improve filter_brands() error messages to include input data properties
  (has_time_bnds, input_vert_dim), candidate brands, and actionable guidance
  for both 'all eliminated' and 'multiple remain' error paths
- Add input guard in filter_brands() for empty brands list
- Add tests: empty brands list, error message property assertions

Agent-Logs-Url: https://github.com/NOAA-GFDL/fre-cli/sessions/aef8d820-d1d3-4c34-8e54-15da812d8e42

Co-authored-by: ilaflott <6273252+ilaflott@users.noreply.github.com>
Copilot AI changed the title [WIP] Harden branded-variable disambiguations harden branded-variable disambiguations in fre.cmor Apr 3, 2026
Copilot AI requested a review from ilaflott April 3, 2026 05:14
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.12%. Comparing base (7e80492) to head (8f02704).

Files with missing lines Patch % Lines
fre/cmor/cmor_mixer.py 78.57% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #832   +/-   ##
=======================================
  Coverage   84.12%   84.12%           
=======================================
  Files          71       71           
  Lines        4944     4952    +8     
=======================================
+ Hits         4159     4166    +7     
- Misses        785      786    +1     
Flag Coverage Δ
unittests 84.12% <81.25%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
fre/cmor/cmor_helpers.py 93.83% <100.00%> (+0.04%) ⬆️
fre/cmor/cmor_mixer.py 89.78% <78.57%> (-0.08%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e80492...8f02704. Read the comment docs.

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

@ilaflott
Copy link
Copy Markdown
Member

fremorizer is still getting to this, keep for now

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.

fre.cmor: harden branded-variable disambiguations

2 participants