-
Notifications
You must be signed in to change notification settings - Fork 518
Description
Bug report checklis
-
Searched the issues page for similar reports
-
Read the relevant sections of the documentation
-
Browse the tutorials and tests for usefull code snippets and examples of use
-
Reproduced the issue after updating with
pip install --upgrade pandapower
(orgit pull
) -
Tried basic troubleshooting (if a bug/error) like restarting the interpreter and checking the pythonpath
Reproducible Example
import pandapower as pp
import pandapower.networks as nw
# Test with built-in network modified to have zero shift
print("Original built-in network (works):")
net_working = nw.simple_four_bus_system()
print(f"Shift degree: {net_working.trafo.iloc[0].shift_degree}°") # 150.0°
ppc_net = pp.converter.to_ppc(net_working, check_connectivity=True, mode='pf', init='flat')
net_converted = pp.converter.from_ppc(ppc_net, f_hz=50)
print(f"Transformers after conversion: {len(net_converted.trafo)}") # 1 (works)
print("\nSame network with zero shift (breaks):")
net_broken = nw.simple_four_bus_system()
net_broken.trafo.loc[0, 'shift_degree'] = 0.0 # Change to zero shift
ppc_net = pp.converter.to_ppc(net_broken, check_connectivity=True, mode='pf', init='flat')
net_converted = pp.converter.from_ppc(ppc_net, f_hz=50)
print(f"Transformers after conversion: {len(net_converted.trafo)}") # 0 (BUG!)
# Show the problem: all branches have ratio=1.0, angle=0.0
for i, branch in enumerate(ppc_net['branch']):
ratio, angle = branch[8], branch[9]
print(f"Branch {i}: ratio={ratio:.3f}, angle={angle:.3f}")
Issue Description and Traceback
Transformers with shift_degree=0 lost during from_ppc() conversion due to incorrect ratio calculation in to_ppc()
- pandapower version: 3.1.2
- pandas version: 2.2.3
- Python version: 3.12
Transformers with shift_degree=0 are completely lost during to_ppc() → from_ppc() round-trip conversion. The to_ppc() converter incorrectly sets transformer turns ratio to 1.0 instead of the actual voltage ratio, and from_ppc() cannot identify elements as transformers when both ratio=1.0 and angle=0.0.
Root Cause
- to_ppc() bug: Transformers should have ratio = vn_hv_kv/vn_lv_kv (e.g., 10.0/0.4 = 25.0), but to_ppc() incorrectly sets ratio=1.0
- from_ppc() logic: Only recognizes transformers when (ratio ≠ 0 AND ratio ≠ 1.0) OR angle ≠ 0
- Result: Zero-shift transformers are not identified and get lost
FutureWarning appears during conversion:
FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
branch_lookup.loc[is_trafo, "element"] = idx_trafo
Expected Behavior
Expected: 10kV/0.4kV transformer should have ratio=25.0 in PPC format
Actual: All branches show ratio=1.0, making zero-shift transformers unidentifiable
Installed Versions
Package Versions:
- Python version: 3.12.9
- pandas version: 2.2.3
- networkx version: 3.4.2
- scipy version: 1.13.1
- numpy version: 1.26.0
- packaging version: 24.2
- tqdm version: 4.67.1
- deepdiff version: 8.2.0
Operating System:
- OS: macOS 14.6.1 (Darwin 23.6.0)
Label
- Relevant labels are selected