Skip to content

Commit

Permalink
Merge pull request #934 from mcdo0486/fix/results_typecheck
Browse files Browse the repository at this point in the history
Regression: fix CSVFormatter.format not recording np.float types
  • Loading branch information
BenediktBurger committed Jun 27, 2023
2 parents 3e16918 + e01ce29 commit 68f5487
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 1 addition & 3 deletions pymeasure/experiment/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ def unique_filename(directory, prefix='DATA', suffix='', ext='csv',
class CSVFormatter(logging.Formatter):
""" Formatter of data results """

numeric_types = (float, int, Decimal)

def __init__(self, columns, delimiter=','):
"""Creates a csv formatter for a given list of columns (=header).
Expand All @@ -146,7 +144,7 @@ def format(self, record):
line = []
for x in self.columns:
value = record.get(x, float("nan"))
if type(value) in self.numeric_types:
if isinstance(value, (float, int, Decimal)) and type(value) is not bool:
line.append(f"{value}")
else:
units = self.units.get(x, None)
Expand Down
4 changes: 3 additions & 1 deletion tests/experiment/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def test_csv_formatter_format(self):
('magnetic (T)', 7, "7"),
('string', "abcdef", "abcdef"),
('count', 9 * ureg.dimensionless, "9"),
('boolean', True, "True")
('boolean', True, "True"),
('numpy (V)', np.float64(1.1), "1.1"),
('boolean nan (V)', True, "nan"),
))
def test_unitful(self, head, value, result):
"""Test, whether units are appended correctly"""
Expand Down

0 comments on commit 68f5487

Please sign in to comment.