Skip to content

Conversation

@aman-coder03
Copy link
Contributor

fixes a ZeroDivisionError in pvlib.transformer.simple_efficiency
when load_loss = 0.

when load_loss is zero, the transformer loss model reduces to a linear
relationship rather than a quadratic one. this PR handles that case
explicitly to avoid division by zero while preserving existing behavior
for load_loss > 0.

Fixes #2645

Comment on lines 108 to 110
if load_loss == 0:
return input_power - no_load_loss * transformer_rating

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if load_loss == 0:
return input_power - no_load_loss * transformer_rating

I don't think this is necessary with the alternate form of the quadratic equation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have removed it

Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test with load_loss=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!! @cwhanse
i have added a test covering the load_loss=0 that checks the linear-limit behavior P_out = P_in − L_no_load * P_nom
please let me know if you would prefer this test to also cover array like inputs or assert behavior at additional edge cases (negative input power)

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep the scope to addressing the division by zero issue. Test looks good.

Please open a new issue to extend testing to np.array and pd.Series types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @cwhanse
sure i will open issues separately for each np.array and pd.Series

Copy link
Contributor

@echedey-ls echedey-ls Jan 2, 2026

Choose a reason for hiding this comment

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

thanks @cwhanse sure i will open issues separately for each np.array and pd.Series

@aman-coder03

Just one issue for both of them types is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done @echedey-ls
thanks for your reply!!

Copy link
Contributor

@echedey-ls echedey-ls left a comment

Choose a reason for hiding this comment

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

LGTM. Add a whatsnew entry in the bugfixes section and this is good IMO.

@aman-coder03, just so you know, a cleaner and modular approach to write the tests would be to use @pytest.mark.parametrize, so you could avoid boiler plate repeated in the test at the top. Let me know if you wanna give it a try, it would definitely look better and introduce you to some of the perks of the testing framework.



def test_simple_efficiency_zero_load_loss():

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

@aman-coder03
Copy link
Contributor Author

@echedey-ls i added a whatsnew entry under Bug fixes.
Thanks for the suggestion on parametrized tests, happy to refactor those next.

@echedey-ls
Copy link
Contributor

Copy link
Member

@cwhanse cwhanse left a comment

Choose a reason for hiding this comment

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

The change needs to be moved to a v0.13.3.rst. I've submitted a PR to create that file.



Bug fixes
* Fixed a division-by-zero error in
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Fixed a division-by-zero error in
* Fix a division-by-zero condition in

@cwhanse
Copy link
Member

cwhanse commented Jan 3, 2026

@echedey-ls I think it's OK to re-implement the tests is a separate PR, to avoid scope creep in a PR that addresses a division-by-zero condition.

@echedey-ls
Copy link
Contributor

@cwhanse I agree with that.

@aman-coder03
Copy link
Contributor Author

thanks both for the guidance @echedey-ls @cwhanse
i have moved the whatsnew entry to v0.13.3 as suggested and removed it from v0.13.2.
i will keep the test in this PR limited to the division-by-zero case only, and open a separate PR later if we want to refactor or consolidate the transformer tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

simple_efficiency raises ZeroDivisionError when load_loss=0

3 participants