Skip to content

Commit

Permalink
Revert "fix to print_summary(decimals=x) in lifelines.statistics"
Browse files Browse the repository at this point in the history
This reverts commit 05bba7f.
  • Loading branch information
CamDavidsonPilon committed Oct 29, 2024
1 parent 3b5648d commit c9d6738
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 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,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:
Expand All @@ -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

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

0 comments on commit c9d6738

Please sign in to comment.