power factor calculator - #11727
Open
ShoaibAbbasDev wants to merge 3 commits into
Open
Conversation
ShoaibAbbasDev
force-pushed
the
Power-factor-calculator
branch
from
October 4, 2024 06:05
d86f7cd to
451ac39
Compare
priya-sundaram-dev
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this, @ShoaibAbbasDev! The power-factor-correction maths look right. A few things needed before this can be merged, matching the repo's CONTRIBUTING conventions:
- Type hints are required on every function. e.g.
def calculate_apparent_power(voltage: float, current: float) -> float:, and likewise for the others. - Doctests are required — right now the module has none, so CI's doctest requirement isn't satisfied. Please add
>>>examples to each function (including the error paths, e.g.calculate_power_factor(100, 0)raisingValueError), and aif __name__ == "__main__": import doctest; doctest.testmod()block. - The
try/except TypeError -> raise ValueErrorwrapping is an anti-pattern here. Withfloattype hints you don't need to guard against non-numbers, andcalculate_reactive_power/calculate_correction_capacitancecatchValueErroronly to re-raise it with a"Calculation error:"prefix, which double-wraps and obscures the original message. I'd drop the try/except and validate inputs directly (if apparent_power == 0: raise ValueError(...)).
Also worth cross-checking against #9535 (shunt-capacitor PF correction) and #12356 so the electronics PF/transform modules don't overlap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Checklist: