Skip to content

Bug fix: Loader.__len__ returns wrong length#144

Merged
ilan-gold merged 4 commits intomainfrom
fix/len-loader
Feb 11, 2026
Merged

Bug fix: Loader.__len__ returns wrong length#144
ilan-gold merged 4 commits intomainfrom
fix/len-loader

Conversation

@felix0097
Copy link
Copy Markdown
Collaborator

In the current implementation Loader.__len__ returns n_obs instead to the number of batches. This PR should fix this

@felix0097 felix0097 requested a review from ilan-gold February 10, 2026 15:06
@felix0097 felix0097 self-assigned this Feb 10, 2026
@felix0097 felix0097 added the bug Something isn't working label Feb 10, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.19%. Comparing base (0628019) to head (a23b021).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
- Coverage   93.19%   91.19%   -2.01%     
==========================================
  Files          10       10              
  Lines         823      829       +6     
==========================================
- Hits          767      756      -11     
- Misses         56       73      +17     
Files with missing lines Coverage Δ
src/annbatch/abc/sampler.py 100.00% <100.00%> (ø)
src/annbatch/loader.py 89.26% <100.00%> (-3.03%) ⬇️
src/annbatch/samplers/_chunk_sampler.py 93.75% <100.00%> (+0.27%) ⬆️

... and 2 files with indirect coverage changes

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

Copy link
Copy Markdown
Collaborator

@ilan-gold ilan-gold left a comment

Choose a reason for hiding this comment

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

Can we add a test for this now? I would think one of the old torch tests were broken silently?

@felix0097 felix0097 requested a review from ilan-gold February 10, 2026 15:31
Comment thread tests/test_dataset.py
)
loader.add_dataset(**data)

expected_len = n_obs // batch_size if drop_last else math.ceil(n_obs / batch_size)
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.

Put this as a parametrized number explicitly. Also not sure why we're parametrizing on chunk size or number of chunks to preload. Can you remove? Seems unrelated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's supposed to also check the n_iters function of the ChunkSampler. This covers different edge cases. I can remove it, if we only wanna check the n_iters.

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.

But https://github.com/scverse/annbatch/pull/144/changes#diff-102eacca529505a20b2ae79d187762c2125e058343b16a2452f981a82f7c17bcR100-R103 doesn't use those parameters - it's just batch_size and n_obs dependent along with the mask - so maybe parametrize by mask start/end?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ok, so this rathe tests if the ChunkSampler handles this correctly. Thinking about this, this isn't really the point of this test. I've removed it now 👍

@felix0097 felix0097 added the skip-gpu-ci Whether gpu ci should be skipped label Feb 10, 2026
@felix0097 felix0097 requested a review from ilan-gold February 10, 2026 17:49
@ilan-gold ilan-gold merged commit dd6e16c into main Feb 11, 2026
11 checks passed
@ilan-gold ilan-gold deleted the fix/len-loader branch February 11, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working skip-gpu-ci Whether gpu ci should be skipped

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants