Skip to content

fix(binaryfile): prefer exact text/paknam2 matches in CellBudgetFile - #2891

Open
wpbonelli wants to merge 1 commit into
modflowpy:developfrom
wpbonelli:fix-cbc-exact-text-match
Open

wpbonelli wants to merge 1 commit into
modflowpy:developfrom
wpbonelli:fix-cbc-exact-text-match

Conversation

@wpbonelli

Copy link
Copy Markdown
Member

CellBudgetFile methods currently match text and paknam/paknam2 arguments as substrings and unconditionally take the first match. This means e.g. text="RCH" could return an RCHA package if it appeared in the file first. Likewise paknam2="rch_1" could return a package named "RCH_10". This is true of the following methods:

  • get_data()
  • get_indices()
  • get_ts()
  • export()

While this is fairly long-standing and could now be considered expected behavior, I think it's best called a bug, since

  • it's surprising for a substring match to take precedence over an exact match, just because of the order of appearance in the output file
  • it broke scripts back when layer-array packages were introduced

I think it is more correct to prefer exact (case- and whitespace-insensitive) matches, falling back to the substring match if there is no exact match. This means abbreviations continue to work.

This has the following consequences.

  • When a text/paknam query exactly matches a record name, that record is now selected even if another name containing the query appears earlier in the file. For example, text="rch" in a model with both RCHA and RCH packages previously returned the RCHA record; it now returns the RCH record(s).
  • export(text=...) will export only the exactly matching record when one exists, rather than every record whose name contains the query. Queries with no exact match keep the previous substring behavior.

…File

CellBudgetFile matched the text and paknam/paknam2 arguments as
substrings and took the first name in the file containing them. With
MF6, text="RCH" could therefore resolve to RCHA (array-based recharge)
or UZF-GWRCH if either appeared in the file first, silently dropping
the list-based RCH records. Likewise paknam2="rch_1" could resolve to
RCH_10.

Prefer an exact (case- and whitespace-insensitive) match, falling back
to the previous substring matching if there is none, so abbreviations
like "spdis" still work. Apply the same rule in export().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wpbonelli wpbonelli added this to the 3.12.1 milestone Nov 16, 2026
@wpbonelli wpbonelli added the bug label Nov 16, 2026
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.0%. Comparing base (556c088) to head (4807f8e).
⚠️ Report is 264 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2891      +/-   ##
===========================================
+ Coverage     55.5%    72.0%   +16.5%     
===========================================
  Files          644      659      +15     
  Lines       124135   132494    +8359     
===========================================
+ Hits         68947    95500   +26553     
+ Misses       55188    36994   -18194     
Files with missing lines Coverage Δ
flopy/utils/binaryfile/__init__.py 74.7% <100.0%> (-9.8%) ⬇️

... and 584 files with indirect coverage changes

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

@wpbonelli
wpbonelli marked this pull request as ready for review November 16, 2026 21:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant