fix: guard against empty dict in clean_incrementing_reverse#3608
Merged
springfall2008 merged 2 commits intomainfrom Mar 20, 2026
Merged
fix: guard against empty dict in clean_incrementing_reverse#3608springfall2008 merged 2 commits intomainfrom
clean_incrementing_reverse#3608springfall2008 merged 2 commits intomainfrom
Conversation
Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com> Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/26f8b1a6-4742-493e-b4d7-7ec07e99c62d
Copilot
AI
changed the title
[WIP] Fix crash in clean_incrementing_reverse when history is empty
fix: guard against empty dict in Mar 20, 2026
clean_incrementing_reverse
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a startup crash in Predbat’s historical minute-data smoothing path by making clean_incrementing_reverse() a no-op when called with empty data (which can occur on fresh installs when history age results in days=0).
Changes:
- Add an early return in
clean_incrementing_reverse()whendatais empty to avoidmax(data)on an empty dict.
Comment on lines
650
to
+652
| new_data = {} | ||
| if not data: | ||
| return new_data |
There was a problem hiding this comment.
This guard fixes the crash, but there’s no regression test covering the specific failure mode (clean_increment=True with days=0 / empty mdata). Please add a unit test (e.g., in apps/predbat/tests/test_minute_data.py) that exercises minute_data() with days=0 and clean_increment=True and asserts it returns an empty dict without raising.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On fresh installs,
pv_todayhistory is often < 24 hours old (age.days == 0), producing an emptymdatadict that gets passed toclean_incrementing_reverse(), which immediately crashes onmax(data).Change
Added an early-return guard in
utils.py:Returning
{}is semantically correct — the caller (minute_data) already handles emptymdatagracefully, and there is nothing to smooth when no data exists.Original prompt
clean_incrementing_reversecrashes withValueError: max() arg is emptywhen history < 24 hours #3601💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.