Skip to content

fix(binaryfile): skip non-matching records when indexing layer files - #2892

Open
wpbonelli wants to merge 1 commit into
modflowpy:developfrom
wpbonelli:fix-layerfile-mixed-text
Open

wpbonelli wants to merge 1 commit into
modflowpy:developfrom
wpbonelli:fix-layerfile-mixed-text

Conversation

@wpbonelli

Copy link
Copy Markdown
Member

HeadFile, UcnFile and HeadUFile read one record type from a binary file, selected by the text argument (e.g. "head"). But when indexing a file, they don't skip records with any other text, they read the record's header but not its data, then try to read the next header from the start of that unread data. Files with more than one record type therefore fail to load (EOFError, or a pandas length mismatch). MF2005, for example, allows more than one record type in a file, e.g. when heads and drawdown are saved to the same file unit.

Fixes:

  • skip the data of non-matching records, and index only headers whose text matches
  • raise ValueError when no record matches the requested text

Files containing a single record type are indexed exactly as before.

BinaryLayerFile._build_index appended every header to recordarray but,
for records whose text did not match (e.g. DRAWDOWN records in a file
read as HEAD), skipped neither the data nor the iposarray entry. The
next header was then read from the middle of the data block, so files
mixing record types (as MODFLOW-2005 output control allows when heads
and drawdown share a unit) failed to load or were indexed incorrectly.

Skip non-matching records' data, index only matching headers, and raise
a clear error when no record matches the requested text.

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 (cb5e3a0).
⚠️ Report is 265 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2892      +/-   ##
===========================================
+ Coverage     55.5%    72.0%   +16.5%     
===========================================
  Files          644      659      +15     
  Lines       124135   132506    +8371     
===========================================
+ Hits         68947    95507   +26560     
+ Misses       55188    36999   -18189     
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 22:23

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