Skip to content

fix: prevent crashes on zero-length dimensions in echodata conversion - #1624

Merged
LOCEANlloydizard merged 3 commits into
echostack-org:mainfrom
OceanStreamIO:oceanstream/fix-zero-length-dims
Aug 16, 2026
Merged

fix: prevent crashes on zero-length dimensions in echodata conversion#1624
LOCEANlloydizard merged 3 commits into
echostack-org:mainfrom
OceanStreamIO:oceanstream/fix-zero-length-dims

Conversation

@beatfactor

Copy link
Copy Markdown
Contributor

Partial/truncated raw files can produce channels with zero pings, causing:

  • Division by zero in set_zarr_encodings() chunk calculation
  • ValueError in _nan_timestamp_handler() on empty ping_time arrays
  • Encoding failure on all-NaN time variables

Changes:

  • utils/coding.py: Skip all-NaN time vars in set_time_encodings(); handle zero-length and scalar dims in set_zarr_encodings()
  • convert/set_groups_base.py: Return [np.nan] cleanly when ping_time arrays are empty in _nan_timestamp_handler()

Partial/truncated raw files (e.g. from autonomous vehicle deployments)
can produce channels with zero pings, causing:
- Division by zero in set_zarr_encodings() chunk calculation
- ValueError in _nan_timestamp_handler() on empty ping_time arrays
- Encoding failure on all-NaN time variables

Changes:
- utils/coding.py: Skip all-NaN time vars in set_time_encodings();
  handle zero-length and scalar dims in set_zarr_encodings()
- convert/set_groups_base.py: Return [np.nan] cleanly when ping_time
  arrays are empty in _nan_timestamp_handler()
@codecov-commenter

codecov-commenter commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.53%. Comparing base (a7c2a62) to head (b0fd72c).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
echopype/utils/coding.py 60.00% 8 Missing ⚠️
echopype/convert/set_groups_base.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1624      +/-   ##
==========================================
+ Coverage   84.90%   85.53%   +0.62%     
==========================================
  Files          79       79              
  Lines        6998     7010      +12     
==========================================
+ Hits         5942     5996      +54     
+ Misses       1056     1014      -42     
Flag Coverage Δ
unittests 85.53% <64.28%> (+0.62%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@LOCEANlloydizard

Copy link
Copy Markdown
Collaborator

Hi @beatfactor, sorry for the delay... I can review this PR and #1635 this week, if that works for you? If so, could you also take a look at the pre-commit failures and resolve the merge conflicts? I'd be happy to help, but I can't push to those PRs... cheers!

@beatfactor

Copy link
Copy Markdown
Contributor Author

Sure, I'll take a look over the next few days.

@LOCEANlloydizard

Copy link
Copy Markdown
Collaborator

Hi @beatfactor, i'm adding this for the next release, due at the end of the month! cheers!

@LOCEANlloydizard LOCEANlloydizard moved this from Todo to In Progress in Echopype 2026 Aug 8, 2026
…ro-length-dims

Resolved conflict in echopype/convert/set_groups_base.py:
 - kept the upstream SONAR_MODELS/model_family lookup, and
 - preserved the empty-ping-times guard so partial/truncated raw files
   still return [np.nan] instead of crashing in np.array(...).min().
@LOCEANlloydizard LOCEANlloydizard moved this from In Progress to In Review in Echopype 2026 Aug 14, 2026
@LOCEANlloydizard
LOCEANlloydizard self-requested a review August 14, 2026 05:39

@LOCEANlloydizard LOCEANlloydizard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @beatfactor looks good to me! Could we/should we just add a few regression tests covering the zero-length/all-NaN cases fixed here? I would do it myself, but I can’t push directly to the PR.. (maybe we could enable the “Allow edits from maintainers” option if not?) cheers!

…ck-org#1624)

- test_coding.py: cover set_time_encodings skipping all-NaN time vars, and
  set_zarr_encodings on zero-length dims + scalar variables.
- test_set_groups_common.py: cover _nan_timestamp_handler for empty ping_time
  dicts, all-empty channel arrays, populated ping_time, and passthrough.

@LOCEANlloydizard LOCEANlloydizard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thx @beatfactor for this and for adding the tests too! i'll merge this now, thx!

@LOCEANlloydizard
LOCEANlloydizard merged commit ec1b82a into echostack-org:main Aug 16, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Echopype 2026 Aug 16, 2026
@beatfactor
beatfactor deleted the oceanstream/fix-zero-length-dims branch August 17, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants