Skip to content
Open
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from pvlib import transformer

import numpy as np


def test_simple_efficiency():

Expand Down Expand Up @@ -58,3 +60,41 @@ def test_simple_efficiency_known_values():
*args),
rating,
)


def test_simple_efficiency_numpy_array_inputs():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aman-coder03 I think it is premature to test with all inputs as np.array. In other discussions we don't have consensus to allow the parameters no_load_loss and load_loss to be anything other than float, and intend to edit the docstring accordingly.

If we agree in the future to allow vectors for these parameters, then this test would be needed.

I don't want to include it now so to prevent someone's AI from deciding we have missed a combination of types in other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer that I remove the test that uses array inputs for no_load_loss and load_loss, and keep only the vectorized input_power case? Or should I drop the vectorized tests entirely for now?

input_power = np.array([100.0, 500.0, 1000.0])
no_load_loss = np.array([0.005, 0.005, 0.005])
load_loss = np.array([0.01, 0.01, 0.01])
rating = 1000.0

output_power = transformer.simple_efficiency(
input_power=input_power,
no_load_loss=no_load_loss,
load_loss=load_loss,
transformer_rating=rating
)

assert isinstance(output_power, np.ndarray)
assert output_power.shape == input_power.shape


def test_simple_efficiency_vector_equals_scalar():
input_power = np.array([200.0, 600.0, 900.0])
no_load_loss = 0.005
load_loss = 0.01
rating = 1000.0

vector_result = transformer.simple_efficiency(
input_power=input_power,
no_load_loss=no_load_loss,
load_loss=load_loss,
transformer_rating=rating
)

scalar_result = np.array([
transformer.simple_efficiency(p, no_load_loss, load_loss, rating)
for p in input_power
])

assert_allclose(vector_result, scalar_result)