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.

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