-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Describe the bug
Several fault analysis functions attempt to coerce impedances to imaginary values using checks like if not isinstance(Z1, complex): Z1 *= 1j. NumPy complex scalars (e.g. np.complex128) are not instances of built-in complex, so already-complex impedances are multiplied by 1j again, producing incorrect results.
Reproduction Code
# Setup
import numpy as np
import electricpy as ep
# Code which causes failure (incorrect numeric result)
Vth = 1 + 0j
Z0 = np.complex128(0.1j)
Z1 = np.complex128(0.2j)
Z2 = np.complex128(0.3j)
If = ep.fault.phase_to_phase_fault(Vth, (Z0, Z1, Z2), sequence=True)
print(If)Expected behavior
If impedances are already complex (including NumPy complex scalars), they should not be modified. Results should be identical to using built-in complex values.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. Linux]
- Python Version [e.g. 3.7]
- Version [e.g. 0.2.1]
Additional context
Type checks should use np.iscomplexobj() or isinstance(x, (complex, np.complexfloating)).