Fix python 2.7/3.5 math support

This commit is contained in:
allegroai 2020-11-25 11:20:09 +02:00
parent 1651faac3d
commit 4aa5c620f4
2 changed files with 6 additions and 5 deletions

View File

@ -195,11 +195,12 @@ class Reporter(InterfaceBase, AbstractContextManager, SetupUploadMixin, AsyncMan
:type round_digits: int
"""
def floatstr(o):
inf_value = math.inf if six.PY3 else float("inf")
if o != o:
return 'nan'
elif o == math.inf:
elif o == inf_value:
return 'inf'
elif o == -math.inf:
elif o == -inf_value:
return '-inf'
return round(o, ndigits=round_digits) if round_digits is not None else o

View File

@ -344,9 +344,9 @@ class Logger(object):
reporter_table = table
else:
reporter_table = table.fillna(str(np.nan))
replace("NaN", np.nan, math.nan)
replace("Inf", np.inf, math.inf)
replace("-Inf", -np.inf, np.NINF, -math.inf)
replace("NaN", np.nan, math.nan if six.PY3 else float("nan"))
replace("Inf", np.inf, math.inf if six.PY3 else float("inf"))
replace("-Inf", -np.inf, np.NINF, -math.inf if six.PY3 else -float("inf"))
# noinspection PyProtectedMember
return self._task._reporter.report_table(
title=title,