Repository navigation
Conversation
…s first hour HourlyContinuousCollection.group_by_month sliced one value too many for every month except the last, so the first hour of each month was also filed under the month before it. total_monthly, average_monthly, percentile_monthly and group_by_month itself were affected. Add tests that compare the month sizes with an independent calendar count, the datetime-based grouping, and constant, pulse and spike data. The existing monthly tests derived their expectations from group_by_month and could not catch this.
This branch has not been deployed
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.
PR summary
fix(collections): stop monthly grouping from counting the next month's first hour
Problem
HourlyContinuousCollection.group_by_monthreturned one value too many for every month except the last. The first hour of each month was filed under both its own month and the month before it. The affected methods are:group_by_monthtotal_monthlyaverage_monthlypercentile_monthlySymptoms
HourlyDiscontinuousCollection.group_by_month, which groups by datetime, returned the correct sizes for the same data.ashrae_climate_zoneandEPW.approximate_design_daycallaverage_monthly().Cause
In
datacollection.py:890,self._values[0:indx + 1]andself._values[indx:indx + interval + 1]slice one element past the end of each month. The last month was unaffected because its slice ends at the end of the data.Which commit introduced it
87db7595c7a936434ccce87d6a7453b0a256dfa3, on 2019-01-24, titled "perf(datacollection): refactor datacollection into mutiple classes". It first shipped in v0.1.0, so every release since is affected, including v0.44.62. That commit added a fasterHourlyContinuousCollectionoverride and left the generic datetime-basedgroup_by_monthfor other classes. I haven't asked the maintainer, but the+ 1looks like an accidental fence-post error.Please forgive me if I got this totally wrong.
The fix
Remove the two
+ 1offsets, so the slices are[0:indx]and[indx:indx + interval].Why the existing tests missed it
test_average_monthly,test_total_monthlyandtest_percentile_monthlybuild their expected values fromdc.group_by_month(), which has the same bug.Tests added
New tests in
datacollection_test.py. On the unfixed code, 28 of the 34 cases fail. The other 6 are the single-month periods, which were never affected.calendarmoduleVerification
git diff --checkis clean.Notes for reviewers
try/except IndexErrorin the same loop can never trigger, since slicing does not raise. I left it alone to keep this change minimal.