Skip to content

Commit

Permalink
numpy 2.0 (#388)
Browse files Browse the repository at this point in the history
* replace np.trapz with np.trapezoid

* bump version to 2.8.14

* allow numpy 2

* check numpy version for trapz vs trapezoid

* bump version to 2.8.15

* use `numpy~=1.0` for docs test

* set minimum numpy version to 1.26.0 to cover numpy 1 version tests, all earlier versions did not want to install locally

* add minimum-dependencies check to codecov

* bump version to 2.8.16

* use `importlib.util.find_spec` rather than `sys.modules` to check whether a python package is installed, appears more robust

---------

Co-authored-by: lukashergt <[email protected]>
Co-authored-by: Lukas Hergt <[email protected]>
  • Loading branch information
3 people authored Sep 30, 2024
1 parent a4c8521 commit 42b1ead
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
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.9.0
:Version: 2.9.1
: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.9.0'
__version__ = '2.9.1'
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 @@ def fastkde_plot_1d(ax, data, *args, **kwargs):
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
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 @@ def kde_plot_1d(ax, data, *args, **kwargs):
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)
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

0 comments on commit 42b1ead

Please sign in to comment.