Skip to content

TST: Speed up hypothesis and slow tests #62028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,19 @@ def pytest_collection_modifyitems(items, config) -> None:
ignore_doctest_warning(item, path, message)


hypothesis_health_checks = [
hypothesis.HealthCheck.too_slow,
hypothesis.HealthCheck.differing_executors,
]

# Hypothesis
# Similar to "ci" config in
# https://hypothesis.readthedocs.io/en/latest/reference/api.html#built-in-profiles
hypothesis.settings.register_profile(
"ci",
# Hypothesis timing checks are tuned for scalars by default, so we bump
# them from 200ms to 500ms per test case as the global default. If this
# is too short for a specific test, (a) try to make it faster, and (b)
# if it really is slow add `@settings(deadline=...)` with a working value,
# or `deadline=None` to entirely disable timeouts for that test.
# 2022-02-09: Changed deadline from 500 -> None. Deadline leads to
# non-actionable, flaky CI failures (# GH 24641, 44969, 45118, 44969)
"pandas_ci",
database=None,
deadline=None,
suppress_health_check=tuple(hypothesis_health_checks),
max_examples=15,
suppress_health_check=(
hypothesis.HealthCheck.too_slow,
hypothesis.HealthCheck.differing_executors,
),
)
hypothesis.settings.load_profile("ci")
hypothesis.settings.load_profile("pandas_ci")

# Registering these strategies makes them globally available via st.from_type,
# which is use for offsets in tests/tseries/offsets/test_offsets_properties.py
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/frame/test_stack_unstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ def test_unstack_unobserved_keys(self, future_stack):
tm.assert_frame_equal(recons, df)

@pytest.mark.slow
def test_unstack_number_of_levels_larger_than_int32(
def test_unstack_number_of_levels_larger_than_int32_warns(
self, performance_warning, monkeypatch
):
# GH#20601
Expand All @@ -2239,6 +2239,9 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
raise Exception("Don't compute final result.")

def _make_selectors(self) -> None:
pass

with monkeypatch.context() as m:
m.setattr(reshape_lib, "_Unstacker", MockUnstacker)
df = DataFrame(
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ def test_pivot_string_func_vs_func(self, f, f_numpy, data):
tm.assert_frame_equal(result, expected)

@pytest.mark.slow
def test_pivot_number_of_levels_larger_than_int32(
def test_pivot_number_of_levels_larger_than_int32_warns(
self, performance_warning, monkeypatch
):
# GH 20601
Expand All @@ -2155,6 +2155,9 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
raise Exception("Don't compute final result.")

def _make_selectors(self) -> None:
pass

with monkeypatch.context() as m:
m.setattr(reshape_lib, "_Unstacker", MockUnstacker)
df = DataFrame(
Expand Down
Loading