Skip to content

Commit

Permalink
Merge pull request #1620 from asarigun/master
Browse files Browse the repository at this point in the history
Changing `trapz` to `trapezoid` for scipy 1.14.0.
  • Loading branch information
CamDavidsonPilon authored Jun 25, 2024
2 parents b8f0174 + ee9570c commit fb5ad90
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lifelines/fitters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import autograd.numpy as anp

from scipy.optimize import minimize, root_scalar
from scipy.integrate import trapz
from scipy.integrate import trapezoid
from scipy import stats

import pandas as pd
Expand Down Expand Up @@ -2507,7 +2507,7 @@ def predict_expectation(self, X, conditional_after=None) -> pd.Series:
warnings.warn("""Approximating the expected value using trapezoid rule.\n""", exceptions.ApproximationWarning)
subjects = utils._get_index(X)
v = self.predict_survival_function(X, conditional_after=conditional_after)[subjects]
return pd.Series(trapz(v.values.T, v.index), index=subjects).squeeze()
return pd.Series(trapezoid(v.values.T, v.index), index=subjects).squeeze()

@property
def median_survival_time_(self):
Expand Down
4 changes: 2 additions & 2 deletions lifelines/fitters/aalen_additive_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pandas as pd
from numpy.linalg import LinAlgError
from scipy.integrate import trapz
from scipy.integrate import trapezoid

from lifelines.fitters import RegressionFitter
from lifelines.utils.printer import Printer
Expand Down Expand Up @@ -396,7 +396,7 @@ def predict_expectation(self, X) -> pd.Series:
"""
index = _get_index(X)
t = self._index
return pd.Series(trapz(self.predict_survival_function(X)[index].values.T, t), index=index)
return pd.Series(trapezoid(self.predict_survival_function(X)[index].values.T, t), index=index)

def _compute_confidence_intervals(self):
ci = 100 * (1 - self.alpha)
Expand Down
4 changes: 2 additions & 2 deletions lifelines/fitters/coxph_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from numpy import dot, einsum, log, exp, zeros, arange, multiply, ndarray
import numpy as np
from scipy.linalg import solve as spsolve, LinAlgError, norm, inv
from scipy.integrate import trapz
from scipy.integrate import trapezoid
from scipy import stats
from pandas import DataFrame, Series, Index
import pandas as pd
Expand Down Expand Up @@ -2514,7 +2514,7 @@ def predict_expectation(self, X: DataFrame, conditional_after: Optional[ndarray]
"""
subjects = utils._get_index(X)
v = self.predict_survival_function(X, conditional_after=conditional_after)[subjects]
return pd.Series(trapz(v.values.T, v.index), index=subjects)
return pd.Series(trapezoid(v.values.T, v.index), index=subjects)

def _compute_baseline_hazard(self, partial_hazards: DataFrame, name: Any) -> pd.DataFrame:
# https://stats.stackexchange.com/questions/46532/cox-baseline-hazard
Expand Down
6 changes: 3 additions & 3 deletions lifelines/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from numpy import ndarray
import numpy as np

from scipy.integrate import quad, trapz
from scipy.integrate import quad, trapezoid
from scipy.linalg import solve
from scipy import stats

Expand Down Expand Up @@ -266,7 +266,7 @@ def _expected_value_of_survival_up_to_t(model_or_survival_function, t: float = n
)
sf = model_or_survival_function.loc[:t]
sf = pd.concat((sf, pd.DataFrame([1], index=[0], columns=sf.columns))).sort_index()
return trapz(y=sf.values[:, 0], x=sf.index)
return trapezoid(y=sf.values[:, 0], x=sf.index)
elif isinstance(model_or_survival_function, lifelines.fitters.UnivariateFitter):
# lifelines model
model = model_or_survival_function
Expand Down Expand Up @@ -313,7 +313,7 @@ def _expected_value_of_survival_squared_up_to_t(
sf = model_or_survival_function.loc[:t]
sf = pd.concat((sf, pd.DataFrame([1], index=[0], columns=sf.columns))).sort_index()
sf_tau = sf * sf.index.values[:, None]
return 2 * trapz(y=sf_tau.values[:, 0], x=sf_tau.index)
return 2 * trapezoid(y=sf_tau.values[:, 0], x=sf_tau.index)
elif isinstance(model_or_survival_function, lifelines.fitters.UnivariateFitter):
# lifelines model
model = model_or_survival_function
Expand Down

0 comments on commit fb5ad90

Please sign in to comment.