Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@skoudoro
Copy link
Collaborator

fix #91

This pull request improves the handling and testing of empty TRX files and ensures consistent dtype comparisons in tests.

  • Updated TrxFile.deepcopy to only write positions and offsets files if the TRX is not empty, preventing unnecessary files in empty TRX archives (trx_file_memmap.py).
  • Modified _create_trx_from_pointer to immediately return an empty TrxFile if the header indicates zero streamlines and vertices, avoiding attempts to load non-existent data (trx_file_memmap.py).

This case has been encounter with Recobundles. Sometimes, the specific bundle is not in the tractogram so it should save an empty TRX instead of crashing.

Please, take a careful look @arokem and @frheault , I might miss something.

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 75.92593% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.06%. Comparing base (384d3c7) to head (fdc7ce0).

Files with missing lines Patch % Lines
trx/tests/test_cli.py 7.69% 12 Missing ⚠️
trx/trx_file_memmap.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #99      +/-   ##
==========================================
+ Coverage   59.76%   60.06%   +0.29%     
==========================================
  Files          12       12              
  Lines        2411     2454      +43     
==========================================
+ Hits         1441     1474      +33     
- Misses        970      980      +10     
Flag Coverage Δ
unittests 60.06% <75.92%> (+0.29%) ⬆️

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.

normalized[key] = _normalize_dtype_dict(value)
elif isinstance(value, np.dtype):
# Normalize to little-endian for multi-byte types
if value.byteorder == "=" and value.itemsize > 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure that I understand this. If we are on a big endian system, couldn't this still be set to "=" (native)? And this would change it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The goal here is to make sure we are in little endian whatever the machine (big endian system or little endian system).

for now, we do not want to stay in native.

If we are on a big endian system, couldn't this still be set to "=" (native)?

yes, but internally, we switch it to little endian

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha, looks good to me! I wonder if @frheault could give it another look, to make sure that I have not missed anything.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems good, I tested using some tracking scripts with 0 seeds and it now works great for saving empty tractogram (lazy saving too) and loading it.

trx.header = header

# Handle empty TRX files early - no positions/offsets to load
if header["NB_STREAMLINES"] == 0 and header["NB_VERTICES"] == 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be a or ? Since streamlines with 0 or 1 points are invalid anyway, maybe this could catch some corner case and force empty TRX?

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.

trx fails when saving empty trx files.

3 participants