Skip to content

[ENH] Move Jupyter auto-formatting to Options, disabled by default #1309

Description

@genedan

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}"

Image

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

  90,000    1    1    1    1    1    1    1    1

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.

Activity

  1. added this to the v2.0.0 milestone on Sep 7, 2026
  2. added theissue type on Sep 7, 2026
  3. updated Priority Medium and Effort Medium on Sep 7, 2026
  4. henrydingliu commented on Oct 3, 2026

    @henrydingliu
    Member

    @genedan do we still need this now that we have stylers?

  5. genedan commented on Oct 4, 2026

    @genedan
    MemberAuthor

    Yeah, there's still a default formatting that overrides the raw Jupyter formatting buried deep in core/ which should be moved to config/.

    Stylers only work on individual triangles, whereas the auto-format applies to all the triangles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    Priority

    Medium

    Effort

    Medium

    Scope

    Both

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions