Skip to content

Commit

Permalink
Able to print an empty triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethshsu committed Mar 26, 2024
1 parent 6c9ad1c commit fddc0a6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions chainladder/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

class TriangleDisplay:
def __repr__(self):
if (self.values.shape[0], self.values.shape[1]) == (1, 1):
data = self._repr_format()
return data.to_string()
else:
return self._summary_frame().__repr__()
try:
self.values

if (self.values.shape[0], self.values.shape[1]) == (1, 1):
data = self._repr_format()
return data.to_string()
else:
return self._summary_frame().__repr__()

except:
print("Triangle is empty")

def _summary_frame(self):
return pd.Series(
Expand All @@ -33,7 +39,7 @@ def _summary_frame(self):
).to_frame()

def _repr_html_(self):
""" Jupyter/Ipython HTML representation """
"""Jupyter/Ipython HTML representation"""
if (self.values.shape[0], self.values.shape[1]) == (1, 1):
data = self._repr_format()
fmt_str = self._get_format_str(data)
Expand Down Expand Up @@ -66,7 +72,7 @@ def _get_format_str(self, data):
def _repr_format(self, origin_as_datetime=False):
out = self.compute().set_backend("numpy").values[0, 0]
if origin_as_datetime and not self.is_pattern:
origin = self.origin.to_timestamp(how='s')
origin = self.origin.to_timestamp(how="s")
else:
origin = self.origin.copy()
origin.name = None
Expand All @@ -85,7 +91,7 @@ def _repr_format(self, origin_as_datetime=False):
return pd.DataFrame(out, index=origin, columns=development)

def heatmap(self, cmap="coolwarm", low=0, high=0, axis=0, subset=None):
""" Color the background in a gradient according to the data in each
"""Color the background in a gradient according to the data in each
column (optionally row). Requires matplotlib
Parameters
Expand Down Expand Up @@ -134,7 +140,12 @@ def heatmap(self, cmap="coolwarm", low=0, high=0, axis=0, subset=None):
else:
default_output = (
data.style.format(fmt_str)
.background_gradient(cmap=cmap, low=low, high=high, axis=axis,)
.background_gradient(
cmap=cmap,
low=low,
high=high,
axis=axis,
)
.render()
)
output_xnan = re.sub("<td.*nan.*td>", "<td></td>", default_output)
Expand Down

0 comments on commit fddc0a6

Please sign in to comment.