Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Next release
*Fixed*

* Table writer no longer errors on ``NaN`` scalar values (#2189).
* Table writer no longer errors on ``Inf`` scalar values (#2196).

6.0.0 (2025-11-21)
^^^^^^^^^^^^^^^^^^^^
Expand Down
18 changes: 18 additions & 0 deletions hoomd/pytest/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,21 @@ def test_nan_is_ok():
sim.operations.writers.append(table_writer)

sim.run(1)


def test_inf_is_ok():
# Ensure that Inf value doesn't cause table writer to error
sim = hoomd.util.make_example_simulation()

logger = hoomd.logging.Logger(categories=["scalar"])
logger[("test", "inf")] = (lambda: float("inf"), "scalar")

output = StringIO("")

table_writer = hoomd.write.Table(
trigger=1, logger=logger, output=output, delimiter=","
)

sim.operations.writers.append(table_writer)

sim.run(1)
4 changes: 3 additions & 1 deletion hoomd/write/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from abc import ABCMeta, abstractmethod
import copy
from numbers import Integral
from math import log10, isnan
from math import log10, isnan, isinf
from sys import stdout
import inspect

Expand Down Expand Up @@ -128,6 +128,8 @@ def format_num(self, value, column_width):
# point including the decimal point.
if isnan(value):
return "NaN"
if isinf(value):
return "Inf"
min_len_repr = self._digits_from_decimal(value) + 1
# Use scientific formatting
if not min_len_repr < 6 or min_len_repr > column_width:
Expand Down