Skip to content

Commit bba49c0

Browse files
authored
Add simple_efficiency tests for numpy array inputs (#2661)
* Add simple_efficiency tests for numpy array inputs * fix flake * flake8 fix after resolving conflicts * removing test_simple_efficiency_numpy_array_inputs * add whatsnew entry for simple_efficiency vectorization test * addressing review comments
1 parent eb5e8bd commit bba49c0

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

docs/sphinx/source/whatsnew/v0.15.1.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Documentation
2929

3030
Testing
3131
~~~~~~~
32-
32+
* Add test to verify that :py:func:`~pvlib.transformer.simple_efficiency`
33+
produces consistent results for vectorized and scalar inputs.
34+
(:issue:`2649`, :pull:`2661`)
3335

3436
Benchmarking
3537
~~~~~~~~~~~~

tests/test_transformer.py

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from pvlib import transformer
77

8+
import numpy as np
9+
810

911
def test_simple_efficiency():
1012

@@ -41,42 +43,50 @@ def test_simple_efficiency():
4143
assert_allclose(calculated_output_power, expected_output_power)
4244

4345

44-
def test_simple_efficiency_known_values():
45-
no_load_loss = 0.005
46-
load_loss = 0.01
47-
rating = 1000
48-
args = (no_load_loss, load_loss, rating)
49-
50-
# verify correct behavior at no-load condition
51-
assert_allclose(
52-
transformer.simple_efficiency(no_load_loss*rating, *args),
53-
0.0
54-
)
55-
56-
# verify correct behavior at rated condition
57-
assert_allclose(
58-
transformer.simple_efficiency(rating*(1 + no_load_loss + load_loss),
59-
*args),
60-
rating,
61-
)
62-
63-
6446
@pytest.mark.parametrize(
65-
"input_power, no_load_loss, load_loss, transformer_rating, expected",
47+
"input_power, no_load_loss, load_loss, rating, expected",
6648
[
49+
# no-load condition
50+
(0.005 * 1000, 0.005, 0.01, 1000, 0.0),
51+
52+
# rated condition
53+
(1000 * (1 + 0.005 + 0.01), 0.005, 0.01, 1000, 1000),
54+
55+
# zero load_loss case
56+
# for load_loss = 0, the model reduces to:
57+
# P_out = P_in - L_no_load * P_nom
6758
(1000.0, 0.01, 0.0, 1000.0, 990.0),
6859
],
6960
)
70-
def test_simple_efficiency_zero_load_loss(
71-
input_power, no_load_loss, load_loss, transformer_rating, expected
61+
def test_simple_efficiency_numeric_cases(
62+
input_power, no_load_loss, load_loss, rating, expected
7263
):
73-
# for load_loss = 0, the model reduces to:
74-
# P_out = P_in - L_no_load * P_nom
7564
result = transformer.simple_efficiency(
7665
input_power=input_power,
7766
no_load_loss=no_load_loss,
7867
load_loss=load_loss,
79-
transformer_rating=transformer_rating,
68+
transformer_rating=rating,
8069
)
8170

8271
assert_allclose(result, expected)
72+
73+
74+
def test_simple_efficiency_vector_equals_scalar():
75+
input_power = np.array([200.0, 600.0, 900.0])
76+
no_load_loss = 0.005
77+
load_loss = 0.01
78+
rating = 1000.0
79+
80+
vector_result = transformer.simple_efficiency(
81+
input_power=input_power,
82+
no_load_loss=no_load_loss,
83+
load_loss=load_loss,
84+
transformer_rating=rating,
85+
)
86+
87+
scalar_result = np.array([
88+
transformer.simple_efficiency(p, no_load_loss, load_loss, rating)
89+
for p in input_power
90+
])
91+
92+
assert_allclose(vector_result, scalar_result)

0 commit comments

Comments
 (0)