Skip to content

Commit dfa3bdf

Browse files
ModellerModeller
Modeller
authored and
Modeller
committed
Changes related to python 3.11.
1 parent fbb795f commit dfa3bdf

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

classes/FlagNetworkFromProjects.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -386,48 +386,52 @@ def _update_edge_attributes(self):
386386

387387
# Deal with edges that are updated by more than one project
388388
multiple_projects = merged_projects[merged_projects.index.value_counts() > 1]
389-
multiple_projects.sort_values(
390-
by=["InServiceDate"], ascending=False, inplace=True
391-
)
392-
multiple_projects.reset_index(inplace=True)
393-
394-
# Create a dataframe that has one unique edge for multiple projects.
395-
# This will then be updated with the correct attributes from multiple projects.
396-
unique_edges_df = multiple_projects.groupby("PSRCEdgeID").first()
397-
398-
row_list = []
399-
for edge_id in multiple_projects["PSRCEdgeID"].unique():
400-
# Dict to hold correct attributes for each edge
401-
row_dict = {"PSRCEdgeID": edge_id}
402-
edges = multiple_projects[multiple_projects["PSRCEdgeID"] == edge_id]
403-
for col in (
404-
self.config["dir_columns"] + self.config["project_update_columns"]
405-
):
406-
# If all values are -1
407-
if max(edges[col].values) == -1:
408-
row_dict[col] = -1
409-
elif np.isnan(np.min(edges[col].values)):
410-
self._logger.info(
411-
"Fatal: Null values encountered. Please check %s attribute from proRteID %s for Null values!"
412-
% (col, str(list(edges.projRteID.values)))
413-
)
414-
sys.exit(1)
415-
416-
else:
417-
field_values = edges[col].values
418-
# Get rid of any -1s, which means no change from that project
419-
field_value = field_values[field_values > -1]
420-
# Get the value of that has the farthest horizon year-
421-
# The first value because the df is ordered by InServiceDate in descending order.
422-
row_dict[col] = field_value[0]
423-
row_list.append(row_dict)
424-
update_df = pd.DataFrame(row_list)
425-
update_df.set_index("PSRCEdgeID", inplace=True)
426-
unique_edges_df.update(update_df)
427-
428-
# get rid of duplicate edges:
429-
merged_projects = merged_projects[merged_projects.index.value_counts() == 1]
430-
merged_projects = pd.concat([merged_projects, unique_edges_df])
389+
390+
if not multiple_projects.empty:
391+
multiple_projects.sort_values(
392+
by=["InServiceDate"], ascending=False, inplace=True
393+
)
394+
multiple_projects.reset_index(inplace=True)
395+
396+
# Create a dataframe that has one unique edge for multiple projects.
397+
# This will then be updated with the correct attributes from multiple projects.
398+
unique_edges_df = multiple_projects.groupby("PSRCEdgeID").first()
399+
400+
row_list = []
401+
for edge_id in multiple_projects["PSRCEdgeID"].unique():
402+
# Dict to hold correct attributes for each edge
403+
row_dict = {"PSRCEdgeID": edge_id}
404+
edges = multiple_projects[multiple_projects["PSRCEdgeID"] == edge_id]
405+
for col in (
406+
self.config["dir_columns"] + self.config["project_update_columns"]
407+
):
408+
# If all values are -1
409+
if max(edges[col].values) == -1:
410+
row_dict[col] = -1
411+
elif np.isnan(np.min(edges[col].values)):
412+
self._logger.info(
413+
"Fatal: Null values encountered. Please check %s attribute from proRteID %s for Null values!"
414+
% (col, str(list(edges.projRteID.values)))
415+
)
416+
sys.exit(1)
417+
418+
else:
419+
field_values = edges[col].values
420+
# Get rid of any -1s, which means no change from that project
421+
field_value = field_values[field_values > -1]
422+
# Get the value of that has the farthest horizon year-
423+
# The first value because the df is ordered by InServiceDate in descending order.
424+
row_dict[col] = field_value[0]
425+
row_list.append(row_dict)
426+
update_df = pd.DataFrame(row_list)
427+
update_df.set_index("PSRCEdgeID", inplace=True)
428+
unique_edges_df.update(update_df)
429+
430+
# get rid of duplicate edges:
431+
merged_projects = merged_projects[merged_projects.index.value_counts() == 1]
432+
merged_projects = pd.concat([merged_projects, unique_edges_df])
433+
434+
############################
431435
# Recode -1s to Nan so they do not update scenario edges
432436
merged_projects.replace(-1, np.NaN, inplace=True)
433437
merged_projects.replace("-1", np.NaN, inplace=True)

classes/ThinNetwork.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ def _report_duplicate_edges(self):
8282
full_net["freq"] = full_net.groupby("id")["id"].transform("count")
8383

8484
dup_edges = full_net.loc[full_net.freq > 1]
85-
dup_edges_dict = (
86-
dup_edges.groupby(["id"]).apply(lambda x: list(x.PSRCEdgeID)).to_dict()
87-
)
85+
if not dup_edges.empty:
86+
dup_edges_dict = (
87+
dup_edges.groupby(["id"]).apply(lambda x: list(x.PSRCEdgeID)).to_dict()
88+
)
8889

89-
if len(dup_edges_dict) > 0:
9090
for node_seq, edge_ids in dup_edges_dict.items():
9191
self._logger.info(
9292
"Warning! Node sequence %s is represented "
9393
"by more than one edge: %s. Please Fix!" % (node_seq, edge_ids)
94-
)
94+
)
9595

9696
def _thin_network(self):
9797
"""

0 commit comments

Comments
 (0)