Skip to content

Commit

Permalink
numpy 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mobiusklein committed Jul 2, 2024
1 parent 9dbb627 commit d70bd6b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
requires = ["setuptools",
"wheel",
"Cython",
"numpy==1.23.2; python_version >= '3.10'",
"oldest-supported-numpy; python_version >= '3.8' and python_version < '3.10'",
"numpy==2.0.0,<2.1.0; python_version >= '3.9'",
"oldest-supported-numpy; python_version >= '3.8' and python_version < '3.9'",
"numpy==1.16.1; python_version <= '3.7' and python_version >= '3'",
"numpy==1.13.3; python_version=='2.7'",
"scipy"]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy
numpy>=2.0.0; python_version >= '3.9'
numpy; python_version < '3.9'
scipy
six
8 changes: 7 additions & 1 deletion src/ms_peak_picker/_c/peak_statistics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ cdef DTYPE_t minimum_signal_to_noise = 4.0

cdef object np_zeros = np.zeros

cdef object trapz = None
try:
trapz = np.trapz
except AttributeError:
trapz = np.trapezoid


@cython.nonecheck(False)
@cython.cdivision(True)
Expand Down Expand Up @@ -651,7 +657,7 @@ cpdef double gaussian_volume(FittedPeak peak):
cdef:
np.ndarray[double, ndim=1] x, y
x, y = gaussian_shape(peak)
return np.trapz(y, x, dx=0.0001)
return trapz(y, x, dx=0.0001)


cdef class PeakShapeModel(object):
Expand Down
9 changes: 7 additions & 2 deletions src/ms_peak_picker/peak_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from .utils import range
from .search import get_nearest

trapz = None
try:
trapz = np.trapz
except AttributeError:
trapz = np.trapezoid

minimum_signal_to_noise = 4.

Expand Down Expand Up @@ -398,7 +403,7 @@ def gaussian_error(peak, mz, intensity):

def gaussian_volume(peak):
x, y = gaussian_shape(peak)
return np.trapz(y, x, dx=0.0001)
return trapz(y, x, dx=0.0001)


def lorentzian_predict(peak, mz):
Expand Down Expand Up @@ -426,7 +431,7 @@ def lorentzian_error(peak, mz, intensity):

def lorentzian_volume(peak):
x, y = lorentzian_shape(peak)
return np.trapz(y, x, dx=0.0001)
return trapz(y, x, dx=0.0001)


class PeakShapeModel(object):
Expand Down

0 comments on commit d70bd6b

Please sign in to comment.