Skip to content

Commit 624ad6c

Browse files
committed
add add column to df
1 parent 99f7520 commit 624ad6c

9 files changed

Lines changed: 30 additions & 41 deletions

File tree

pandapower/build_branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ def _calculate_3w_tap_changers(t3, t2, sides):
16031603
at_star_point = t3.tap_at_star_point.values
16041604
any_at_star_point = at_star_point.any()
16051605
for side in sides:
1606-
if 'tap_side' not in t3:
1606+
if 'tap_side' not in t3: # TODO: add column wont work here
16071607
t3['tap_side'] = pd.NA
16081608
tap_mask = (t3.tap_side.fillna("") == side).to_numpy()
16091609
for var in tap_variables:

pandapower/build_gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pandas as pd
99

10+
from pandapower.create._utils import add_column_to_df
1011
from pandapower.pf.ppci_variables import bustypes
1112
from pandapower.pypower.bustypes import bustypes_dc
1213
from pandapower.pypower.idx_bus import PV, REF, VA, VM, BUS_TYPE, NONE, VMAX, VMIN, SL_FAC as SL_FAC_BUS
@@ -530,8 +531,7 @@ def _calculate_qmin_qmax_from_q_capability_characteristics(net, element):
530531
return None
531532

532533
# Filter rows with True 'reactive_capability_curve'
533-
if 'reactive_capability_curve' not in net[element]:
534-
net[element]['reactive_capability_curve'] = pd.NA
534+
add_column_to_df(net, element, 'reactive_capability_curve')
535535
element_data = net[element].loc[net[element]['reactive_capability_curve'].fillna(False)]
536536

537537
if element_data.empty:

pandapower/contingency/contingency.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pandas as pd
99
import warnings
1010
from packaging.version import Version
11-
11+
from pandapower.create._utils import add_column_to_df
1212
import logging
1313

1414
logger = logging.getLogger(__name__)
@@ -164,11 +164,8 @@ def run_contingency_ls2g(net, nminus1_cases, contingency_evaluation_function=run
164164
if not lightsim2grid_installed:
165165
raise UserWarning("lightsim2grid package not installed. "
166166
"Install lightsim2grid e.g. by running 'pip install lightsim2grid' in command prompt.")
167-
if "min_q_mvar" not in net["gen"].columns:
168-
net["gen"]["min_q_mvar"] = float("nan")
169-
if "max_q_mvar" not in net["gen"].columns:
170-
net["gen"]["max_q_mvar"] = float("nan")
171-
167+
add_column_to_df(net, "gen", "min_q_mvar")
168+
add_column_to_df(net, "gen", 'max_q_mvar')
172169
# check for continuous bus index starting with 0:
173170
n_bus = len(net.bus)
174171
last_bus = net.bus.index[-1]

pandapower/plotting/geo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def update_props(r: pd.Series) -> None:
281281
if element:
282282
props: dict = {}
283283
for table in [name, f"res_{name}"]:
284-
if table not in net.keys():
284+
if table not in net:
285285
continue
286286

287287
tempdf = net[table].copy(deep=True)

pandapower/protection/utility_functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import List, Tuple
55

66
from matplotlib.collections import PatchCollection
7-
from typing_extensions import deprecated
87

98
import geojson
109
import math
@@ -17,6 +16,7 @@
1716

1817
from pandapower.auxiliary import pandapowerNet
1918
from pandapower.topology.create_graph import create_nxgraph
19+
from pandapower.create._utils import add_column_to_df
2020
from pandapower.create import create_bus, create_line_from_parameters
2121
from pandapower.plotting.collections import create_annotation_collection, create_line_collection, \
2222
create_bus_collection, create_line_switch_collection, draw_collections, create_trafo_collection, \
@@ -88,12 +88,15 @@ def create_sc_bus(net_copy, sc_line_id, sc_fraction):
8888
# sim bench grids
8989
if 's_sc_max_mva' not in net.ext_grid:
9090
print('input s_sc_max_mva or taking 1000')
91+
add_column_to_df(net, "ext_grid", "s_sc_max_mva")
9192
net.ext_grid['s_sc_max_mva'] = 1000
9293
if 'rx_max' not in net.ext_grid:
9394
print('input rx_max or taking 0.1')
95+
add_column_to_df(net, "ext_grid", "rx_max")
9496
net.ext_grid['rx_max'] = 0.1
9597
if 'k' not in net.sgen and len(net.sgen) != 0:
9698
print('input Ratio of nominal current to short circuit current- k or taking k=1')
99+
add_column_to_df(net, "sgen", "k")
97100
net.sgen['k'] = 1
98101

99102
# set new lines

pandapower/test/control/test_stactrl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99

1010
from pandapower.control.controller.station_control import BinarySearchControl, DroopControl
11+
from pandapower.create._utils import add_column_to_df
1112
from pandapower.create import create_empty_network, create_bus, create_buses, create_ext_grid, create_transformer, \
1213
create_load, create_line, create_sgen, create_impedance
1314
from pandapower.run import runpp
@@ -186,8 +187,7 @@ def test_qlimits_with_capability_curve():
186187
'p_mw': [-2.0, -1.0, 0.0, 1.0, 2.0],
187188
'q_min_mvar': [-0.1, -0.1, -0.1, -0.1, -0.1],
188189
'q_max_mvar': [0.1, 0.1, 0.1, 0.1, 0.1]})
189-
if 'id_q_capability_characteristic' not in net.sgen:
190-
net.sgen['id_q_capability_characteristic'] = pd.NA
190+
add_column_to_df(net, "sgen", "id_q_capability_characteristic")
191191
net.sgen.at[0, "id_q_capability_characteristic"] = 0
192192
net.sgen['curve_style'] = "straightLineYValues"
193193
create_q_capability_characteristics_object(net)

pandapower/test/control/test_tap_dependent_impedance.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
import numpy as np
88

9+
from pandapower.create._utils import add_column_to_df
910
from pandapower.control import Characteristic, SplineCharacteristic, TapDependentImpedance, \
1011
trafo_characteristic_table_diagnostic
1112
from pandapower.control.util.diagnostic import shunt_characteristic_table_diagnostic
@@ -136,10 +137,8 @@ def test_trafo_characteristic_table_diagnostic():
136137
'vkr_percent': [1.3, 1.4, 1.44, 1.5, 1.6], 'vk_hv_percent': np.nan, 'vkr_hv_percent': np.nan,
137138
'vk_mv_percent': np.nan, 'vkr_mv_percent': np.nan, 'vk_lv_percent': np.nan, 'vkr_lv_percent': np.nan})
138139
# populate id_characteristic_table parameter
139-
if 'id_characteristic_table' not in net.trafo:
140-
net.trafo.at[0, 'id_characteristic_table'] = pd.NA
141-
if 'tap_dependency_table' not in net.trafo:
142-
net.trafo.at[0, 'tap_dependency_table'] = pd.NA
140+
add_column_to_df(net, "trafo", "id_characteristic_table")
141+
add_column_to_df(net, "trafo", 'tap_dependency_table')
143142
net.trafo['id_characteristic_table'].at[0] = 0
144143
net.trafo['tap_dependency_table'].at[0] = False
145144
with pytest.warns(UserWarning):

pandapower/test/grid_equivalents/test_get_equivalent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandapower import pp_dir
99
from pandapower.control import ConstControl
1010
from pandapower.control.util.auxiliary import create_trafo_characteristic_object
11+
from pandapower.create._utils import add_column_to_df
1112
from pandapower.create import create_empty_network, create_buses, create_ext_grid, create_poly_cost, create_line, \
1213
create_load, create_sgen, create_pwl_cost, create_bus, create_switch, create_motor
1314
from pandapower.grid_equivalents.auxiliary import replace_motor_by_load, _runpp_except_voltage_angles
@@ -483,9 +484,9 @@ def test_characteristic():
483484
'angle_deg': [0, 0, 0, 0, 0], 'vk_percent': [2, 3, 4, 5, 6],
484485
'vkr_percent': [1.323, 1.324, 1.325, 1.326, 1.327], 'vk_hv_percent': np.nan, 'vkr_hv_percent': np.nan,
485486
'vk_mv_percent': np.nan, 'vkr_mv_percent': np.nan, 'vk_lv_percent': np.nan, 'vkr_lv_percent': np.nan})
486-
net.trafo['id_characteristic_table'] = pd.NA
487+
add_column_to_df(net, "trafo", "id_characteristic_table")
488+
add_column_to_df(net, "trafo", 'tap_dependency_table')
487489
net.trafo.at[1, 'id_characteristic_table'] = 0
488-
net.trafo['tap_dependency_table'] = pd.NA
489490
net.trafo.at[1, 'tap_dependency_table'] = True
490491
# add spline characteristics for one transformer based on trafo_characteristic_table
491492
create_trafo_characteristic_object(net)

pandapower/test/loadflow/test_runpp.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from pandapower import pp_dir
1616
from pandapower.auxiliary import _check_connectivity, _add_ppc_options, lightsim2grid_available
17+
from pandapower.create._utils import add_column_to_df
1718
from pandapower.create import create_bus, create_empty_network, create_ext_grid, create_dcline, create_load, \
1819
create_sgen, create_switch, create_transformer, create_xward, create_transformer3w, create_gen, create_shunt, \
1920
create_line_from_parameters, create_line, create_impedance, create_storage, create_buses, \
@@ -1395,11 +1396,8 @@ def test_tap_dependent_impedance():
13951396
'angle_deg': [0, 0, 0, 0, 0], 'vk_percent': [5.5, 5.8, 6, 6.2, 6.5],
13961397
'vkr_percent': [1.4, 1.42, 1.44, 1.46, 1.48], 'vk_hv_percent': np.nan, 'vkr_hv_percent': np.nan,
13971398
'vk_mv_percent': np.nan, 'vkr_mv_percent': np.nan, 'vk_lv_percent': np.nan, 'vkr_lv_percent': np.nan})
1398-
if 'id_characteristic_table' not in net.trafo:
1399-
net.trafo['id_characteristic_table'] = pd.NA
1400-
net.trafo.at[0, 'id_characteristic_table'] = 0
1401-
if 'tap_dependency_table' not in net.trafo:
1402-
net.trafo['tap_dependency_table'] = pd.NA
1399+
add_column_to_df(net, "trafo", "id_characteristic_table")
1400+
add_column_to_df(net, "trafo", 'tap_dependency_table')
14031401
net.trafo.at[0, 'tap_dependency_table'] = True
14041402
net.trafo.at[1, 'tap_dependency_table'] = False
14051403

@@ -1410,10 +1408,8 @@ def test_tap_dependent_impedance():
14101408
'vkr_mv_percent': [0.3, 0.3, 0.3, 0.3, 0.3], 'vk_lv_percent': [1, 1, 1, 1, 1],
14111409
'vkr_lv_percent': [0.3, 0.3, 0.3, 0.3, 0.3]})
14121410
net["trafo_characteristic_table"] = pd.concat([net["trafo_characteristic_table"], new_rows], ignore_index=True)
1413-
if 'id_characteristic_table' not in net.trafo3w:
1414-
net.trafo3w['id_characteristic_table'] = pd.NA
1415-
if 'tap_dependency_table' not in net.trafo3w:
1416-
net.trafo3w['tap_dependency_table'] = pd.NA
1411+
add_column_to_df(net, "trafo3w", "id_characteristic_table")
1412+
add_column_to_df(net, "trafo33w", 'tap_dependency_table')
14171413
net.trafo3w.at[0, 'id_characteristic_table'] = 1
14181414
net.trafo3w.at[0, 'tap_dependency_table'] = True
14191415

@@ -1462,10 +1458,8 @@ def test_tap_table_order():
14621458
'vk_hv_percent': [0.95, 0.98, 1, 1.02, 1.05], 'vkr_hv_percent': [0.3, 0.3, 0.3, 0.3, 0.3],
14631459
'vk_mv_percent': [1, 1, 1, 1, 1], 'vkr_mv_percent': [0.3, 0.3, 0.3, 0.3, 0.3],
14641460
'vk_lv_percent': [1, 1, 1, 1, 1], 'vkr_lv_percent': [0.3, 0.3, 0.3, 0.3, 0.3]})
1465-
if 'id_characteristic_table' not in net.trafo3w:
1466-
net.trafo3w['id_characteristic_table'] = pd.NA
1467-
if 'tap_dependency_table' not in net.trafo3w:
1468-
net.trafo3w['tap_dependency_table'] = pd.NA
1461+
add_column_to_df(net, "trafo3w", "id_characteristic_table")
1462+
add_column_to_df(net, "trafo3w", 'tap_dependency_table')
14691463
net.trafo3w.at[0, 'id_characteristic_table'] = 0
14701464
net.trafo3w.at[0, 'tap_dependency_table'] = True
14711465

@@ -1476,10 +1470,8 @@ def test_tap_table_order():
14761470
'vkr_percent': [1.4, 1.42, 1.44, 1.46, 1.48, 1.4, 1.42, 1.44, 1.46, 1.48], 'vk_hv_percent': np.nan, 'vkr_hv_percent': np.nan,
14771471
'vk_mv_percent': np.nan, 'vkr_mv_percent': np.nan, 'vk_lv_percent': np.nan, 'vkr_lv_percent': np.nan})
14781472
net["trafo_characteristic_table"] = pd.concat([net["trafo_characteristic_table"], new_rows], ignore_index=True)
1479-
if 'id_characteristic_table' not in net.trafo:
1480-
net.trafo['id_characteristic_table'] = pd.NA
1481-
if 'tap_dependency_table' not in net.trafo:
1482-
net.trafo['tap_dependency_table'] = pd.NA
1473+
add_column_to_df(net, "trafo", "id_characteristic_table")
1474+
add_column_to_df(net, "trafo", 'tap_dependency_table')
14831475
net.trafo.at[0, 'id_characteristic_table'] = 2
14841476
net.trafo.at[1, 'id_characteristic_table'] = 1
14851477
net.trafo.at[0, 'tap_dependency_table'] = True
@@ -1682,9 +1674,7 @@ def test_q_capability_curve():
16821674
0, -265.01001, -134.00999, -0.01000],
16831675
'q_max_mvar': [0.01000, 134.00999, 228.00999, 257.01001, 261.01001, 261.01001, 261.01001, 257.01001, 30, 40,
16841676
134.0099, 0.01]})
1685-
1686-
if 'id_q_capability_characteristic' not in net.gen:
1687-
net.gen["id_q_capability_characteristic"] = pd.NA
1677+
add_column_to_df(net, "gen", "id_q_capability_characteristic")
16881678
net.gen.at[0, "id_q_capability_characteristic"] = 0
16891679
net.gen['curve_style'] = "straightLineYValues"
16901680

@@ -1733,8 +1723,7 @@ def test_q_capability_curve_for_sgen():
17331723
-265.01001, -134.00999, -0.01000],
17341724
'q_max_mvar': [0.01000, 134.00999, 228.00999, 257.01001, 261.01001, 261.01001, 261.01001, 257.01001, 218.0099945068,
17351725
134.0099, 0.01]})
1736-
if 'id_q_capability_characteristic' not in net.sgen:
1737-
net.sgen["id_q_capability_characteristic"] = pd.NA
1726+
add_column_to_df(net, "sgen", "id_q_capability_characteristic")
17381727
net.sgen.at[0, "id_q_capability_characteristic"] = 0
17391728
net.sgen['curve_style'] = "straightLineYValues"
17401729
create_q_capability_characteristics_object(net)

0 commit comments

Comments
 (0)