Skip to content

Commit 78756cd

Browse files
author
anomam
committed
Always return timestamped series and dataframe and test for that
1 parent 608863f commit 78756cd

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

pvlib/bifacial.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ def pvfactors_timeseries(
137137

138138
# Select the calculated outputs from the pvrow to observe
139139
ipoa_front = df_outputs.loc[:, idx_slice[index_observed_pvrow,
140-
'front', 'qinc']].values
140+
'front', 'qinc']]
141141

142142
ipoa_back = df_outputs.loc[:, idx_slice[index_observed_pvrow,
143-
'back', 'qinc']].values
143+
'back', 'qinc']]
144+
145+
# Set timestamps as index of df_registries for consistency of outputs
146+
df_registries = df_registries.set_index('timestamps')
144147

145148
return ipoa_front, ipoa_back, df_registries

pvlib/test/test_bifacial.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import numpy as np
21
import pandas as pd
32
from datetime import datetime
43
from pvlib.bifacial import pvfactors_timeseries
@@ -13,7 +12,8 @@ def test_pvfactors_timeseries():
1312

1413
# Create some inputs
1514
timestamps = pd.DatetimeIndex([datetime(2017, 8, 31, 11),
16-
datetime(2017, 8, 31, 12)])
15+
datetime(2017, 8, 31, 12)]
16+
).set_names('timestamps')
1717
solar_zenith = [20., 10.]
1818
solar_azimuth = [110., 140.]
1919
surface_tilt = [10., 0.]
@@ -31,47 +31,50 @@ def test_pvfactors_timeseries():
3131
horizon_band_angle = 15.
3232

3333
# Expected values
34-
expected_ipoa_front = [1034.96216923, 795.4423259]
35-
expected_ipoa_back = [92.11871485, 70.39404124]
36-
tolerance = 1e-6
34+
expected_ipoa_front = pd.Series([1034.96216923, 795.4423259],
35+
index=timestamps,
36+
name=(1, 'front', 'qinc'))
37+
expected_ipoa_back = pd.Series([92.11871485, 70.39404124],
38+
index=timestamps,
39+
name=(1, 'back', 'qinc'))
3740

3841
# Test serial calculations
39-
ipoa_front, ipoa_back, _ = pvfactors_timeseries(
42+
ipoa_front, ipoa_back, df_registries = pvfactors_timeseries(
4043
solar_azimuth, solar_zenith, surface_azimuth, surface_tilt,
4144
timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo,
4245
n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow,
4346
rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow,
4447
horizon_band_angle=horizon_band_angle,
4548
run_parallel_calculations=False, n_workers_for_parallel_calcs=None)
4649

47-
np.testing.assert_allclose(ipoa_front, expected_ipoa_front,
48-
atol=0, rtol=tolerance)
49-
np.testing.assert_allclose(ipoa_back, expected_ipoa_back,
50-
atol=0, rtol=tolerance)
50+
pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front)
51+
pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back)
52+
pd.testing.assert_index_equal(timestamps, df_registries.index.unique())
5153

5254
# Run calculations in parallel
53-
ipoa_front, ipoa_back, _ = pvfactors_timeseries(
55+
ipoa_front, ipoa_back, df_registries = pvfactors_timeseries(
5456
solar_azimuth, solar_zenith, surface_azimuth, surface_tilt,
5557
timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo,
5658
n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow,
5759
rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow,
5860
horizon_band_angle=horizon_band_angle,
5961
run_parallel_calculations=True, n_workers_for_parallel_calcs=None)
6062

61-
np.testing.assert_allclose(ipoa_front, expected_ipoa_front,
62-
atol=0, rtol=tolerance)
63-
np.testing.assert_allclose(ipoa_back, expected_ipoa_back,
64-
atol=0, rtol=tolerance)
63+
pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front)
64+
pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back)
65+
pd.testing.assert_index_equal(timestamps, df_registries.index.unique())
6566

6667

6768
@requires_pvfactors
6869
def test_pvfactors_timeseries_pandas_inputs():
6970
""" Test that pvfactors is functional, using the TLDR section inputs of the
70-
package github repo README.md file, but converted to pandas Series"""
71+
package github repo README.md file, but converted to pandas Series:
72+
https://github.com/SunPower/pvfactors/blob/master/README.md#tldr---quick-start"""
7173

7274
# Create some inputs
7375
timestamps = pd.DatetimeIndex([datetime(2017, 8, 31, 11),
74-
datetime(2017, 8, 31, 12)])
76+
datetime(2017, 8, 31, 12)]
77+
).set_names('timestamps')
7578
solar_zenith = pd.Series([20., 10.])
7679
solar_azimuth = pd.Series([110., 140.])
7780
surface_tilt = pd.Series([10., 0.])
@@ -89,34 +92,35 @@ def test_pvfactors_timeseries_pandas_inputs():
8992
horizon_band_angle = 15.
9093

9194
# Expected values
92-
expected_ipoa_front = [1034.96216923, 795.4423259]
93-
expected_ipoa_back = [92.11871485, 70.39404124]
94-
tolerance = 1e-6
95+
expected_ipoa_front = pd.Series([1034.96216923, 795.4423259],
96+
index=timestamps,
97+
name=(1, 'front', 'qinc'))
98+
expected_ipoa_back = pd.Series([92.11871485, 70.39404124],
99+
index=timestamps,
100+
name=(1, 'back', 'qinc'))
95101

96102
# Test serial calculations
97-
ipoa_front, ipoa_back, _ = pvfactors_timeseries(
103+
ipoa_front, ipoa_back, df_registries = pvfactors_timeseries(
98104
solar_azimuth, solar_zenith, surface_azimuth, surface_tilt,
99105
timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo,
100106
n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow,
101107
rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow,
102108
horizon_band_angle=horizon_band_angle,
103109
run_parallel_calculations=False, n_workers_for_parallel_calcs=None)
104110

105-
np.testing.assert_allclose(ipoa_front, expected_ipoa_front,
106-
atol=0, rtol=tolerance)
107-
np.testing.assert_allclose(ipoa_back, expected_ipoa_back,
108-
atol=0, rtol=tolerance)
111+
pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front)
112+
pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back)
113+
pd.testing.assert_index_equal(timestamps, df_registries.index.unique())
109114

110115
# Run calculations in parallel
111-
ipoa_front, ipoa_back, _ = pvfactors_timeseries(
116+
ipoa_front, ipoa_back, df_registries = pvfactors_timeseries(
112117
solar_azimuth, solar_zenith, surface_azimuth, surface_tilt,
113118
timestamps, dni, dhi, gcr, pvrow_height, pvrow_width, albedo,
114119
n_pvrows=n_pvrows, index_observed_pvrow=index_observed_pvrow,
115120
rho_front_pvrow=rho_front_pvrow, rho_back_pvrow=rho_back_pvrow,
116121
horizon_band_angle=horizon_band_angle,
117122
run_parallel_calculations=True, n_workers_for_parallel_calcs=None)
118123

119-
np.testing.assert_allclose(ipoa_front, expected_ipoa_front,
120-
atol=0, rtol=tolerance)
121-
np.testing.assert_allclose(ipoa_back, expected_ipoa_back,
122-
atol=0, rtol=tolerance)
124+
pd.testing.assert_series_equal(ipoa_front, expected_ipoa_front)
125+
pd.testing.assert_series_equal(ipoa_back, expected_ipoa_back)
126+
pd.testing.assert_index_equal(timestamps, df_registries.index.unique())

0 commit comments

Comments
 (0)