@@ -539,6 +539,7 @@ def compare(
539539 other : "Simulation" ,
540540 variables : list [str ] = None ,
541541 period : str = None ,
542+ change_only : bool = False ,
542543 ):
543544 """Compare two simulations for a specific variable list.
544545
@@ -569,14 +570,12 @@ def compare(
569570 for variable in variables :
570571 self_col = f"{ variable } _self"
571572 other_col = f"{ variable } _other"
572- if pd .api .types .is_numeric_dtype (
573- df_combined [self_col ]
574- ) and pd .api .types .is_numeric_dtype (df_combined [other_col ]):
573+ try :
575574 df_combined [f"{ variable } _change" ] = (
576575 df_combined [other_col ] - df_combined [self_col ]
577576 )
578- else :
579- # True if different, False if same
577+ except :
578+ # For other data types, use XOR
580579 df_combined [f"{ variable } _change" ] = (
581580 df_combined [other_col ] != df_combined [self_col ]
582581 )
@@ -590,4 +589,17 @@ def compare(
590589 f"{ variable } _change" ,
591590 ]
592591 )
592+
593+ if change_only :
594+ variables_to_include = []
595+ for variable in variables :
596+ if df_combined [f"{ variable } _change" ].mean () > 0 :
597+ variables_to_include .extend (
598+ [
599+ f"{ variable } _self" ,
600+ f"{ variable } _other" ,
601+ f"{ variable } _change" ,
602+ ]
603+ )
604+ columns = variables_to_include
593605 return df_combined [columns ]
0 commit comments