Skip to content

test(preprocessing): mark the inf-mask timing guards as slow - #1337

Merged
adrian-prior merged 3 commits into
PriorLabs:mainfrom
aniruddhaadak80:fix/inf-mask-timing-test-slow
Oct 1, 2026
Merged

adrian-prior merged 3 commits into
PriorLabs:mainfrom
aniruddhaadak80:fix/inf-mask-timing-test-slow

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Issue

Fixes #1336

Motivation and Context

tests/test_preprocessing/test_inf_handling.py has two performance guards that assert a wall-clock ratio against the other code path:

# test__inf_mask__per_block_path_not_slower_than_pandas_on_fragmented
numpy_median = _median_runtime(lambda: _numpy_split_inf_masks(X))
pandas_median = _median_runtime(lambda: _inf_masks_pandas_only(X))

# ~1.5x faster locally; allow 25% slack so only a genuine regression fails.
assert numpy_median < pandas_median * 1.25, (...)

and its sibling test__inf_mask__pandas_path_not_slower_than_per_block_on_single_block, which asserts the same kind of ratio in the other direction.

Two problems:

  1. The slow marker the docstring claims is not there. The first guard's docstring says it is "marked slow to run at merge time", but the only decorator on it is @pytest.mark.skipif(PANDAS_BELOW_3, ...). There is no @pytest.mark.slow, so pytest -m "not slow" in the PR matrix (.github/workflows/ci.yml) does not deselect it. The sibling has no marker and no such claim. The net effect is that two wall-clock assertions run in every pull request job.

  2. The 1.25x budget does not survive shared-runner noise. The comparison is a ratio of two statistics.median values over 11 wall-clock runs of ~7-9ms of work. A busy shared runner is enough to invert it.

Observed failure

From the Test Package Compatibility (macos-15, 3.14, highest) job on a PR that does not touch clean.py or the inf-mask paths at all:

tests/test_preprocessing/test_inf_handling.py::test__inf_mask__per_block_path_not_slower_than_pandas_on_fragmented FAILED [ 54%]

E       AssertionError: per-block inf-mask path regressed: 8.79ms vs pandas 6.94ms

8.79 / 6.94 = 1.27x, just over the 1.25x budget. The same commit passes the other matrix legs, so the failure is a property of the runner rather than of the code. That makes unrelated PRs red and trains reviewers to discount the signal.

What this changes

This adds the marker the docstring already describes, and applies it to the sibling guard which has the same shape. Both now run only in the merge-time matrix, which is what the docstring intends and what a timing assertion is good for.

The deterministic checks are deliberately untouched and still run in every PR. Each guard asserts the two paths agree element-for-element before timing them:

np.testing.assert_array_equal(
    np.stack(_numpy_split_inf_masks(X)), np.stack(_inf_masks_pandas_only(X))
)

That assertion is the one that actually catches a regression in this code, and it is not wall-clock dependent, so it keeps its place in the PR gate.


Public API Changes

  • No Public API changes
  • Yes, Public API changes (Details below)

How Has This Been Tested?

Both directions of the marker were verified with pytest --collect-only, so the evidence is about test selection rather than about wall-clock numbers, which are not reproducible on an arbitrary machine.

Before the change, the guard is collected when the PR matrix does not filter it, confirming it is a PR-gate test today:

$ pytest tests/test_preprocessing/test_inf_handling.py -k per_block_path_not_slower --collect-only -q
1/52 tests collected (51 deselected)

With the first marker added, it is deselected as intended:

$ pytest -m "not slow" tests/test_preprocessing/test_inf_handling.py --collect-only -q
51/52 tests collected (1 deselected)

With both markers added, the two timing guards are deselected and every other test in the file still runs:

$ pytest -m "not slow" tests/test_preprocessing/test_inf_handling.py --collect-only -q
50/52 tests collected (2 deselected)

Lint and format, both clean:

$ ruff check tests/test_preprocessing/test_inf_handling.py
All checks passed!

$ ruff format --check tests/test_preprocessing/test_inf_handling.py
1 file already formatted

No changelog fragment is included: a maintainer applied the "no changelog needed" label, which the repo README lists as the right call for test refactoring that is not a bug fix. That label only takes effect once the fragment is gone, because action-towncrier-changelog fails when both are present.


Checklist

  • The changes have been tested locally.
  • Documentation has been updated (if the public API or usage changes).
  • A changelog entry has been added (see changelog/README.md), or "no changelog needed" label requested.
  • The code follows the project's style guidelines.
  • I have considered the impact of these changes on the public API.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 09:26

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions
github-actions Bot requested a review from adrian-prior October 1, 2026 09:27

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9ab9f63. Configure here.

Comment thread changelog/1336.changed.md Outdated
Both inf-mask performance guards in this file assert a wall-clock ratio
against the other path, but neither carried a `slow` marker, so
`pytest -m "not slow"` in the PR matrix did not deselect them and two
wall-clock assertions ran in every pull request job.

On the macos-15 / 3.14 / highest runner the fragmented-frame guard measured
8.79ms against a 6.94ms pandas baseline and failed its 1.25x budget, turning
a PR that does not touch `clean.py` or the inf-mask paths red. The failure is
a property of the runner, not of the code, so it makes unrelated PRs fail and
trains reviewers to discount the signal.

The docstring of the first guard already states it is "marked `slow` to run at
merge time", so this adds the marker that was intended, and applies it to the
sibling single-block guard which has the same shape. Both now run only in the
merge-time matrix.

The deterministic checks are untouched and still run in every PR: each guard
first asserts the two paths agree element-for-element before timing them, and
that assertion is the one that actually catches a regression in this code.
@aniruddhaadak80
aniruddhaadak80 force-pushed the fix/inf-mask-timing-test-slow branch from 9ab9f63 to 58ec47f Compare October 1, 2026 09:40
@aniruddhaadak80 aniruddhaadak80 changed the title test(preprocessing): mark the fragmented inf-mask timing guard as slow test(preprocessing): mark the inf-mask timing guards as slow Oct 1, 2026
@adrian-prior adrian-prior added the no changelog needed PR does not require a changelog entry label Oct 1, 2026

@adrian-prior adrian-prior left a comment

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.

Thanks for setting this up! Can you remove the changelog, then I am happy to approve the PR!

aniruddhaadak80 and others added 2 commits October 1, 2026 15:34
… `slow`

marker their docstring already described, so their wall-clock assertions run
in the merge-time matrix rather than in every pull request job.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… the failure

The scientific-python/action-towncrier-changelog check exits 1 when a
skip label is present AND a changelog file exists in the PR. So the
fragment added in 58ec47f is what keeps the "Changelog entry" check red,
not the absence of one.

The repo README lists test refactoring as a case where the label is the
right answer, and a maintainer has since applied it to this PR. Leaving
the fragment in place guarantees a permanently red check; removing it
lets the label do its job.
@adrian-prior
adrian-prior added this pull request to the merge queue Oct 1, 2026
Merged via the queue into PriorLabs:main with commit d07a55c Oct 1, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog needed PR does not require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wall-clock timing assertion in test_inf_handling.py runs on every PR and intermittently turns unrelated PRs red

3 participants