Fix: PandasReporter with droplevels keeps one belief per event - #2595
Conversation
With droplevels, the reporter drops the source level and asserts one row per event, so an input sensor with an event reported by several sources made it fail. It now searches such inputs for one deterministic belief per event, unless an input sets one_deterministic_belief_per_event itself. Closes #2594 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Documentation build overview
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The newly added tests introduce unused local variables (likely flake8 F841) that should be cleaned up to avoid lint failures.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR fixes PandasReporter failures when droplevels: true is used and multiple data sources report the same event, by defaulting input searches to one_deterministic_belief_per_event=True (while still allowing per-input overrides). It adds regression tests covering the multi-source overlap case and the override behavior, plus a user-facing changelog entry.
Changes:
- Default
one_deterministic_belief_per_eventtodroplevelsviasetdefaultinPandasReporter.fetch_data. - Add tests ensuring
droplevelskeeps one belief per event when multiple sources overlap, and that explicit per-input overrides are respected. - Add a main changelog entry describing the bugfix.
| File | Description |
|---|---|
| flexmeasures/data/models/reporting/pandas_reporter.py | Default deterministic belief selection when droplevels is enabled to prevent duplicate events after dropping index levels |
| flexmeasures/data/models/reporting/tests/test_pandas_reporter.py | Add regression tests for multi-source overlap under droplevels and for respecting per-input overrides |
| documentation/changelog.rst | Document the bugfix in the main changelog |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Description
Closes #2594.
A
PandasReporterwithdroplevels: truedrops thesourcelevel of its inputs and asserts one row per event,so it failed with
AssertionError: BeliefDataframe has more than one row per event.as soon as an input event was reported by more than one data source.This showed up when porting a reporting job to an automation gave its results a new data source, and a downstream job reporting on a rolling window saw both sources until the window moved on.
droplevels, each input is now searched withone_deterministic_belief_per_event=True, asAggregatorReporterandProfitOrLossReporteralready do.setdefault: an input that setsone_deterministic_belief_per_eventitself keeps its value, instead of the keyword reachingsearch_beliefstwice (TypeError).How to test
pytest flexmeasures/data/models/reporting/tests/test_pandas_reporter.py -k droplevelstest_pandas_reporter_droplevels_with_several_sourcesuses the existing fixture data in which two sources report the same noon event. It fails onmainwith theAssertionErrorabove.test_pandas_reporter_droplevels_respects_input_overridechecks that an input's ownone_deterministic_belief_per_event: falseis respected. It fails with aTypeErrorif the flag is passed as a fixed keyword instead of a default.The whole reporting test package and the report CLI tests pass.
🤖 Generated with Claude Code