From 31f8e4d3bf64d8ce7a80ef3ac6d5e15b46c22aaf Mon Sep 17 00:00:00 2001 From: Ethan Kang Date: Thu, 13 Aug 2026 09:33:44 -0700 Subject: [PATCH 1/2] docs: add Triangle.heatmap doctest examples (#704) Co-authored-by: Cursor --- chainladder/core/display.py | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/chainladder/core/display.py b/chainladder/core/display.py index db2ee07b2..86fb8f2d5 100644 --- a/chainladder/core/display.py +++ b/chainladder/core/display.py @@ -174,6 +174,50 @@ def heatmap( ------- Ipython.display.HTML + Examples + -------- + ``heatmap`` styles a single 2-D triangle for notebook display. The + return value is an IPython HTML object with a background gradient. + + .. testsetup:: + + import chainladder as cl + + .. testcode:: + + html = cl.load_sample('raa').heatmap() + print(type(html).__name__) + print('background-color' in html.data) + + .. testoutput:: + + HTML + True + + A different matplotlib colormap can be passed to ``cmap``. The result + is still HTML; only the colors change. + + .. testcode:: + + html = cl.load_sample('raa').heatmap(cmap='viridis') + print(type(html).__name__) + + .. testoutput:: + + HTML + + Multi-dimensional triangles are not supported. + + .. testcode:: + + try: + cl.load_sample('clrd').heatmap() + except ValueError as err: + print(err) + + .. testoutput:: + + heatmap() only works with a single triangle. """ if self._dimensionality == 'single': data = self._repr_format() From 1ff506c61d199b5225de7361fdc44bf3ee177863 Mon Sep 17 00:00:00 2001 From: Ethan Kang Date: Thu, 13 Aug 2026 13:09:07 -0700 Subject: [PATCH 2/2] Point heatmap docs at the User Guide example instead of HTML doctests. Doctest cannot render a background gradient; the Triangle notebook already shows one. Co-authored-by: Cursor --- chainladder/core/display.py | 50 ++++------------------------------ docs/user_guide/triangle.ipynb | 1 + 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/chainladder/core/display.py b/chainladder/core/display.py index 86fb8f2d5..0a80c07dd 100644 --- a/chainladder/core/display.py +++ b/chainladder/core/display.py @@ -158,6 +158,11 @@ def heatmap( Color the background in a gradient according to the data in each column (optionally row). Requires matplotlib. + Styles a single 2-D triangle for notebook display and returns an + IPython HTML object. Multi-dimensional triangles raise + ``ValueError``. See the :ref:`User Guide ` for a + rendered example. + Parameters ---------- @@ -173,51 +178,6 @@ def heatmap( Returns ------- Ipython.display.HTML - - Examples - -------- - ``heatmap`` styles a single 2-D triangle for notebook display. The - return value is an IPython HTML object with a background gradient. - - .. testsetup:: - - import chainladder as cl - - .. testcode:: - - html = cl.load_sample('raa').heatmap() - print(type(html).__name__) - print('background-color' in html.data) - - .. testoutput:: - - HTML - True - - A different matplotlib colormap can be passed to ``cmap``. The result - is still HTML; only the colors change. - - .. testcode:: - - html = cl.load_sample('raa').heatmap(cmap='viridis') - print(type(html).__name__) - - .. testoutput:: - - HTML - - Multi-dimensional triangles are not supported. - - .. testcode:: - - try: - cl.load_sample('clrd').heatmap() - except ValueError as err: - print(err) - - .. testoutput:: - - heatmap() only works with a single triangle. """ if self._dimensionality == 'single': data = self._repr_format() diff --git a/docs/user_guide/triangle.ipynb b/docs/user_guide/triangle.ipynb index 0db555b7b..8f39da4b3 100644 --- a/docs/user_guide/triangle.ipynb +++ b/docs/user_guide/triangle.ipynb @@ -1246,6 +1246,7 @@ "id": "a6a578af", "metadata": {}, "source": [ + "(triangle:heatmap)=\n", "### Link Ratios\n", "\n", "The age-to-age factors or link ratios of a Triangle can be accessed with the\n",