Skip to content

Commit

Permalink
numpy 2.0 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mfranz13 committed Jun 18, 2024
1 parent 4024050 commit e6da5e5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/component_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def init_results_element(net, element, output, all_float):
dtype=np.float64)
else:
net[res_element] = pd.DataFrame(np.zeros(0, dtype=output), index=[])
net[res_element] = pd.DataFrame(np.NaN, index=net[element].index,
net[res_element] = pd.DataFrame(np.nan, index=net[element].index,
columns=net[res_element].columns)


Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/converter/stanet/data_cleaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def sort_by_pos(group):

def sort_by_flow(group):
group["follower"] = group.FLUSSB.apply(lambda b: group.index[group.FLUSSA == b][0]
if b in group.FLUSSA.values else np.NaN)
if b in group.FLUSSA.values else np.nan)
ls = list(group.loc[~group.FLUSSA.isin(group.FLUSSB)].index)
assert len(ls) == 1
while len(ls) < len(group):
Expand Down
8 changes: 4 additions & 4 deletions src/pandapipes/converter/stanet/preparing_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def adapt_pipe_data_according_to_nodes(pipe_data, pipes_to_check, node_geo, pipe
node_val = node_geo.loc[pipe_data.loc[pipes_to_check, node_nr].values, node_name].values

if pipe_name not in pipe_data.columns:
pipe_data[pipe_name] = np.NaN
pipe_data[pipe_name] = np.nan
pipe_data.loc[pipes_to_check, pipe_name] = node_val
current_pipe_data = pipe_data.loc[pipes_to_check]
if not np.allclose(node_val, current_pipe_data[pipe_name].values):
Expand Down Expand Up @@ -401,9 +401,9 @@ def connection_pipe_section_table(stored_data, pipe_geodata, house_pipe_geodata,
# but requires checks (e.g. positioning on pipe, max. 2 valves per pipe)
c2 = stored_data["slider_valves"].loc[:, [c for c in required_columns if c not in
["PRECH", "VMA", "VMB"]]]
c2["PRECH"] = np.NaN
c2["VMA"] = np.NaN
c2["VMB"] = np.NaN
c2["PRECH"] = np.nan
c2["VMA"] = np.nan
c2["VMB"] = np.nan
c2["type"] = "slider_valves"
connections = pd.concat([connections, c2], ignore_index=True)

Expand Down
28 changes: 14 additions & 14 deletions src/pandapipes/converter/stanet/table_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def create_valve_and_pipe(net, stored_data, index_mapping, net_params, stanet_li
j_ref = net.junction.loc[node_mapping[from_stanet_nr], :]
j_ref_geodata = net.junction_geodata.loc[node_mapping[from_stanet_nr], :]
j_aux = pandapipes.create_junction(
net, np.NaN, tfluid_k=net_params["medium_temp_K"], height_m=j_ref['height_m'],
net, np.nan, tfluid_k=net_params["medium_temp_K"], height_m=j_ref['height_m'],
name='aux_' + j_ref['stanet_id'], geodata=(j_ref_geodata.x, j_ref_geodata.y),
stanet_nr=-999, stanet_id='aux_' + j_ref['stanet_id'], p_stanet=np.NaN,
stanet_nr=-999, stanet_id='aux_' + j_ref['stanet_id'], p_stanet=np.nan,
stanet_active=bool(row.ISACTIVE), **add_info
)
text_k = 293
Expand All @@ -169,7 +169,7 @@ def create_valve_and_pipe(net, stored_data, index_mapping, net_params, stanet_li
net, j_aux, node_mapping[to_stanet_nr], diameter_m=float(row.DM / 1000),
opened=row.AUF == 'J', loss_coefficient=0,
name="valve_%s_%s" % ('aux_' + str(row.ENDNAM), str(row.ENDNAM)),
stanet_nr=int(row.RECNO), stanet_id=str(row.STANETID), v_stanet=np.NaN,
stanet_nr=int(row.RECNO), stanet_id=str(row.STANETID), v_stanet=np.nan,
stanet_active=bool(row.ISACTIVE), **add_info
)

Expand Down Expand Up @@ -382,7 +382,7 @@ def create_control_components(net, stored_data, index_mapping, net_params, add_l

drop_eg = net.ext_grid.loc[net.ext_grid.junction.isin(to_junctions[is_pc])].index
net.ext_grid.drop(drop_eg, inplace=True)
net.junction.loc[to_junctions[is_pc], "pn_bar"] = np.NaN
net.junction.loc[to_junctions[is_pc], "pn_bar"] = np.nan
pandapipes.reindex_elements(net, "ext_grid", np.arange(len(net.ext_grid)))

if np.any(is_fc):
Expand Down Expand Up @@ -463,7 +463,7 @@ def create_junctions_from_connections(net, connection_table, net_params, index_m
continue
stanet_ids = cons.STANETID.astype(str).values
stanet_nrs = cons.RECNO.astype(np.int32).values
p_stanet = cons.PRECH.astype(np.float64).values if houses_in_calculation else np.NaN
p_stanet = cons.PRECH.astype(np.float64).values if houses_in_calculation else np.nan
names = stanet_ids if con_type not in extend_from_to else \
stanet_ids + node_type.replace(con_type, "")
geo = np.array([cons.geo.apply(lambda g: g[0]), cons.geo.apply(lambda g: g[1])]).transpose()
Expand All @@ -475,7 +475,7 @@ def create_junctions_from_connections(net, connection_table, net_params, index_m
if add_layers:
add_info["stanet_layer"] = cons.LAYER.values.astype(str)
pp_indices = pandapipes.create_junctions(
net, len(cons), np.NaN, net_params["medium_temp_K"], name=names,
net, len(cons), np.nan, net_params["medium_temp_K"], name=names,
height_m=cons.GEOH.astype(np.float64).values, geodata=geo, type=cons.type.values,
in_service=in_service, stanet_nr=stanet_nrs, stanet_id=stanet_ids, p_stanet=p_stanet,
stanet_system=cons.CLIENTTYP.replace(CLIENT_TYPES_OF_PIPES).values,
Expand Down Expand Up @@ -798,13 +798,13 @@ def build_house_junctions(net, index_mapping, hh_types, hh_recno, house_table, m
add_info["stanet_layer"] = connected_houses.LAYER.values.astype(str)
# create junctions for houses that are directly connected via house pipes
pp_ind = pandapipes.create_junctions(
net, len(connected_houses), np.NaN, tfluid_k=net_params["medium_temp_K"],
net, len(connected_houses), np.nan, tfluid_k=net_params["medium_temp_K"],
height_m=heights_houses.astype(np.float64), geodata=geodata,
in_service=houses_in_calculation,
name=["house_%s" % hn for hn in connected_houses.RECNO.values],
type="house", stanet_nr=connected_houses.RECNO.values,
stanet_id=connected_houses.STANETID.values.astype(str),
p_stanet=connected_houses.PRECH.values if houses_in_calculation else np.NaN,
p_stanet=connected_houses.PRECH.values if houses_in_calculation else np.nan,
stanet_system=CLIENT_TYPES_OF_PIPES[HOUSE_PIPE_TYPE],
stanet_active=connected_houses.ISACTIVE.values.astype(np.bool_),
stanet_valid=houses_in_calculation, **add_info
Expand All @@ -827,13 +827,13 @@ def build_meter_junctions(net, index_mapping, hh_types, hh_recno, meter_table, n
add_info["stanet_layer"] = connected_meters.LAYER.values.astype(str)
# create junctions for meters that are directly connected via house pipes
pp_ind = pandapipes.create_junctions(
net, len(connected_meters), np.NaN, tfluid_k=net_params["medium_temp_K"],
net, len(connected_meters), np.nan, tfluid_k=net_params["medium_temp_K"],
height_m=connected_meters.GEOH.values.astype(np.float64),
name=connected_meters.STANETID.values.astype(str), geodata=geodata, type="meter",
stanet_nr=connected_meters.RECNO.values,
stanet_id=connected_meters.STANETID.astype(str),
in_service=houses_in_calculation,
p_stanet=connected_meters.PRECH.values if houses_in_calculation else np.NaN,
p_stanet=connected_meters.PRECH.values if houses_in_calculation else np.nan,
stanet_system=CLIENT_TYPES_OF_PIPES[HOUSE_PIPE_TYPE],
stanet_active=connected_meters.ISACTIVE.values.astype(np.bool_),
stanet_valid=houses_in_calculation, **add_info
Expand All @@ -853,12 +853,12 @@ def build_house_node_junctions(net, index_mapping, stored_data, net_params, hous
if add_layers:
add_info["stanet_layer"] = house_nodes.LAYER.values.astype(str)
pp_ind = pandapipes.create_junctions(
net, len(house_node_nrs), np.NaN, tfluid_k=net_params["medium_temp_K"],
net, len(house_node_nrs), np.nan, tfluid_k=net_params["medium_temp_K"],
height_m=house_nodes.GEOH.values.astype(np.float64),
name=house_nodes.STANETID.values.astype(str), geodata=geodata,
type="house_node", stanet_nr=house_node_nrs,
stanet_id=house_nodes.STANETID.astype(str), in_service=houses_in_calculation,
p_stanet=house_nodes.PRECH.values if houses_in_calculation else np.NaN,
p_stanet=house_nodes.PRECH.values if houses_in_calculation else np.nan,
stanet_system=CLIENT_TYPES_OF_PIPES[HOUSE_PIPE_TYPE],
stanet_active=house_nodes.ISACTIVE.values.astype(np.bool_),
stanet_valid=houses_in_calculation, **add_info
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def create_sinks_meters(net, meter_table, index_mapping, net_params, add_layers)

assigned_node_nums = meter_table.KNONUM.astype(np.int32)
meter_nrs = meter_table.RECNO.astype(np.int32)
junctions_assigned = pd.Series([node_mapping.get(nn, np.NaN) for nn in assigned_node_nums],
junctions_assigned = pd.Series([node_mapping.get(nn, np.nan) for nn in assigned_node_nums],
index=meter_table.index, dtype=float)

junctions_connected = pd.Series(index=meter_table.index, dtype=float)
Expand All @@ -1110,7 +1110,7 @@ def create_sinks_meters(net, meter_table, index_mapping, net_params, add_layers)

if np.any(junctions_connected.isnull()):
junctions_connected.loc[junctions_connected.isnull()] = \
[node_mapping.get(n, np.NaN) if not np.isnan(n) else np.NaN for n in
[node_mapping.get(n, np.nan) if not np.isnan(n) else np.nan for n in
meter_table.KNONUM.loc[junctions_connected.isnull()].values]
logger.warning("The meters %s cannot be mapped to a house connection node and will be "
"assigned to nodes %s"
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/pf/internals_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _sum_by_group_sorted(indices, *values):
val[i] = val[i][index]
still_na = nans[index]
val[i][1:] = val[i][1:] - val[i][:-1]
val[i][still_na] = np.NaN
val[i][still_na] = np.nan
else:
np.cumsum(val[i], out=val[i])
val[i] = val[i][index]
Expand Down
4 changes: 2 additions & 2 deletions src/pandapipes/pf/result_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ def extract_results_active_pit(net, mode="hydraulics"):
not_affected_branch_col]])
rows_branches = np.arange(net["_pit"]["branch"].shape[0])[branches_connected]

net["_pit"]["node"][~nodes_connected, result_node_col] = np.NaN
net["_pit"]["node"][~nodes_connected, result_node_col] = np.nan
net["_pit"]["node"][rows_nodes[:, np.newaxis], copied_node_cols[np.newaxis, :]] = \
net["_active_pit"]["node"][:, copied_node_cols]
net["_pit"]["branch"][~branches_connected, result_branch_col] = np.NaN
net["_pit"]["branch"][~branches_connected, result_branch_col] = np.nan
net["_pit"]["branch"][rows_branches[:, np.newaxis], copied_branch_cols[np.newaxis, :]] = \
net["_active_pit"]["branch"][:, copied_branch_cols]

Expand Down

0 comments on commit e6da5e5

Please sign in to comment.