Skip to content

Commit

Permalink
Merge pull request e2nIEE#2371 from quant12345/dtype
Browse files Browse the repository at this point in the history
Cast the column to the correct type before assigning values
  • Loading branch information
vogt31337 authored Aug 29, 2024
2 parents a044a46 + 5808955 commit 11af12c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Change Log

[upcoming release] - 2024-..-..
-------------------------------
- [FIXED] cast the column to the correct type before assigning values
- [FIXED] replacement for deprecated namespaces scipy.sparse.csc and scipy.sparse.csr
- [FIXED] copy array element to standard python scalar
- [REMOVED] python 3.8 support
Expand Down
1 change: 1 addition & 0 deletions pandapower/converter/pypower/from_ppc.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def _from_ppc_branch(net, ppc, f_hz, **kwargs):
branch_lookup.loc[is_line, "element_type"] = "line"
branch_lookup.loc[is_trafo, "element"] = idx_trafo
branch_lookup.loc[is_trafo, "element_type"] = "trafo"
branch_lookup["element"] = branch_lookup["element"].astype("float64")
branch_lookup.loc[is_impedance, "element"] = idx_impedance
branch_lookup.loc[is_impedance, "element_type"] = "impedance"
return branch_lookup
Expand Down
2 changes: 1 addition & 1 deletion pandapower/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5987,8 +5987,8 @@ def _set_value_if_not_nan(net, index, value, column, element_type, dtype=float64
if not column_exists:
net[element_type].loc[:, column] = pd.Series(
data=default_val, index=net[element_type].index)
net[element_type].at[index, column] = value
try_astype(net[element_type], column, dtype)
net[element_type].at[index, column] = value
elif column_exists:
if _not_nan(default_val):
net[element_type].at[index, column] = default_val
Expand Down
1 change: 1 addition & 0 deletions pandapower/networks/mv_oberrhein.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def mv_oberrhein(scenario="load", cosphi_load=0.98, cosphi_pv=1.0, include_subst
net.sgen.q_mvar = np.tan(np.arccos(cosphi_pv)) * net.sgen.p_mw

hv_trafos = net.trafo[net.trafo.sn_mva > 1].index
net.trafo["tap_pos"] = net.trafo["tap_pos"].astype("float64")
if scenario == "load":
net.load.scaling = 0.6
net.sgen.scaling = 0.0
Expand Down
1 change: 1 addition & 0 deletions pandapower/plotting/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def convert_geodata_to_geojson(
if not coords:
continue
ls = f'{{"coordinates": {coords}, "type": "LineString"}}'
ldf["geo"] = ldf["geo"].astype(object)
ldf.geo.at[l_id] = ls

if delete:
Expand Down
3 changes: 2 additions & 1 deletion pandapower/test/shortcircuit/test_iec60909_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ def test_detect_power_station_units():

detect_power_station_unit(net)
assert np.all(net.gen.power_station_trafo.values[[0, 1]] == np.array([0, 1]))
net.gen.loc[:, 'power_station_trafo'] = None
net.gen["power_station_trafo"] = net.gen["power_station_trafo"].astype(object)
net.gen.loc[:, "power_station_trafo"] = None

detect_power_station_unit(net, mode="trafo")
assert np.all(net.gen.power_station_trafo.values[[0, 1]] == np.array([0, 1]))
Expand Down
16 changes: 10 additions & 6 deletions pandapower/toolbox/grid_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,9 @@ def replace_ext_grid_by_gen(net, ext_grids=None, gen_indices=None, slack=False,
in_service=ext_grid.in_service, controllable=True, index=index)
new_idx.append(idx)
net.gen.loc[new_idx, "slack"] = slack
net.gen.loc[new_idx, existing_cols_to_keep] = net.ext_grid.loc[
ext_grids, existing_cols_to_keep].values

val = net.ext_grid.loc[ext_grids, existing_cols_to_keep].values
net.gen[existing_cols_to_keep] = net.gen[existing_cols_to_keep].astype(val.dtype)
net.gen.loc[new_idx, existing_cols_to_keep] = val
_replace_group_member_element_type(net, ext_grids, "ext_grid", new_idx, "gen")

# --- drop replaced ext_grids
Expand All @@ -1260,7 +1260,8 @@ def replace_ext_grid_by_gen(net, ext_grids=None, gen_indices=None, slack=False,
(net[table].element.isin(ext_grids))]
if len(to_change):
net[table].loc[to_change, "et"] = "gen"
net[table].loc[to_change, "element"] = new_idx
net[table].loc[to_change, "element"] = np.array(
new_idx, net[table]["element"].dtypes)

# --- result data
if net.res_ext_grid.shape[0]:
Expand Down Expand Up @@ -1426,7 +1427,8 @@ def replace_gen_by_sgen(net, gens=None, sgen_indices=None, cols_to_keep=None,
to_change = net[table].index[(net[table].et == "gen") & (net[table].element.isin(gens))]
if len(to_change):
net[table].loc[to_change, "et"] = "sgen"
net[table].loc[to_change, "element"] = new_idx
net[table].loc[to_change, "element"] = np.array(
new_idx, net[table]["element"].dtypes)

# --- result data
if net.res_gen.shape[0]:
Expand Down Expand Up @@ -1647,7 +1649,9 @@ def replace_pq_elmtype(net, old_element_type, new_element_type, old_indices=None
(net[table].element.isin(old_indices))]
if len(to_change):
net[table].loc[to_change, "et"] = new_element_type
net[table].loc[to_change, "element"] = new_idx
net[table].loc[to_change, "element"] = np.array(
new_idx, net[table]["element"].dtypes)


# --- result data
if net["res_" + old_element_type].shape[0]:
Expand Down

0 comments on commit 11af12c

Please sign in to comment.