From 019d0e97b11a00a65a8e14a6e3c5b33ad09a849c Mon Sep 17 00:00:00 2001 From: gedeck Date: Sat, 30 Sep 2023 01:57:42 -0400 Subject: [PATCH] Function test fails for np.mean (#380) * Function test for np.mean * linter * Add 3.10 * Add 3.11 * Change code --- .github/workflows/python_tests.yml | 2 +- pingouin/effsize.py | 4 ++-- pingouin/tests/test_effsize.py | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 6091bf1a..6a4a7879 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-latest, macos-latest, windows-latest] - python-version: [3.7, 3.8, 3.9] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] runs-on: ${{ matrix.platform }} diff --git a/pingouin/effsize.py b/pingouin/effsize.py index c2d53849..359c0252 100644 --- a/pingouin/effsize.py +++ b/pingouin/effsize.py @@ -356,14 +356,14 @@ def compute_bootci( ... f"{bt.mean():.4f} ± {bt.std():.4f}") The bootstrap distribution has 10000 samples. The mean and standard 0.8807 ± 0.1704 """ - from inspect import isfunction + from inspect import isfunction, isroutine from scipy.stats import norm # Check other arguments assert isinstance(confidence, float) assert 0 < confidence < 1, "confidence must be between 0 and 1." assert method in ["norm", "normal", "percentile", "per", "cpercentile", "cper"] - assert isfunction(func) or isinstance(func, str), ( + assert isfunction(func) or isinstance(func, str) or isroutine(func), ( "func must be a function (e.g. np.mean, custom function) or a string (e.g. 'pearson'). " "See documentation for more details." ) diff --git a/pingouin/tests/test_effsize.py b/pingouin/tests/test_effsize.py index 7c20d5d4..0b656c32 100644 --- a/pingouin/tests/test_effsize.py +++ b/pingouin/tests/test_effsize.py @@ -117,6 +117,14 @@ def test_compute_boot_esci(self): assert ci_p[0] == 2.98 and ci_p[1] == 3.21 assert ci_c[0] == 2.98 and round(ci_c[1], 1) == 3.2 + # 2.a Univariate function: np.mean + ci_n = compute_bootci(x_m, func=np.mean, method="norm", seed=42) + ci_p = compute_bootci(x_m, func=np.mean, method="per", seed=42) + ci_c = compute_bootci(x_m, func=np.mean, method="cper", seed=42) + assert ci_n[0] == 2.98 and ci_n[1] == 3.21 + assert ci_p[0] == 2.98 and ci_p[1] == 3.21 + assert ci_c[0] == 2.98 and round(ci_c[1], 1) == 3.2 + # 3. Univariate custom function: skewness from scipy.stats import skew