Skip to content

KeyError when an .eso data line has an undeclared report ID #39

Closed

Description

@btokarzewskidb

Summary

DBEsoFileCollection.from_path() raises a bare KeyError when a data line's report ID is not declared for the current frequency in the file's data dictionary. One such line is enough to stop the whole file loading.

Reproduce

Using main at 27f36ef, take any valid .eso file and insert one data line with an undeclared ID just before End of Data:

...
99999,42.0
End of Data
from db_eplusout_reader import DBEsoFileCollection
DBEsoFileCollection.from_path("unknown_id.eso")
  File "db_eplusout_reader/processing/esofile_reader.py", line 312, in read_body
    raw_outputs.outputs[frequency][line_id][-1] = res
KeyError: 99999

I found this when comparing the reader with idfkit's ESO parser. idfkit's edge-case test (tests/test_simulation_eso_parser.py::test_unknown_report_id_is_skipped) uses exactly this input and skips the line. All 1,654 variable/environment series in the files I compared matched idfkit's values exactly, so this was the only real difference.

Cause

In read_body, a result line is written straight to raw_outputs.outputs[frequency][line_id]. There's no check that line_id was declared for the current frequency.

Suggested fix

Skip result lines whose ID has no output slot for the current frequency, and log them at debug level instead of failing the whole file. Add a test with an injected unknown ID, checking that every declared variable still reads correctly.

EnergyPlus shouldn't write such lines itself, so this is about robustness: hand-edited or post-processed files, or files joined from several runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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