diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f35bf98..6a975a4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ New features Bug fixes ######### +* Fix leap year handling in VDI 4655 profiles Other changes ############# diff --git a/src/demandlib/vdi/regions.py b/src/demandlib/vdi/regions.py index cda6c29..83d6dd0 100644 --- a/src/demandlib/vdi/regions.py +++ b/src/demandlib/vdi/regions.py @@ -343,7 +343,7 @@ def _load_profile_factors(self, tl): # Create a table for every minute of the year minute_table = pd.DataFrame( index=pd.date_range( - f"1/1/{self._year}", periods=525600, freq="Min" + f"1/1/{self._year}", periods=self.hoy * 60, freq="Min" ) ) diff --git a/tests/test_vdi4655.py b/tests/test_vdi4655.py index e16c13e..1d4abf6 100644 --- a/tests/test_vdi4655.py +++ b/tests/test_vdi4655.py @@ -105,15 +105,25 @@ def test_resample_rule(self, example_houses): # Quarter-hourly data should have 4 times as many entries assert len(load_curves_quarter) == len(load_curves_hourly) * 4 - def test_leap_year(self): - """Test handling of leap years.""" - # region_leap = Region(2020, try_region=4) # Leap year - region_normal = Region( - 2017, Climate().from_try_data(4) - ) # Non-leap year - - # assert region_leap.hoy == 8784 # Hours in leap year - assert region_normal.hoy == 8760 # Hours in normal year + def test_leap_year(self, example_houses, example_holidays): + """Test generation of load curves for leap year.""" + climate = Climate().from_try_data(4) + climate.temperature = pd.concat( + [climate.temperature, climate.temperature.iloc[[-1]]] + ) + climate.cloud_coverage = pd.concat( + [climate.cloud_coverage, climate.cloud_coverage.iloc[[-1]]] + ) + + region = Region( + 2024, + climate=climate, + houses=example_houses, + holidays=example_holidays, + resample_rule="1h", + ) + load_curves = region.get_load_curve_houses() + assert len(load_curves) == 8784 # 366 days * 24 hours def test_temperature_limits(self, example_houses): """Test custom temperature limits."""