Skip to content

Commit

Permalink
Fix float highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Sep 9, 2020
1 parent beee39f commit 13c219a
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lab/reports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,18 @@ def _format(self, cells):
for dynamic_data_module in self.dynamic_data_modules:
dynamic_data_module.format(self, cells)

def _format_value(self, value):
if isinstance(value, float):
return f"{value:.{self.digits}f}"
else:
result = str(value)

# Only escape text if it doesn't contain LaTeX or HTML markup.
if "''" in result:
return result
else:
return markup.escape(result)

def _format_row(self, row_name, row):
"""Format all entries in **row** (in place)."""
if row_name == self.header_row:
Expand Down Expand Up @@ -730,7 +742,7 @@ def _format_row(self, row_name, row):

def is_close(a, b):
# Highlight based on precision visible in table, not actual values.
return math.isclose(a, b, abs_tol=10 ** -self.digits)
return self._format_value(a) == self._format_value(b)

for col_name, value in row.items():
color = None
Expand Down Expand Up @@ -770,19 +782,7 @@ def _format_cell(self, row_name, col_name, value, color=None, bold=False):

justify_right = isinstance(value, (float, int))

def format_value(value):
if isinstance(value, float):
return f"{value:.{self.digits}f}"
else:
result = str(value)

# Only escape text if it doesn't contain LaTeX or HTML markup.
if "''" in result:
return result
else:
return markup.escape(result)

value_text = format_value(value)
value_text = self._format_value(value)

if color is not None:
value_text = f"{{{value_text}|color:{color}}}"
Expand Down

0 comments on commit 13c219a

Please sign in to comment.