Skip to content

Commit

Permalink
BUILD: Add support for numpy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zoj613 committed Jul 17, 2024
1 parent bcb062f commit 798b5fb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.txt
cythonize polyagamma/*.pyx
- name: Run Pytest, report coverage
# Cython's linetracing is broken in 3.12 due to changes in the python c-API
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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());'"
]
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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
4 changes: 2 additions & 2 deletions tests/test_polyagamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 798b5fb

Please sign in to comment.