@@ -386,48 +386,52 @@ def _update_edge_attributes(self):
386
386
387
387
# Deal with edges that are updated by more than one project
388
388
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
+ ############################
431
435
# Recode -1s to Nan so they do not update scenario edges
432
436
merged_projects .replace (- 1 , np .NaN , inplace = True )
433
437
merged_projects .replace ("-1" , np .NaN , inplace = True )
0 commit comments