Describe the bug
Several fault functions attempt to “ensure X-components are imaginary” using if not isinstance(Xk, complex): Xk *= 1j.
But if a user supplies NumPy complex scalars (e.g., np.complex128), isinstance(..., complex) is False, so the code incorrectly multiplies an already-complex impedance by 1j, rotating/scaling it and producing wrong fault currents.
This pattern is visible in the module code. https://electricpy.readthedocs.io/en/latest/_modules/electricpy/fault.html
Reproduction Code
# Setup
import numpy as np
import electricpy as ep
# Code which causes failure (wrong numeric result, not necessarily an exception)
Vth = 1.0 + 0.0j
# Already-complex impedances (NumPy complex scalars are common in numeric workflows)
Z0 = np.complex128(0.1j)
Z1 = np.complex128(0.2j)
Z2 = np.complex128(0.25j)
# Example: line-to-line fault
If_seq = ep.fault.phase_to_phase_fault(Vth, (Z0, Z1, Z2), sequence=True)
print(If_seq)
Expected behavior
If Z0, Z1, Z2 are already complex (including NumPy complex scalars), the function should not multiply them by 1j. Results should match the same calculation done with built-in complex types.
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
The logic uses isinstance(Xk, complex) to decide whether to apply * 1j. That excludes NumPy complex scalars, causing incorrect math.
Describe the bug
Several fault functions attempt to “ensure X-components are imaginary” using if not isinstance(Xk, complex): Xk *= 1j.
But if a user supplies NumPy complex scalars (e.g., np.complex128), isinstance(..., complex) is False, so the code incorrectly multiplies an already-complex impedance by 1j, rotating/scaling it and producing wrong fault currents.
This pattern is visible in the module code. https://electricpy.readthedocs.io/en/latest/_modules/electricpy/fault.html
Reproduction Code
Expected behavior
If Z0, Z1, Z2 are already complex (including NumPy complex scalars), the function should not multiply them by 1j. Results should match the same calculation done with built-in complex types.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
The logic uses isinstance(Xk, complex) to decide whether to apply * 1j. That excludes NumPy complex scalars, causing incorrect math.