From 9991a2a661b3a15e93cad041d41cc3dec9138ef5 Mon Sep 17 00:00:00 2001 From: Zolisa Bleki Date: Wed, 17 Jul 2024 12:49:14 +0200 Subject: [PATCH] BUILD: Add support for numpy 2.0 --- pyproject.toml | 12 ++++++------ requirements-dev.txt | 3 ++- tests/test_polyagamma.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e94d76e..728adeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,12 +7,12 @@ requires = [ # the used version of python. This does not affect required numpy version at # installation time; `project.dependencies` is most relevant for required numpy # when installtng at user level. - "numpy==1.26.0; python_version=='3.12' and platform_python_implementation!='PyPy'", - "numpy==1.23.2; python_version=='3.11' and platform_python_implementation!='PyPy'", - "numpy==1.21.3; python_version=='3.10' and platform_python_implementation!='PyPy'", - "numpy==1.19.3; python_version=='3.9' and platform_python_implementation!='PyPy'", + "numpy==2.0.0; python_version=='3.12' and platform_python_implementation!='PyPy'", + "numpy==2.0.0; python_version=='3.11' and platform_python_implementation!='PyPy'", + "numpy==2.0.0; python_version=='3.10' and platform_python_implementation!='PyPy'", + "numpy==2.0.0; python_version=='3.9' and platform_python_implementation!='PyPy'", # PyPy specific requirements - "numpy==1.25.0; python_version=='3.9' and platform_python_implementation=='PyPy'", + "numpy==2.0.0; python_version=='3.9' and platform_python_implementation=='PyPy'", ] build-backend = "setuptools.build_meta" @@ -73,7 +73,7 @@ skip = ["pp31*", "pp3*_aarch64", "*-musllinux_aarch64"] # The test-command string is not parsed correctly on windows so we skip testing the wheel for now. # ARM64 wheels on MacOS currently can't be test with cibuildwheels, so we skip testing until it can be supoorted. test-skip = ["*-win*", "*-macosx_arm64"] -before-test = "pip install numpy --pre" +before-test = "pip install numpy==1.19.0 --pre" test-command = [ "python -c 'from polyagamma import random_polyagamma;print(random_polyagamma());'" ] diff --git a/requirements-dev.txt b/requirements-dev.txt index 3ec7f7c..d921df4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ cython==3.0.* -numpy==1.26.0 +numpy==2.0.0 pre-commit==3.4.0 pytest==7.4.0 pytest-cov==4.1.0 +setuptools==70.3.0 diff --git a/tests/test_polyagamma.py b/tests/test_polyagamma.py index f0f2484..524f665 100644 --- a/tests/test_polyagamma.py +++ b/tests/test_polyagamma.py @@ -172,7 +172,7 @@ def test_polyagamma_pdf_cdf(method, h, z): x = random_polyagamma(h, z, size=5000, method=method, random_state=rng) x.sort() d = polyagamma_pdf(x, h=h, z=z) - area_under_curve = np.trapz(d, x) + area_under_curve = np.trapezoid(d, x) # relative tolerance is set so that 0.998 can pass the tests. assert np.isclose(1.0, area_under_curve, rtol=1e-2) @@ -181,7 +181,7 @@ def test_polyagamma_pdf_cdf(method, h, z): # calculate the cdf of the distribution at the mean of the samples cdf = polyagamma_cdf(xx, h=h, z=z) # estimate empirical cdf from the sampled and corresponding density - ecdf = np.trapz(d[mask], x[mask]) + ecdf = np.trapezoid(d[mask], x[mask]) # test if the empirical cdf is equal to the distribution's to 2 decimals assert np.allclose(ecdf, cdf, rtol=1e-2)