Skip to content

[1/5] Tests: characterize flatten_fragments before the memory refactor - #434

Open
GeorgWa wants to merge 1 commit into
mainfrom
test/flatten-fragments-characterization
Open

[1/5] Tests: characterize flatten_fragments before the memory refactor#434
GeorgWa wants to merge 1 commit into
mainfrom
test/flatten-fragments-characterization

Conversation

@GeorgWa

@GeorgWa GeorgWa commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Tests only. No production change.

flatten_fragments had no unit test. Add black-box tests that pin its contract, so the refactoring that follows can be checked step by step.

All tests pass unchanged on main.

First of 5 stacked PRs splitting #429.

🤖 Generated with Claude Code

flatten_fragments had no unit test. Add black-box tests that pin its contract, so
the refactoring that follows can be checked step by step.

`_dense_library` builds dense frames with mz == 0 padding from both sources that
produce it: unmodified precursors carry no modloss fragments, and some fragments
fall outside the mz range. Intensities are distinct, so the top-k selection is
unambiguous.

`_expected_keep_mask` derives the expected mask per precursor, without
flatten_fragments. The tests cover the kept fragments over five combinations of
`keep_top_k_fragments` and `min_fragment_intensity`, every annotation column, the
reannotated precursor pointers, `custom_df` and `custom_columns`, the path
without intensities, an empty library, and a precursor long enough to need more
than a uint8 fragment number.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@GeorgWa GeorgWa changed the title Tests: characterize flatten_fragments before the memory refactor [1/5] Tests: characterize flatten_fragments before the memory refactor Aug 31, 2026
@pytest.mark.requires_numba
def test_flatten_fragments_long_precursor():
"""A long precursor keeps fragment numbers above 255, and the columns stay uint32."""
n_rows = 260 # close to the max_frag_per_peptide limit of _fill_in_indices

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

brittle?

def _expected_keep_mask(
precursor_df, mz_df, intensity_df, keep_top_k_fragments, min_fragment_intensity
):
"""Give the keep mask over all dense slots. This does not use flatten_fragments."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we add a test for this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seriously, could we not work with statically define input data (and data to assert against)?

such minimal data models would also help understand/debug the code better one day

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.

@mschwoer do you mean we SHOULD work with static examples or we should keep this logic?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should "strongly consider"™️ it :-D

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.

2 participants