From 028d89d3cba6f4b7f9f37192dbe7cb265acbd1cb Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Tue, 29 Oct 2024 05:13:21 -0400 Subject: [PATCH 1/6] bump numpy --- CHANGELOG.md | 5 ++++- reqs/base-requirements.txt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6f5b8917..fc99921f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ ## Changelog +#### 0.30.0 - 2024-06-25 + - update dependencies (numpy >= 1.14.0) + + #### 0.29.0 - 2024-06-25 - update dependencies (pandas >= 2.1) - update dependencies (scipy >= 1.7) - #### 0.28.0 - 2024-01-03 - Fixes bins that are far into the future with using `survival_table_from_events`, see #1587 - Removed `sklean_adaptor`. It was a terrible hack, and causing more confusion and support debt than I want. This cleans up our API and simplifies the library. ✨ There's no replacement, and I doubt I'll introduce one ✨ diff --git a/reqs/base-requirements.txt b/reqs/base-requirements.txt index 862b2ca0a..31e48cde1 100644 --- a/reqs/base-requirements.txt +++ b/reqs/base-requirements.txt @@ -1,4 +1,4 @@ -numpy>=1.14.0,<2.0 +numpy>=1.14.0 scipy>=1.7.0 pandas>=2.1 matplotlib>=3.0 From 3b5648d43228a97f5521df1571b086128a409c07 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Tue, 29 Oct 2024 05:19:41 -0400 Subject: [PATCH 2/6] bump --- CHANGELOG.md | 3 ++- lifelines/version.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc99921f1..c7da7c1f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ## Changelog -#### 0.30.0 - 2024-06-25 +#### 0.30.0 - 2024-10-29 - update dependencies (numpy >= 1.14.0) + - fix for `decimal` kwarg not working in StatisticalResult #### 0.29.0 - 2024-06-25 diff --git a/lifelines/version.py b/lifelines/version.py index 112869107..a69767f31 100644 --- a/lifelines/version.py +++ b/lifelines/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -__version__ = "0.29.0" +__version__ = "0.30.0" From c9d67381c6ad77e3837f25fc41a35fe28c6256d6 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Tue, 29 Oct 2024 05:39:20 -0400 Subject: [PATCH 3/6] Revert "fix to `print_summary(decimals=x)` in lifelines.statistics" This reverts commit 05bba7fe49130108bcf527e83aed8a9f12ebf254. --- lifelines/statistics.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lifelines/statistics.py b/lifelines/statistics.py index 1b18cb2e3..e7b227876 100644 --- a/lifelines/statistics.py +++ b/lifelines/statistics.py @@ -77,7 +77,7 @@ def __init__(self, p_value, test_statistic, name=None, test_name=None, **kwargs) kwargs["test_name"] = test_name self._kwargs = kwargs - def _print_specific_style(self, style, **kwargs): + def _print_specific_style(self, style, decimals=2, **kwargs): """ Parameters ----------- @@ -87,11 +87,11 @@ def _print_specific_style(self, style, **kwargs): """ if style == "html": - return self._html_print(**kwargs) + return self._html_print(decimals=decimals, **kwargs) elif style == "ascii": - return self._ascii_print(**kwargs) + return self._ascii_print(decimals=decimals, **kwargs) elif style == "latex": - return self._latex_print(**kwargs) + return self._latex_print(decimals=decimals, **kwargs) else: raise ValueError("style not available.") @@ -110,7 +110,6 @@ def print_summary(self, decimals=2, style=None, **kwargs): multiple outputs. """ - self.decimals=decimals if style is not None: self._print_specific_style(style) else: @@ -121,16 +120,16 @@ def print_summary(self, decimals=2, style=None, **kwargs): except ImportError: self._ascii_print() - def _html_print(self, **kwargs): - print(self.to_html(**kwargs)) + def _html_print(self, decimals=2, **kwargs): + print(self.to_html(decimals, **kwargs)) - def _latex_print(self, **kwargs): - print(self.to_latex(**kwargs)) + def _latex_print(self, decimals=2, **kwargs): + print(self.to_latex(decimals, **kwargs)) - def _ascii_print(self, **kwargs): - print(self.to_ascii(**kwargs)) + def _ascii_print(self, decimals=2, **kwargs): + print(self.to_ascii(decimals, **kwargs)) - def to_html(self, **kwargs): + def to_html(self, decimals=2, **kwargs): extra_kwargs = dict(list(self._kwargs.items()) + list(kwargs.items())) summary_df = self.summary @@ -141,14 +140,14 @@ def to_html(self, **kwargs): header_df = pd.DataFrame.from_records(headers).set_index(0) header_html = header_df.to_html(header=False, notebook=True, index_names=False) - summary_html = summary_df.to_html(float_format=format_floats(self.decimals), formatters={**{"p": format_p_value(self.decimals)}}) + summary_html = summary_df.to_html(float_format=format_floats(decimals), formatters={**{"p": format_p_value(decimals)}}) return header_html + summary_html - def to_latex(self, **kwargs): + def to_latex(self, decimals=2, **kwargs): # This is using the new Style object in Pandas. Previously df.to_latex was giving a warning. s = self.summary.style - s = s.format(precision=self.decimals) + s = s.format(precision=decimals) return s.to_latex() @property @@ -173,7 +172,7 @@ def summary(self): df["-log2(p)"] = -utils.quiet_log2(df["p"]) return df - def to_ascii(self, **kwargs): + def to_ascii(self, decimals=2, **kwargs): extra_kwargs = dict(list(self._kwargs.items()) + list(kwargs.items())) meta_data = self._stringify_meta_data(extra_kwargs) @@ -183,7 +182,7 @@ def to_ascii(self, **kwargs): s += "\n" + meta_data + "\n" s += "---\n" s += df.to_string( - float_format=format_floats(self.decimals), index=self.name is not None, formatters={"p": format_p_value(self.decimals)} + float_format=format_floats(decimals), index=self.name is not None, formatters={"p": format_p_value(decimals)} ) return s From 1e0a3d553c757766654fb263ad41fda272ce9830 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Tue, 29 Oct 2024 05:56:03 -0400 Subject: [PATCH 4/6] revert PR for new fix, fix strata labeller to handle np types --- lifelines/fitters/coxph_fitter.py | 12 ++++++++++-- lifelines/statistics.py | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lifelines/fitters/coxph_fitter.py b/lifelines/fitters/coxph_fitter.py index 145752e4a..0a627a830 100644 --- a/lifelines/fitters/coxph_fitter.py +++ b/lifelines/fitters/coxph_fitter.py @@ -2991,7 +2991,11 @@ def __init__(self, strata, strata_values, n_baseline_knots=1, knots=None, *args, @staticmethod def _strata_labeler(stratum, i): - return "s%s_phi%d_" % (stratum, i) + try: + return "s%s_phi%d_" % (tuple(str(s) for s in stratum), i) + except: + # singleton + return "s%s_phi%d_" % (stratum, i) @property def _fitted_parameter_names(self): @@ -3112,7 +3116,11 @@ def __init__(self, strata, strata_values, breakpoints, *args, **kwargs): @staticmethod def _strata_labeler(stratum, i): - return "s%s_lambda%d_" % (stratum, i) + try: + return "s%s_lambda%d_" % (tuple(str(s) for s in stratum), i) + except: + # singleton + return "s%s_lambda%d_" % (stratum, i) @property def _fitted_parameter_names(self): diff --git a/lifelines/statistics.py b/lifelines/statistics.py index e7b227876..2db02bbe9 100644 --- a/lifelines/statistics.py +++ b/lifelines/statistics.py @@ -111,14 +111,14 @@ def print_summary(self, decimals=2, style=None, **kwargs): """ if style is not None: - self._print_specific_style(style) + self._print_specific_style(style, decimals=decimals, **kwargs) else: try: from IPython.display import display display(self) except ImportError: - self._ascii_print() + self._ascii_print(decimals=decimals, **kwargs) def _html_print(self, decimals=2, **kwargs): print(self.to_html(decimals, **kwargs)) @@ -835,7 +835,7 @@ def multivariate_logrank_test( assert abs(Z_j.sum()) < 10e-8, "Sum is not zero." # this should move to a test eventually. # compute covariance matrix - factor = (((n_i - d_i) / (n_i - 1)).replace([np.inf, np.nan], 1)) * d_i / n_i ** 2 + factor = (((n_i - d_i) / (n_i - 1)).replace([np.inf, np.nan], 1)) * d_i / n_i**2 n_ij["_"] = n_i.values V_ = (n_ij.mul(w_i, axis=0)).mul(np.sqrt(factor), axis="index").fillna(0) # weighted V_ V = -np.dot(V_.T, V_) @@ -923,7 +923,7 @@ def proportional_hazard_test( def compute_statistic(times, resids, n_deaths): demeaned_times = times - times.mean() T = (demeaned_times.values[:, None] * resids.values).sum(0) ** 2 / ( - n_deaths * (fitted_cox_model.standard_errors_ ** 2) * (demeaned_times ** 2).sum() + n_deaths * (fitted_cox_model.standard_errors_**2) * (demeaned_times**2).sum() ) return T From ef2713974ab9dabf159bfb59b31060652810704b Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Tue, 29 Oct 2024 06:21:46 -0400 Subject: [PATCH 5/6] loltravis --- .travis.yml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cb68b5388..000000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: python -cache: pip -dist: xenial -python: - - "3.6" - - "3.7" - - "3.8" -env: - matrix: - - PANDAS_VERSION=0.23.4 && NUMPY_VERSION=1.19.0 - - PANDAS_VERSION=0.25.3 && NUMPY_VERSION=1.19.0 - - NUMPY_VERSION=1.15.4 && PANDAS_VERSION=1.1.0 - - NUMPY_VERSION=1.19.0 && PANDAS_VERSION=1.1.0 -before_install: - - ls - # - sudo apt-get update -install: "make" -script: - # command to run tests - - make test -after_script: - - coveralls -# Don't want notifications -notifications: - email: false From 04b2081e9bc20602312be7da23fb302134505bb6 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Tue, 29 Oct 2024 06:30:54 -0400 Subject: [PATCH 6/6] fix test --- lifelines/tests/test_estimation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lifelines/tests/test_estimation.py b/lifelines/tests/test_estimation.py index abf1d5f97..28087af82 100644 --- a/lifelines/tests/test_estimation.py +++ b/lifelines/tests/test_estimation.py @@ -3320,7 +3320,7 @@ def test_strata_estimation_is_same_if_using_trivial_strata(self, rossi): assert_frame_equal( cph.summary.loc[[("beta_", "Intercept"), ("phi1_", "Intercept")]].reset_index(drop=True), - trivial_strata_cph.summary.loc[[("beta_", "Intercept"), ("sa_phi1_", "Intercept")]].reset_index(drop=True), + trivial_strata_cph.summary.loc[[("beta_", "Intercept"), ("s('a',)_phi1_", "Intercept")]].reset_index(drop=True), atol=0.05, )