Skip to content

Commit

Permalink
Merge pull request #1643 from CamDavidsonPilon/0.30.0
Browse files Browse the repository at this point in the history
0.30.0
  • Loading branch information
CamDavidsonPilon authored Oct 29, 2024
2 parents d20609f + 04b2081 commit 47afb1c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
## Changelog

#### 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
- 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 ✨
Expand Down
12 changes: 10 additions & 2 deletions lifelines/fitters/coxph_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
41 changes: 20 additions & 21 deletions lifelines/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand All @@ -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.")

Expand All @@ -110,27 +110,26 @@ def print_summary(self, decimals=2, style=None, **kwargs):
multiple outputs.
"""
self.decimals=decimals
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, **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

Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -836,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_)
Expand Down Expand Up @@ -924,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

Expand Down
2 changes: 1 addition & 1 deletion lifelines/tests/test_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion lifelines/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = "0.29.0"
__version__ = "0.30.0"
2 changes: 1 addition & 1 deletion reqs/base-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy>=1.14.0,<2.0
numpy>=1.14.0
scipy>=1.7.0
pandas>=2.1
matplotlib>=3.0
Expand Down

0 comments on commit 47afb1c

Please sign in to comment.