From b1cb161f8ea16849c5060b697c4542db85c33b7b Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 18 Jan 2026 15:26:54 +0530 Subject: [PATCH 1/4] Fix division-by-zero in transformer.simple_efficiency --- pvlib/transformer.py | 3 ++- tests/test_transformer.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pvlib/transformer.py b/pvlib/transformer.py index 3b66b0beb3..3fea282e2b 100644 --- a/pvlib/transformer.py +++ b/pvlib/transformer.py @@ -111,7 +111,8 @@ def simple_efficiency( b = 1 c = no_load_loss - input_power_normalized - output_power_normalized = (-b + (b**2 - 4*a*c)**0.5) / (2 * a) + disc = (b*b - 4*a*c)**0.5 + output_power_normalized = 2*c / (-b - disc) output_power = output_power_normalized * transformer_rating return output_power diff --git a/tests/test_transformer.py b/tests/test_transformer.py index 0739a9e95a..7d7a106a3b 100644 --- a/tests/test_transformer.py +++ b/tests/test_transformer.py @@ -1,4 +1,5 @@ import pandas as pd +import pytest from numpy.testing import assert_allclose @@ -58,3 +59,24 @@ def test_simple_efficiency_known_values(): *args), rating, ) + + +@pytest.mark.parametrize( + "input_power, no_load_loss, load_loss, transformer_rating, expected", + [ + (1000.0, 0.01, 0.0, 1000.0, 990.0), + ], +) +def test_simple_efficiency_zero_load_loss( + input_power, no_load_loss, load_loss, transformer_rating, expected +): + # for load_loss = 0, the model reduces to: + # P_out = P_in - L_no_load * P_nom + result = transformer.simple_efficiency( + input_power=input_power, + no_load_loss=no_load_loss, + load_loss=load_loss, + transformer_rating=transformer_rating, + ) + + assert_allclose(result, expected) From 0028bb6294358c989c392f87ffaa571b3f0dc52e Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 18 Jan 2026 15:29:42 +0530 Subject: [PATCH 2/4] fix flake8 --- tests/test_transformer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_transformer.py b/tests/test_transformer.py index 7d7a106a3b..48f11e0a45 100644 --- a/tests/test_transformer.py +++ b/tests/test_transformer.py @@ -79,4 +79,4 @@ def test_simple_efficiency_zero_load_loss( transformer_rating=transformer_rating, ) - assert_allclose(result, expected) + assert_allclose(result, expected) From bb83bbd72b37ec48600d37c6c2b78885000ee82b Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 21 Jan 2026 22:55:04 +0530 Subject: [PATCH 3/4] Add whatsnew note for simple_efficiency division-by-zero fix --- docs/sphinx/source/whatsnew/v0.14.1.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.14.1.rst b/docs/sphinx/source/whatsnew/v0.14.1.rst index 3a15193886..07c3ca4be5 100644 --- a/docs/sphinx/source/whatsnew/v0.14.1.rst +++ b/docs/sphinx/source/whatsnew/v0.14.1.rst @@ -14,7 +14,9 @@ Deprecations Bug fixes ~~~~~~~~~ - +* Fix a division-by-zero condition in + :py:func:`~pvlib.transformer.simple_efficiency` when ``load_loss = 0``. + (:issue:`2645`) Enhancements ~~~~~~~~~~~~ @@ -42,4 +44,5 @@ Maintenance Contributors ~~~~~~~~~~~~ +* Aman Srivastava (:ghuser:`aman-coder03`) From f8b12ff6d28fd1040e0980f4e52102b49d017bab Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Fri, 23 Jan 2026 09:24:29 +0530 Subject: [PATCH 4/4] fixing docs --- docs/sphinx/source/whatsnew/v0.14.1.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.14.1.rst b/docs/sphinx/source/whatsnew/v0.14.1.rst index 07c3ca4be5..53a07adf3f 100644 --- a/docs/sphinx/source/whatsnew/v0.14.1.rst +++ b/docs/sphinx/source/whatsnew/v0.14.1.rst @@ -15,8 +15,8 @@ Deprecations Bug fixes ~~~~~~~~~ * Fix a division-by-zero condition in - :py:func:`~pvlib.transformer.simple_efficiency` when ``load_loss = 0``. - (:issue:`2645`) + :py:func:`pvlib.transformer.simple_efficiency` when ``load_loss = 0``. + (:issue:`2645`, :pull:`2646`) Enhancements ~~~~~~~~~~~~