Skip to content

Commit

Permalink
Make fixtures more concise (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Nov 20, 2023
1 parent cb0451a commit 3d28dea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 56 deletions.
20 changes: 19 additions & 1 deletion numbagg/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,31 @@ def numbagg_two_array_setup(func, a, **kwargs):
}


@pytest.fixture(params=["numbagg", "pandas", "bottleneck"], scope="module")
@pytest.fixture(params=["numbagg"], scope="module")
def library(request):
"""By default, limits to numbagg. But can be extended to pandas and bottleneck
```
@pytest.mark.parametrize("library", ["numbagg", "pandas", "bottleneck"], indirect=True)
def test_func():
# ...
```
"""
return request.param


@pytest.fixture(params=COMPARISONS.keys(), scope="module")
def func(request):
"""By default, all functions here. But can be limited in a test:
```
@pytest.mark.parametrize("func", [move_mean], indirect=True)
def test_func():
# ...
```
"""

return request.param


Expand Down
58 changes: 5 additions & 53 deletions numbagg/test/test_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
import numpy as np
import pytest

from .. import (
bfill,
ffill,
move_corr,
move_cov,
move_exp_nancorr,
move_exp_nancount,
move_exp_nancov,
move_exp_nanmean,
move_exp_nanstd,
move_exp_nansum,
move_exp_nanvar,
move_mean,
move_std,
move_sum,
move_var,
nanquantile,
)

from numbagg.moving import move_mean

@pytest.fixture(
params=[
bfill,
ffill,
move_corr,
move_cov,
move_exp_nancorr,
move_exp_nancount,
move_exp_nancov,
move_exp_nanmean,
move_exp_nanstd,
move_exp_nansum,
move_exp_nanvar,
move_mean,
move_std,
move_sum,
move_var,
nanquantile,
],
scope="module",
)
def func(request):
return request.param
from .. import bfill, ffill


@pytest.fixture(
Expand All @@ -60,15 +20,8 @@ def shape(request):
return request.param


# One disadvantage of having this in a fixture is that pytest keeps it around for the
# whole test session. So we at least use module scoping so it will keep a single one for
# all tests.
@pytest.fixture(scope="module")
def array(shape):
array = np.random.RandomState(0).rand(*shape)
return np.where(array > 0.1, array, np.nan)


@pytest.mark.parametrize("func", [move_mean], indirect=True)
@pytest.mark.parametrize("library", ["numbagg", "pandas", "bottleneck"], indirect=True)
def test_benchmark_all(benchmark, func, func_callable, shape):
benchmark.group = f"{func}|{shape}"
benchmark.pedantic(
Expand All @@ -81,8 +34,7 @@ def test_benchmark_all(benchmark, func, func_callable, shape):

@pytest.mark.parametrize("func", [ffill, bfill], indirect=True)
@pytest.mark.parametrize("shape", [(10, 10, 10, 10, 1000)], indirect=True)
@pytest.mark.parametrize("library", ["numbagg"], indirect=True)
def test_benchmark_f_bfill(benchmark, func, func_callable, shape):
def test_benchmark_f_bfill(benchmark, func_callable):
"""
Was seeing some weird results for ffill and bfill — bfill was sometimes much faster
than ffill. We can check this if we see this again.
Expand Down
2 changes: 0 additions & 2 deletions numbagg/test/test_multithreading.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from concurrent.futures import ThreadPoolExecutor

import numpy as np
import pytest


@pytest.mark.parametrize("library", ["numbagg"], indirect=True)
def test_multithreading(func_callable):
# Test whether the functions work in a multithreaded context

Expand Down

0 comments on commit 3d28dea

Please sign in to comment.