Skip to content

Commit 52e1a50

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 0e9a985 + 75d092e commit 52e1a50

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

pvlib/bifacial.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ def build(report, pvarray):
159159
back surface of center pvrow (index=1)"""
160160
# Initialize the report as a dictionary
161161
if report is None:
162-
list_keys = ['total_inc_back', 'total_inc_front']
163-
report = {key: [] for key in list_keys}
162+
report = {'total_inc_back': [], 'total_inc_front': []}
164163
# Add elements to the report
165164
if pvarray is not None:
166165
pvrow = pvarray.pvrows[1] # use center pvrow
@@ -177,13 +176,12 @@ def build(report, pvarray):
177176

178177
@staticmethod
179178
def merge(reports):
180-
"""Works for dictionary reports"""
179+
"""Works for dictionary reports. Merges the reports list of
180+
dictionaries in a single dictionary. The list of the first
181+
dictionary are extended by those of all subsequent lists."""
181182
report = reports[0]
182-
# Merge only if more than 1 report
183-
if len(reports) > 1:
184-
keys_report = list(reports[0].keys())
185-
for other_report in reports[1:]:
186-
if other_report is not None:
187-
for key in keys_report:
188-
report[key] += other_report[key]
183+
keys_report = list(report.keys())
184+
for other_report in reports[1:]: # loop won't run if len(reports) < 2
185+
for key in keys_report:
186+
report[key] += other_report[key]
189187
return report

pvlib/test/test_bifacial.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pandas as pd
2+
import numpy as np
23
from datetime import datetime
3-
from pvlib.bifacial import pvfactors_timeseries
4+
from pvlib.bifacial import pvfactors_timeseries, PVFactorsReportBuilder
45
from conftest import requires_pvfactors
56
import pytest
67

@@ -107,3 +108,43 @@ def test_pvfactors_timeseries_pandas_inputs(run_parallel_calculations):
107108

108109
pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front)
109110
pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back)
111+
112+
113+
def test_build_1():
114+
"""Test that build correctly instantiates a dictionary, when passed a Nones
115+
for the report and pvarray arguments.
116+
"""
117+
report = None
118+
pvarray = None
119+
expected = {'total_inc_back': [np.nan], 'total_inc_front': [np.nan]}
120+
assert expected == PVFactorsReportBuilder.build(report, pvarray)
121+
122+
123+
def test_merge_1():
124+
"""Test that merge correctly returns the first element of the reports
125+
argument when there is only dictionary in reports.
126+
"""
127+
test_dict = {'total_inc_back': [1, 2, 3], 'total_inc_front': [4, 5, 6]}
128+
reports = [test_dict]
129+
assert test_dict == PVFactorsReportBuilder.merge(reports)
130+
131+
132+
def test_merge_2():
133+
"""Test that merge correctly combines two dictionary reports.
134+
"""
135+
test_dict_1 = {'total_inc_back': [1, 2], 'total_inc_front': [4, 5]}
136+
test_dict_2 = {'total_inc_back': [3], 'total_inc_front': [6]}
137+
expected = {'total_inc_back': [1, 2, 3], 'total_inc_front': [4, 5, 6]}
138+
reports = [test_dict_1, test_dict_2]
139+
assert expected == PVFactorsReportBuilder.merge(reports)
140+
141+
142+
def test_merge_3():
143+
"""Test that merge correctly combines three dictionary reports.
144+
"""
145+
test_dict_1 = {'total_inc_back': [1], 'total_inc_front': [4]}
146+
test_dict_2 = {'total_inc_back': [2], 'total_inc_front': [5]}
147+
test_dict_3 = {'total_inc_back': [3], 'total_inc_front': [6]}
148+
expected = {'total_inc_back': [1, 2, 3], 'total_inc_front': [4, 5, 6]}
149+
reports = [test_dict_1, test_dict_2, test_dict_3]
150+
assert expected == PVFactorsReportBuilder.merge(reports)

0 commit comments

Comments
 (0)