Skip to content

KeyError in DBEsoFile.frequencies for EnergyPlus 10.0+ files (version string mis-parsed) #32

Closed

Description

@voightp

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].frequencies
KeyError: ''

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 5

Modern files are therefore treated as pre-8.9 files, with two consequences:

  1. 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 the order map in
    DBEsoFile.frequencies (db_eplusout_reader/db_esofile.py:126) and raises KeyError.

  2. last_standard_item_id is also passed to read_body as highest_frequency_id, so the
    annual frequency line (id 6) 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 .eso containing one !Annual variable: it parses
    correctly when the version line says 9.2.0 and raises the above when it says 25.2.0.)

Suggested fix

  • Parse the version properly, e.g. split the major.minor numbers 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_file should compare against the 8.9 boundary correctly.
  • Alternatively / additionally, make DBEsoFile.frequencies robust to unknown keys rather than indexing order directly, 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_line covering 9.2.0, 23.1.0 and 25.2.0.
  • A cross-version regression test in tests/test_eso_versions.py asserting frequencies on any_eso_file.
  • An .eso fixture with annual outputs to cover the read_body path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions