Skip to content
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

numpy 2.0 #388

Merged
merged 13 commits into from
Sep 30, 2024
1 change: 1 addition & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Upgrade pip and install doc requirements
run: |
python -m pip install --upgrade pip
python -m pip install numpy~=1.0
python -m pip install -e ".[all,docs]"
- name: build documentation
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anesthetic: nested sampling post-processing
===========================================
:Authors: Will Handley and Lukas Hergt
:Version: 2.8.15
:Version: 2.8.16
:Homepage: https://github.com/handley-lab/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.8.15'
__version__ = '2.8.16'
13 changes: 11 additions & 2 deletions anesthetic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
to create a set of axes and legend proxies.

"""
from packaging import version
import numpy as np
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -839,7 +840,11 @@
p /= p.max()
i = ((x > quantile(x, q[0], p)) & (x < quantile(x, q[-1], p)))

area = np.trapz(x=x[i], y=p[i]) if density else 1
if version.parse(np.__version__) >= version.parse("2.0.0"):
trapezoid = np.trapezoid
else:
trapezoid = np.trapz

Check warning on line 846 in anesthetic/plot.py

View check run for this annotation

Codecov / codecov/patch

anesthetic/plot.py#L846

Added line #L846 was not covered by tests
area = trapezoid(x=x[i], y=p[i]) if density else 1
if ax.get_xaxis().get_scale() == 'log':
x = 10**x
ans = ax.plot(x[i], p[i]/area, color=color, *args, **kwargs)
Expand Down Expand Up @@ -962,7 +967,11 @@
bw = np.sqrt(kde.covariance[0, 0])
pp = cut_and_normalise_gaussian(x, p, bw, xmin=data.min(), xmax=data.max())
pp /= pp.max()
area = np.trapz(x=x, y=pp) if density else 1
if version.parse(np.__version__) >= version.parse("2.0.0"):
trapezoid = np.trapezoid
else:
trapezoid = np.trapz
area = trapezoid(x=x, y=pp) if density else 1
if ax.get_xaxis().get_scale() == 'log':
x = 10**x
ans = ax.plot(x, pp/area, color=color, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ license = {file = "LICENSE"}
requires-python = ">=3.8"
dependencies = [
"scipy<2.0.0",
"numpy<2.0.0",
"numpy>=1.26.0,<3.0.0",
"pandas~=2.2.0",
"matplotlib>=3.6.1,<3.10.0",
]
Expand Down
10 changes: 5 additions & 5 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from importlib.util import find_spec
import pytest
import sys

try:
import astropy # noqa: F401
except ImportError:
pass

condition = 'astropy' not in sys.modules
condition = find_spec('astropy') is None
reason = "requires astropy package"
raises = ImportError
astropy_mark_skip = pytest.mark.skipif(condition, reason=reason)
Expand All @@ -22,7 +22,7 @@ def skipif_no_astropy(param):
except ImportError:
pass
reason = "requires fastkde package"
condition = 'fastkde' not in sys.modules
condition = find_spec('fastkde') is None
raises = ImportError
fastkde_mark_skip = pytest.mark.skipif(condition, reason=reason)
fastkde_mark_xfail = pytest.mark.xfail(condition, raises=raises, reason=reason)
Comment on lines 24 to 28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change addresses the problem that @AdamOrmondroyd raised in a comment:

All the pytests involving fastkde skip rather than fail due to the failed import, which is a flaw in how our optional dependency tests work. Really, the "true" tests should fail.

With these changes the extras=true tests now fail, and the extras=false tests pass. Hopefully all tests pass once fastkde functions properly with numpy 2.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just what we need, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works locally with the current main branch of fastkde, just need them to update it on pypi when they've fixed their ci

Expand All @@ -36,7 +36,7 @@ def skipif_no_fastkde(param):
import getdist # noqa: F401
except ImportError:
pass
condition = 'getdist' not in sys.modules
condition = find_spec('getdist') is None
reason = "requires getdist package"
raises = ImportError
getdist_mark_skip = pytest.mark.skipif(condition, reason=reason)
Expand Down Expand Up @@ -65,7 +65,7 @@ def skipif_no_getdist(param):
except ImportError:
pass

condition = 'h5py' not in sys.modules
condition = find_spec('h5py') is None
reason = "requires h5py package"
raises = ImportError
h5py_mark_skip = pytest.mark.skipif(condition, reason=reason)
Expand Down
Loading