Repository navigation
Description
Summary
DBEsoFile.frequencies raises KeyError: '' for every .eso file produced by EnergyPlus 10.0 or newer (i.e. all currently supported versions). The root cause is get_eso_file_version, which mis-parses two-digit major versions, and the same bug also breaks parsing of annual outputs.
Reproduction
from db_eplusout_reader.db_esofile import DBEsoFileCollection
collection = DBEsoFileCollection.from_path("tests/test_files/252_1ZoneUncontrolled.eso")
collection[0].frequenciesKeyError: ''
The same happens for tests/test_files/231_1ZoneUncontrolled.eso and tests/test_files/251_1ZoneUncontrolled.eso. tests/test_files/920_eplusout.eso (EnergyPlus 9.2) works and returns ['hourly', 'daily', 'monthly', 'runperiod'].
Root cause
get_eso_file_version (db_eplusout_reader/processing/esofile_reader.py:34) takes a fixed five-character slice of the version string and strips the dots:
return int(version[(start + 1) : (start + 6)].replace(".", ""))That was written for single-digit majors:
| Version string | Parsed as |
|---|---|
Version 9.2.0-921312fa1d |
920 |
Version 23.1.0-87ed9199d4 |
231 |
Version 25.2.0-cf7368216c |
252 |
So every version from 10.0 onwards parses to a number well below the 890 threshold used in read_file (esofile_reader.py:317):
last_standard_item_id = 6 if version >= 890 else 5Modern files are therefore treated as pre-8.9 files, with two consequences:
-
Only 5 of the 6 standard dictionary lines are skipped, so line 7 of the file —
6,1,Calendar Year of Simulation[] ! When Annual Report Variables Requested—
is parsed as a normal header line. It has no!<Frequency>token, so it lands in the header
under the frequency key'', which is missing from theordermap in
DBEsoFile.frequencies(db_eplusout_reader/db_esofile.py:126) and raisesKeyError. -
last_standard_item_idis also passed toread_bodyashighest_frequency_id, so the
annual frequency line (id6) in the body is treated as a result value instead of a
frequency marker. Any file that actually contains annual outputs fails to parse at all:File "db_eplusout_reader/processing/esofile_reader.py", line 301, in read_body raw_outputs.outputs[frequency][line_id][-1] = res KeyError: 6(Verified with a minimal hand-written
.esocontaining one!Annualvariable: it parses
correctly when the version line says9.2.0and raises the above when it says25.2.0.)
Suggested fix
- Parse the version properly, e.g. split the
major.minornumbers out of the version string and compare as a tuple, or normalise to a sortable integer that works for two-digit majors. Whatever form is chosen,read_fileshould compare against the 8.9 boundary correctly. - Alternatively / additionally, make
DBEsoFile.frequenciesrobust to unknown keys rather than indexingorderdirectly, so a future unexpected token degrades gracefully instead of raising.
Test coverage
There is currently no test exercising DBEsoFile.frequencies, and no .eso test file containing annual outputs (there is a resources/252_1ZoneUncontrolledAnnualOutputs.idf but no generated .eso in tests/test_files/). Suggested additions:
- Unit tests for
get_eso_file_version/process_statement_linecovering9.2.0,23.1.0and25.2.0. - A cross-version regression test in
tests/test_eso_versions.pyassertingfrequenciesonany_eso_file. - An
.esofixture with annual outputs to cover theread_bodypath.
Activity