Skip to content

refactor bifacial merge, improve merge tests #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0d4cb80
Simplify merge method.
alexandermorgan Jul 8, 2019
55d8f08
Update what's new doc.
alexandermorgan Jul 8, 2019
c969994
Update whatsnew file syntax.
alexandermorgan Jul 8, 2019
93d0559
Rename whatsnew file to change format to rst.
alexandermorgan Jul 8, 2019
e244343
Fix linting errors.
alexandermorgan Jul 8, 2019
84d7189
Remove pandas and numpy version reqs
alexandermorgan Jul 9, 2019
d131657
Update v0.7.1.rst
alexandermorgan Jul 9, 2019
94f2db5
Revert "Update v0.7.1.rst"
alexandermorgan Jul 9, 2019
4fdb599
Revert "Remove pandas and numpy version reqs"
alexandermorgan Jul 9, 2019
d1429d5
Merge branch 'master' into bifacial_dicts
alexandermorgan Jul 9, 2019
e12b807
Reword elements in merge() comprehension.
alexandermorgan Jul 10, 2019
25da151
Fix handling of None values in merge.
alexandermorgan Jul 10, 2019
feb7bf3
Remove unnecessary checks in merge().
alexandermorgan Jul 11, 2019
079bb48
Add tests for merge() and build().
alexandermorgan Jul 11, 2019
2189952
Fix lint errors.
alexandermorgan Jul 11, 2019
39c2889
Correct import mistake.
alexandermorgan Jul 12, 2019
eeb8053
Reinsert type check in merge loop.
alexandermorgan Jul 12, 2019
465d228
Revert "Reinsert type check in merge loop."
alexandermorgan Jul 12, 2019
c108362
Fix test_build_1 test.
alexandermorgan Jul 12, 2019
4447e6c
Update what's new file.
alexandermorgan Jul 12, 2019
74c8eba
Fix merge conflicts in what's new file.
alexandermorgan Jul 12, 2019
4eaf93f
Revert "Fix merge conflicts in what's new file."
alexandermorgan Jul 13, 2019
b2ed214
Revert "Update what's new file."
alexandermorgan Jul 13, 2019
c2fbecb
Revert "Rename whatsnew file to change format to rst."
alexandermorgan Jul 13, 2019
fa9b64a
Revert "Update whatsnew file syntax."
alexandermorgan Jul 13, 2019
be8ec1c
Revert "Update what's new doc."
alexandermorgan Jul 13, 2019
80809f2
Merge what's new updates from upstream.
alexandermorgan Jul 13, 2019
797dc83
Update what's new file.
alexandermorgan Jul 13, 2019
bd0740a
Merge branch 'master' into bifacial_dicts
alexandermorgan Jul 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/sphinx/source/whatsnew/v0.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a major release that drops support for Python 2 and Python 3.4. We
recommend all users of v0.6.3 upgrade to this release after checking API
compatibility notes.

**Python 2.7 support ended on June 1, 2019**. (:issue:`501`)
**Python 2.7 support ended on June 1, 2019.** (:issue:`501`)
**Minimum numpy version is now 1.10.4. Minimum pandas version is now 0.18.1.**

Bug fixes
Expand All @@ -18,10 +18,12 @@ Bug fixes
Testing
~~~~~~~
* Added 30 minutes to timestamps in `test_psm3.csv` to match change in NSRDB (:issue:`733`)
* Added tests for methods in bifacial.py.


Contributors
~~~~~~~~~~~~
* Mark Campanellli (:ghuser:`markcampanelli`)
* Will Holmgren (:ghuser:`wholmgren`)
* Oscar Dowson (:ghuser:`odow`)
* Alexander Morgan (:ghuser:`alexandermorgan`)
18 changes: 8 additions & 10 deletions pvlib/bifacial.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ def build(report, pvarray):
back surface of center pvrow (index=1)"""
# Initialize the report as a dictionary
if report is None:
list_keys = ['total_inc_back', 'total_inc_front']
report = {key: [] for key in list_keys}
report = {'total_inc_back': [], 'total_inc_front': []}
# Add elements to the report
if pvarray is not None:
pvrow = pvarray.pvrows[1] # use center pvrow
Expand All @@ -177,13 +176,12 @@ def build(report, pvarray):

@staticmethod
def merge(reports):
"""Works for dictionary reports"""
"""Works for dictionary reports. Merges the reports list of
dictionaries in a single dictionary. The list of the first
dictionary are extended by those of all subsequent lists."""
report = reports[0]
# Merge only if more than 1 report
if len(reports) > 1:
keys_report = list(reports[0].keys())
for other_report in reports[1:]:
if other_report is not None:
for key in keys_report:
report[key] += other_report[key]
keys_report = list(report.keys())
for other_report in reports[1:]: # loop won't run if len(reports) < 2
for key in keys_report:
report[key] += other_report[key]
return report
43 changes: 42 additions & 1 deletion pvlib/test/test_bifacial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pandas as pd
import numpy as np
from datetime import datetime
from pvlib.bifacial import pvfactors_timeseries
from pvlib.bifacial import pvfactors_timeseries, PVFactorsReportBuilder
from conftest import requires_pvfactors
import pytest

Expand Down Expand Up @@ -107,3 +108,43 @@ def test_pvfactors_timeseries_pandas_inputs(run_parallel_calculations):

pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front)
pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back)


def test_build_1():
"""Test that build correctly instantiates a dictionary, when passed a Nones
for the report and pvarray arguments.
"""
report = None
pvarray = None
expected = {'total_inc_back': [np.nan], 'total_inc_front': [np.nan]}
assert expected == PVFactorsReportBuilder.build(report, pvarray)


def test_merge_1():
"""Test that merge correctly returns the first element of the reports
argument when there is only dictionary in reports.
"""
test_dict = {'total_inc_back': [1, 2, 3], 'total_inc_front': [4, 5, 6]}
reports = [test_dict]
assert test_dict == PVFactorsReportBuilder.merge(reports)


def test_merge_2():
"""Test that merge correctly combines two dictionary reports.
"""
test_dict_1 = {'total_inc_back': [1, 2], 'total_inc_front': [4, 5]}
test_dict_2 = {'total_inc_back': [3], 'total_inc_front': [6]}
expected = {'total_inc_back': [1, 2, 3], 'total_inc_front': [4, 5, 6]}
reports = [test_dict_1, test_dict_2]
assert expected == PVFactorsReportBuilder.merge(reports)


def test_merge_3():
"""Test that merge correctly combines three dictionary reports.
"""
test_dict_1 = {'total_inc_back': [1], 'total_inc_front': [4]}
test_dict_2 = {'total_inc_back': [2], 'total_inc_front': [5]}
test_dict_3 = {'total_inc_back': [3], 'total_inc_front': [6]}
expected = {'total_inc_back': [1, 2, 3], 'total_inc_front': [4, 5, 6]}
reports = [test_dict_1, test_dict_2, test_dict_3]
assert expected == PVFactorsReportBuilder.merge(reports)