Skip to content

Commit fe28d42

Browse files
Increase test coverage for simple_efficiency and clarify loss parameter docs
1 parent b3a3782 commit fe28d42

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

pvlib/transformer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ def simple_efficiency(
2727
input_power : numeric
2828
The real AC power input to the transformer. [W]
2929
30-
no_load_loss : numeric
30+
no_load_loss : float
3131
The constant losses experienced by a transformer, even
32-
when the transformer is not under load. Fraction of transformer rating,
33-
value from 0 to 1. [unitless]
32+
when the transformer is not under load. Fraction of transformer rating, value from 0 to 1. [unitless]
3433
35-
load_loss: numeric
34+
load_loss: float
3635
The load dependent losses experienced by the transformer.
3736
Fraction of transformer rating, value from 0 to 1. [unitless]
3837

tests/test_transformer.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pandas as pd
2+
import numpy as np
3+
import pytest
24

35
from numpy.testing import assert_allclose
4-
6+
from pvlib.transformer import simple_efficiency
57
from pvlib import transformer
68

79

@@ -48,13 +50,47 @@ def test_simple_efficiency_known_values():
4850

4951
# verify correct behavior at no-load condition
5052
assert_allclose(
51-
transformer.simple_efficiency(no_load_loss*rating, *args),
53+
transformer.simple_efficiency(no_load_loss * rating, *args),
5254
0.0
5355
)
5456

5557
# verify correct behavior at rated condition
5658
assert_allclose(
57-
transformer.simple_efficiency(rating*(1 + no_load_loss + load_loss),
58-
*args),
59+
transformer.simple_efficiency(
60+
rating * (1 + no_load_loss + load_loss),
61+
*args
62+
),
5963
rating,
6064
)
65+
66+
67+
# =========================
68+
# NEW TESTS (Issue #2649)
69+
# =========================
70+
71+
def test_simple_efficiency_numpy_input_power():
72+
input_power = np.array([500, 1000, 1500])
73+
no_load_loss = 0.01
74+
load_loss = 0.02
75+
transformer_rating = 2000
76+
77+
output = simple_efficiency(
78+
input_power, no_load_loss, load_loss, transformer_rating
79+
)
80+
81+
assert isinstance(output, np.ndarray)
82+
assert output.shape == input_power.shape
83+
84+
85+
def test_simple_efficiency_zero_load_loss():
86+
input_power = np.array([500, 1000])
87+
no_load_loss = 0.01
88+
load_loss = 0.0
89+
transformer_rating = 2000
90+
91+
with pytest.warns(RuntimeWarning):
92+
output = simple_efficiency(
93+
input_power, no_load_loss, load_loss, transformer_rating
94+
)
95+
96+
assert np.all(np.isnan(output))

0 commit comments

Comments
 (0)