@@ -868,11 +868,15 @@ class AuxiliaryResult(calculation.Calculation):
868868 """
869869 Produce an additional output, but then pass the main result on.
870870 """
871- def __init__ (self , subcalc_main , subcalc_aux , auxname ):
872- super (AuxiliaryResult , self ).__init__ ([subcalc_main .unitses [0 ], subcalc_aux .unitses [0 ]] + subcalc_main .unitses [1 :])
871+ def __init__ (self , subcalc_main , subcalc_aux , auxname , keeplastonly = True ):
872+ if keeplastonly :
873+ super (AuxiliaryResult , self ).__init__ ([subcalc_main .unitses [0 ], subcalc_aux .unitses [0 ]] + subcalc_main .unitses [1 :])
874+ else :
875+ super (AuxiliaryResult , self ).__init__ ([subcalc_main .unitses [0 ]] + subcalc_aux .unitses + subcalc_main .unitses [1 :])
873876 self .subcalc_main = subcalc_main
874877 self .subcalc_aux = subcalc_aux
875878 self .auxname = auxname
879+ self .keeplastonly = keeplastonly
876880
877881 def format (self , lang , * args , ** kwargs ):
878882 beforeauxlen = len (formatting .format_labels )
@@ -884,7 +888,7 @@ def format(self, lang, *args, **kwargs):
884888 def apply (self , region , * args , ** kwargs ):
885889 subapp_main = self .subcalc_main .apply (region , * args , ** kwargs )
886890 subapp_aux = self .subcalc_aux .apply (region , * args , ** kwargs )
887- return AuxiliaryResultApplication (region , subapp_main , subapp_aux )
891+ return AuxiliaryResultApplication (region , subapp_main , subapp_aux , self . keeplastonly )
888892
889893 def partial_derivative (self , covariate , covarunit ):
890894 """
@@ -899,7 +903,10 @@ def column_info(self):
899903 infos_aux = self .subcalc_aux .column_info ()
900904 infos_aux [0 ]['name' ] = self .auxname
901905
902- return [infos_main [0 ], infos_aux [0 ]] + infos_main [1 :]
906+ if self .keeplastonly :
907+ return [infos_main [0 ], infos_aux [0 ]] + infos_main [1 :]
908+ else :
909+ return [infos_main [0 ]] + infos_aux + infos_main [1 :]
903910
904911 @staticmethod
905912 def describe ():
@@ -927,16 +934,20 @@ class AuxiliaryResultApplication(calculation.Application):
927934 """
928935 Perform both main and auxiliary calculation, and order as main[0], aux, main[1:]
929936 """
930- def __init__ (self , region , subapp_main , subapp_aux ):
937+ def __init__ (self , region , subapp_main , subapp_aux , keeplastonly ):
931938 super (AuxiliaryResultApplication , self ).__init__ (region )
932939 self .subapp_main = subapp_main
933940 self .subapp_aux = subapp_aux
941+ self .keeplastonly = keeplastonly
934942
935943 def push (self , ds ):
936944 for yearresult in self .subapp_main .push (ds ):
937945 for yearresult_aux in self .subapp_aux .push (ds ):
938- next # Just take the last one
939- yield list (yearresult [0 :2 ]) + [yearresult_aux [1 ]] + list (yearresult [2 :])
946+ pass # Just take the last one
947+ if self .keeplastonly :
948+ yield list (yearresult [0 :2 ]) + [yearresult_aux [1 ]] + list (yearresult [2 :])
949+ else :
950+ yield list (yearresult [0 :2 ]) + list (yearresult_aux [1 :]) + list (yearresult [2 :])
940951
941952 def done (self ):
942953 self .subapp_aux .done ()
0 commit comments