Skip to content

Commit e50cb15

Browse files
authored
Merge pull request #249 from avcopan/dev
Fix NumPy version issue
2 parents 115b6a8 + 66d0ecb commit e50cb15

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/mess_io/reader/ped.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
from ioformat import remove_comment_lines
1313
from mess_io.reader._label import name_label_dct
1414
from automol.util.dict_ import invert
15+
# AVC: Backward compatibility for numpy < 2.0, where the function is called `trapz`
16+
try:
17+
from numpy import trapezoid
18+
except ImportError:
19+
from numpy import trapz as trapezoid
1520

1621

1722
def ped_names(input_str):
@@ -87,7 +92,7 @@ def prob_en_single(probability, energy, del_neg = False):
8792

8893
# prob_en = prob_en[prob_en > 0]
8994
if del_neg:
90-
if np.trapz(prob_en.values, x=prob_en.index) < 0:
95+
if trapezoid(prob_en.values, x=prob_en.index) < 0:
9196
# I don't know how to treat negative probabilities
9297
# alternative: set the absolute value? or do nothing
9398
prob_en *= 0
@@ -113,7 +118,7 @@ def prob_en_single(probability, energy, del_neg = False):
113118
# prob_en = prob_en[prob_en[prob_en < 0].index[-1]+1:]
114119
# print(prob_en, '\n')
115120
# integrate with trapz
116-
prob_en /= abs(np.trapz(prob_en.values, x=prob_en.index))
121+
prob_en /= abs(trapezoid(prob_en.values, x=prob_en.index))
117122

118123
# if issues : keep only max value like dirac delta
119124
if any(np.isnan(prob_en.values)) or any(np.isinf(prob_en.values)):

0 commit comments

Comments
 (0)