In Jupyter, triangles are auto-formatted based on the size of the elements in it, adds a thousands separator, and replaces NaN with a blank string:
|
elif self._dimensionality == "single": |
|
data = self._repr_format() |
|
fmt_str = self._get_format_str(data=data) |
|
default = ( |
|
data |
|
.to_html( |
|
max_rows=pd.options.display.max_rows, |
|
max_cols=pd.options.display.max_columns, |
|
float_format=fmt_str.format, |
|
) |
|
.replace("nan", "") |
|
.replace("NaN", "") |
|
) |
|
def _get_format_str(data: DataFrame) -> str: |
|
""" |
|
Returns a numerical format string based on the magnitude of the mean absolute value of the values in the |
|
supplied DataFrame. |
|
|
|
Returns |
|
------- |
|
str |
|
""" |
|
if np.all(np.isnan(data)): |
|
return "" |
|
elif np.nanmean(abs(data)) < 10: |
|
return "{0:,.4f}" |
|
elif np.nanmean(abs(data)) < 1000: |
|
return "{0:,.2f}" |
|
else: |
|
return "{:,.0f}" |
This has the effect of improving the aesthetics for the purpose of presentation, i.e., executive summaries, slide shows, etc. One might also refer to this as "pretty printing".
However, for other uses, such as exploratory analysis, this may not be appropriate, as the user may prefer the default level of precision and/or have the formatting be controllable.
Furthermore, the current auto-format works well for the Chainladder docs, generated by Jupyter, because the specific examples contained in work with how the auto-format is defined. However, real-world examples that are not contained in the docs may cause problems, such as one discussed in #1284:
small nitpick. not uncommon to have massive factor(s) in the first dev period for either a selected pattern or a ldf triangle. are you open to setting the default pattern format to 4 decimals?
i.e.,
12-24 24-36 36-48 48-60 60-72 72-84 84-96 96-108 108-120
(All) 90000.0 1.006235 1.002709 1.001717 1.001134 1.000419 1.000333 1.000169 1.000092
Would be become
In Jupyter.
Because of this, as part of our drive to broaden the appeal of Chainladder for more use cases and locales, I would propose that while we continue to support a built-in pretty print, we make it optional:
- Rework the auto-format/pretty print to handle both value and pattern cases
- Move the auto-format to Options
- Disable the auto-formatting by default
- Enable the auto-formatting for the docs
- Allow the user to provide their own formatting scheme via a callable
- Write a tutorial in the docs on how the user can do this
Additional info
Disabling the auto-format by default is a breaking change, we can delay that step for version 2.0.0 while accomplishing the other steps in prior releases.
In Jupyter, triangles are auto-formatted based on the size of the elements in it, adds a thousands separator, and replaces
NaNwith a blank string:chainladder-python/chainladder/core/display.py
Lines 75 to 87 in 91a942f
chainladder-python/chainladder/core/display.py
Lines 97 to 113 in 91a942f
This has the effect of improving the aesthetics for the purpose of presentation, i.e., executive summaries, slide shows, etc. One might also refer to this as "pretty printing".
However, for other uses, such as exploratory analysis, this may not be appropriate, as the user may prefer the default level of precision and/or have the formatting be controllable.
Furthermore, the current auto-format works well for the Chainladder docs, generated by Jupyter, because the specific examples contained in work with how the auto-format is defined. However, real-world examples that are not contained in the docs may cause problems, such as one discussed in #1284:
i.e.,
Would be become
In Jupyter.
Because of this, as part of our drive to broaden the appeal of Chainladder for more use cases and locales, I would propose that while we continue to support a built-in pretty print, we make it optional:
Additional info
Disabling the auto-format by default is a breaking change, we can delay that step for version 2.0.0 while accomplishing the other steps in prior releases.