Skip to content

Commit 47afb1c

Browse files
Merge pull request #1643 from CamDavidsonPilon/0.30.0
0.30.0
2 parents d20609f + 04b2081 commit 47afb1c

File tree

7 files changed

+38
-52
lines changed

7 files changed

+38
-52
lines changed

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
## Changelog
22

3+
#### 0.30.0 - 2024-10-29
4+
- update dependencies (numpy >= 1.14.0)
5+
- fix for `decimal` kwarg not working in StatisticalResult
6+
7+
38
#### 0.29.0 - 2024-06-25
49
- update dependencies (pandas >= 2.1)
510
- update dependencies (scipy >= 1.7)
611

712

8-
913
#### 0.28.0 - 2024-01-03
1014
- Fixes bins that are far into the future with using `survival_table_from_events`, see #1587
1115
- 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 ✨

lifelines/fitters/coxph_fitter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,11 @@ def __init__(self, strata, strata_values, n_baseline_knots=1, knots=None, *args,
29912991

29922992
@staticmethod
29932993
def _strata_labeler(stratum, i):
2994-
return "s%s_phi%d_" % (stratum, i)
2994+
try:
2995+
return "s%s_phi%d_" % (tuple(str(s) for s in stratum), i)
2996+
except:
2997+
# singleton
2998+
return "s%s_phi%d_" % (stratum, i)
29952999

29963000
@property
29973001
def _fitted_parameter_names(self):
@@ -3112,7 +3116,11 @@ def __init__(self, strata, strata_values, breakpoints, *args, **kwargs):
31123116

31133117
@staticmethod
31143118
def _strata_labeler(stratum, i):
3115-
return "s%s_lambda%d_" % (stratum, i)
3119+
try:
3120+
return "s%s_lambda%d_" % (tuple(str(s) for s in stratum), i)
3121+
except:
3122+
# singleton
3123+
return "s%s_lambda%d_" % (stratum, i)
31163124

31173125
@property
31183126
def _fitted_parameter_names(self):

lifelines/statistics.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, p_value, test_statistic, name=None, test_name=None, **kwargs)
7777
kwargs["test_name"] = test_name
7878
self._kwargs = kwargs
7979

80-
def _print_specific_style(self, style, **kwargs):
80+
def _print_specific_style(self, style, decimals=2, **kwargs):
8181
"""
8282
Parameters
8383
-----------
@@ -87,11 +87,11 @@ def _print_specific_style(self, style, **kwargs):
8787
8888
"""
8989
if style == "html":
90-
return self._html_print(**kwargs)
90+
return self._html_print(decimals=decimals, **kwargs)
9191
elif style == "ascii":
92-
return self._ascii_print(**kwargs)
92+
return self._ascii_print(decimals=decimals, **kwargs)
9393
elif style == "latex":
94-
return self._latex_print(**kwargs)
94+
return self._latex_print(decimals=decimals, **kwargs)
9595
else:
9696
raise ValueError("style not available.")
9797

@@ -110,27 +110,26 @@ def print_summary(self, decimals=2, style=None, **kwargs):
110110
multiple outputs.
111111
112112
"""
113-
self.decimals=decimals
114113
if style is not None:
115-
self._print_specific_style(style)
114+
self._print_specific_style(style, decimals=decimals, **kwargs)
116115
else:
117116
try:
118117
from IPython.display import display
119118

120119
display(self)
121120
except ImportError:
122-
self._ascii_print()
121+
self._ascii_print(decimals=decimals, **kwargs)
123122

124-
def _html_print(self, **kwargs):
125-
print(self.to_html(**kwargs))
123+
def _html_print(self, decimals=2, **kwargs):
124+
print(self.to_html(decimals, **kwargs))
126125

127-
def _latex_print(self, **kwargs):
128-
print(self.to_latex(**kwargs))
126+
def _latex_print(self, decimals=2, **kwargs):
127+
print(self.to_latex(decimals, **kwargs))
129128

130-
def _ascii_print(self, **kwargs):
131-
print(self.to_ascii(**kwargs))
129+
def _ascii_print(self, decimals=2, **kwargs):
130+
print(self.to_ascii(decimals, **kwargs))
132131

133-
def to_html(self, **kwargs):
132+
def to_html(self, decimals=2, **kwargs):
134133
extra_kwargs = dict(list(self._kwargs.items()) + list(kwargs.items()))
135134
summary_df = self.summary
136135

@@ -141,14 +140,14 @@ def to_html(self, **kwargs):
141140
header_df = pd.DataFrame.from_records(headers).set_index(0)
142141
header_html = header_df.to_html(header=False, notebook=True, index_names=False)
143142

144-
summary_html = summary_df.to_html(float_format=format_floats(self.decimals), formatters={**{"p": format_p_value(self.decimals)}})
143+
summary_html = summary_df.to_html(float_format=format_floats(decimals), formatters={**{"p": format_p_value(decimals)}})
145144

146145
return header_html + summary_html
147146

148-
def to_latex(self, **kwargs):
147+
def to_latex(self, decimals=2, **kwargs):
149148
# This is using the new Style object in Pandas. Previously df.to_latex was giving a warning.
150149
s = self.summary.style
151-
s = s.format(precision=self.decimals)
150+
s = s.format(precision=decimals)
152151
return s.to_latex()
153152

154153
@property
@@ -173,7 +172,7 @@ def summary(self):
173172
df["-log2(p)"] = -utils.quiet_log2(df["p"])
174173
return df
175174

176-
def to_ascii(self, **kwargs):
175+
def to_ascii(self, decimals=2, **kwargs):
177176
extra_kwargs = dict(list(self._kwargs.items()) + list(kwargs.items()))
178177
meta_data = self._stringify_meta_data(extra_kwargs)
179178

@@ -183,7 +182,7 @@ def to_ascii(self, **kwargs):
183182
s += "\n" + meta_data + "\n"
184183
s += "---\n"
185184
s += df.to_string(
186-
float_format=format_floats(self.decimals), index=self.name is not None, formatters={"p": format_p_value(self.decimals)}
185+
float_format=format_floats(decimals), index=self.name is not None, formatters={"p": format_p_value(decimals)}
187186
)
188187

189188
return s
@@ -836,7 +835,7 @@ def multivariate_logrank_test(
836835
assert abs(Z_j.sum()) < 10e-8, "Sum is not zero." # this should move to a test eventually.
837836

838837
# compute covariance matrix
839-
factor = (((n_i - d_i) / (n_i - 1)).replace([np.inf, np.nan], 1)) * d_i / n_i ** 2
838+
factor = (((n_i - d_i) / (n_i - 1)).replace([np.inf, np.nan], 1)) * d_i / n_i**2
840839
n_ij["_"] = n_i.values
841840
V_ = (n_ij.mul(w_i, axis=0)).mul(np.sqrt(factor), axis="index").fillna(0) # weighted V_
842841
V = -np.dot(V_.T, V_)
@@ -924,7 +923,7 @@ def proportional_hazard_test(
924923
def compute_statistic(times, resids, n_deaths):
925924
demeaned_times = times - times.mean()
926925
T = (demeaned_times.values[:, None] * resids.values).sum(0) ** 2 / (
927-
n_deaths * (fitted_cox_model.standard_errors_ ** 2) * (demeaned_times ** 2).sum()
926+
n_deaths * (fitted_cox_model.standard_errors_**2) * (demeaned_times**2).sum()
928927
)
929928
return T
930929

lifelines/tests/test_estimation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3320,7 +3320,7 @@ def test_strata_estimation_is_same_if_using_trivial_strata(self, rossi):
33203320

33213321
assert_frame_equal(
33223322
cph.summary.loc[[("beta_", "Intercept"), ("phi1_", "Intercept")]].reset_index(drop=True),
3323-
trivial_strata_cph.summary.loc[[("beta_", "Intercept"), ("sa_phi1_", "Intercept")]].reset_index(drop=True),
3323+
trivial_strata_cph.summary.loc[[("beta_", "Intercept"), ("s('a',)_phi1_", "Intercept")]].reset_index(drop=True),
33243324
atol=0.05,
33253325
)
33263326

lifelines/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4-
__version__ = "0.29.0"
4+
__version__ = "0.30.0"

reqs/base-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy>=1.14.0,<2.0
1+
numpy>=1.14.0
22
scipy>=1.7.0
33
pandas>=2.1
44
matplotlib>=3.0

0 commit comments

Comments
 (0)