Skip to content

Commit

Permalink
Merge pull request #80 from NREL/CatchBadNumerics
Browse files Browse the repository at this point in the history
Handle strange numerics in CSV
  • Loading branch information
Myoldmopar committed Nov 8, 2021
2 parents 933c3cd + 74b15ab commit 3b45453
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion epregressions/diffs/math_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ def dict_of_dicts2dict_of_lists(dict_of_dicts, key_order, list_labels):
for key in key_order:
dict_of_lists[key] = []
for ll in list_labels:
dict_of_lists[key].append(dict_of_dicts[key][ll])
try:
dict_of_lists[key].append(dict_of_dicts[key][ll])
except ValueError:
print(f"Encountered a ValueError, trying to find key: {ll}, can be caused by malformed CSV numerics")
raise
return dict_of_lists


Expand Down
25 changes: 25 additions & 0 deletions epregressions/tests/diffs/csv_resources/eplusout_bad_numeric.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Date/Time,Environment:Site Outdoor Air Wetbulb Temperature [C](Hourly),WEST ZONE:Zone Air System Sensible Heating Rate [W](Hourly),WEST ZONE:Zone Air System Sensible Cooling Rate [W](Hourly)
01/21 01:00:00,20.5999,48620.76450.0
01/21 02:00:00,20.5999,49227.47950.0
01/21 03:00:00,20.5999,49824.70480.0
01/21 04:00:00,20.5999,50339.72300.0
01/21 05:00:00,20.5999,50787.90430.0
01/21 06:00:00,20.5999,51220.80220.0
01/21 07:00:00,20.5999,51594.31630.0
01/21 08:00:00,20.5999,92827.72790.0
01/21 09:00:00,20.5999,83743.07730.0
01/21 10:00:00,20.5999,81058.18110.0
01/21 11:00:00,20.5999,78987.43000.0
01/21 12:00:00,20.5999,77362.27870.0
01/21 13:00:00,20.5999,76066.99400.0
01/21 14:00:00,20.5999,74923.00170.0
01/21 15:00:00,20.5999,73972.79390.0
01/21 16:00:00,20.5999,73148.68060.0
01/21 17:00:00,20.5999,72468.10000.0
01/21 18:00:00,20.5999,31805.57580.0
01/21 19:00:00,20.5999,41006.69260.0
01/21 20:00:00,20.5999,43051.07830.0
01/21 21:00:00,20.5999,44624.37680.0
01/21 22:00:00,20.5999,45894.46180.0
01/21 23:00:00,20.5999,46968.05140.0
01/21 24:00:00,20.5999,47805.01140.0
13 changes: 13 additions & 0 deletions epregressions/tests/diffs/test_math_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ def test_small_diff_in_watts_files(self):
self.assertEqual(0, response[2]) # big diffs
self.assertEqual(2, response[3]) # small diffs

def test_bad_numeric_raises_exception(self):
"""This tests the ability to handle bad numerics which cause weird errors in MathDiff"""
with self.assertRaises(KeyError):
math_diff(
self.thresh_dict,
os.path.join(self.diff_files_dir, 'eplusout.csv'),
os.path.join(self.diff_files_dir, 'eplusout_bad_numeric.csv'),
os.path.join(self.temp_output_dir, 'abs_diff.csv'),
os.path.join(self.temp_output_dir, 'rel_diff.csv'),
os.path.join(self.temp_output_dir, 'math_diff.log'),
os.path.join(self.temp_output_dir, 'summary.csv'),
)

def test_big_diff_in_watts_files(self):
"""This tests the ability to capture diffs in a regular (not-temperature) variable"""
response = math_diff(
Expand Down

0 comments on commit 3b45453

Please sign in to comment.