@@ -319,6 +319,19 @@ def __add__(self, other):
319319 else :
320320 raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
321321
322+ @inheritdoc (Container )
323+ def __iadd__ (self , other ):
324+ if isinstance (other , Label ):
325+ if self .keySet != other .keySet :
326+ raise ContainerException ("cannot add Labels because keys differ:\n {0}\n {1}" .format (", " .join (sorted (self .keys )), ", " .join (sorted (other .keys ))))
327+ self .entries += other .entries
328+ for k in self .keys :
329+ v = self (k )
330+ v += other (k )
331+ return self
332+ else :
333+ raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
334+
322335 @inheritdoc (Container )
323336 def __mul__ (self , factor ):
324337 if math .isnan (factor ) or factor <= 0.0 :
@@ -360,6 +373,9 @@ def _numpy(self, data, weights, shape):
360373 else :
361374 self .entries += float (weights * shape [0 ])
362375
376+ def _sparksql (self , jvm , converter ):
377+ return converter .Label ([jvm .scala .Tuple2 (k , v ._sparksql (jvm , converter )) for k , v in self .pairs .items ()])
378+
363379 @property
364380 def children (self ):
365381 """List of sub-aggregators, to make it possible to walk the tree."""
@@ -517,6 +533,19 @@ def __add__(self, other):
517533 else :
518534 raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
519535
536+ @inheritdoc (Container )
537+ def __iadd__ (self , other ):
538+ if isinstance (other , UntypedLabel ):
539+ if self .keySet != other .keySet :
540+ raise ContainerException ("cannot add UntypedLabels because keys differ:\n {0}\n {1}" .format (", " .join (sorted (self .keys )), ", " .join (sorted (other .keys ))))
541+ self .entries += other .entries
542+ for k in self .keys :
543+ v = self (k )
544+ v += other (k )
545+ return self
546+ else :
547+ raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
548+
520549 @inheritdoc (Container )
521550 def __mul__ (self , factor ):
522551 if math .isnan (factor ) or factor <= 0.0 :
@@ -558,6 +587,9 @@ def _numpy(self, data, weights, shape):
558587 else :
559588 self .entries += float (weights * shape [0 ])
560589
590+ def _sparksql (self , jvm , converter ):
591+ return converter .UntypedLabel ([jvm .scala .Tuple2 (k , v ._sparksql (jvm , converter )) for k , v in self .pairs .items ()])
592+
561593 @property
562594 def children (self ):
563595 """List of sub-aggregators, to make it possible to walk the tree."""
@@ -723,6 +755,18 @@ def __add__(self, other):
723755 else :
724756 raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
725757
758+ @inheritdoc (Container )
759+ def __iadd__ (self , other ):
760+ if isinstance (other , Index ):
761+ if self .size != other .size :
762+ raise ContainerException ("cannot add Indexes because they have different sizes: ({0} vs {1})" .format (self .size , other .size ))
763+ self .entries += other .entries
764+ for x , y in zip (self .values , other .values ):
765+ x += y
766+ return self
767+ else :
768+ raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
769+
726770 @inheritdoc (Container )
727771 def __mul__ (self , factor ):
728772 if math .isnan (factor ) or factor <= 0.0 :
@@ -762,6 +806,9 @@ def _numpy(self, data, weights, shape):
762806 else :
763807 self .entries += float (weights * shape [0 ])
764808
809+ def _sparksql (self , jvm , converter ):
810+ return converter .Index ([v ._sparksql (jvm , converter ) for v in self .values ])
811+
765812 @property
766813 def children (self ):
767814 """List of sub-aggregators, to make it possible to walk the tree."""
@@ -934,6 +981,18 @@ def __add__(self, other):
934981 else :
935982 raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
936983
984+ @inheritdoc (Container )
985+ def __iadd__ (self , other ):
986+ if isinstance (other , Branch ):
987+ if self .size != other .size :
988+ raise ContainerException ("cannot add Branches because they have different sizes: ({0} vs {1})" .format (self .size , other .size ))
989+ self .entries += other .entries
990+ for x , y in zip (self .values , other .values ):
991+ x += y
992+ return self
993+ else :
994+ raise ContainerException ("cannot add {0} and {1}" .format (self .name , other .name ))
995+
937996 @inheritdoc (Container )
938997 def __mul__ (self , factor ):
939998 if math .isnan (factor ) or factor <= 0.0 :
@@ -973,6 +1032,9 @@ def _numpy(self, data, weights, shape):
9731032 else :
9741033 self .entries += float (weights * shape [0 ])
9751034
1035+ def _sparksql (self , jvm , converter ):
1036+ return converter .Branch (* [v ._sparksql (jvm , converter ) for v in self .values ])
1037+
9761038 @property
9771039 def children (self ):
9781040 """List of sub-aggregators, to make it possible to walk the tree."""
0 commit comments