|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2016 DIANA-HEP |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import histogrammar.primitives.average |
| 18 | +import histogrammar.primitives.bag |
| 19 | +import histogrammar.primitives.bin |
| 20 | +import histogrammar.primitives.categorize |
| 21 | +import histogrammar.primitives.centrallybin |
| 22 | +import histogrammar.primitives.collection |
| 23 | +import histogrammar.primitives.count |
| 24 | +import histogrammar.primitives.deviate |
| 25 | +import histogrammar.primitives.fraction |
| 26 | +import histogrammar.primitives.irregularlybin |
| 27 | +import histogrammar.primitives.minmax |
| 28 | +import histogrammar.primitives.select |
| 29 | +import histogrammar.primitives.sparselybin |
| 30 | +import histogrammar.primitives.stack |
| 31 | +import histogrammar.primitives.sum |
| 32 | + |
| 33 | +def addMethods(df): |
| 34 | + def histogrammar(self, h): |
| 35 | + converter = self.df._sc._jvm.org.dianahep.histogrammar.sparksql.pyspark.AggregatorConverter() |
| 36 | + agg = h._sparksql(self.df._sc._jvm, converter) |
| 37 | + result = converter.histogrammar(self.df._jdf, agg) |
| 38 | + return Factory.fromJson(jsonlib.loads(result.toJsonString())) |
| 39 | + |
| 40 | + def Average(self, quantity): |
| 41 | + return self.histogrammar(histogrammar.primitives.average.Average(quantity)) |
| 42 | + |
| 43 | + def Bag(self, quantity, range): |
| 44 | + return self.histogrammar(histogrammar.primitives.bag.Bag(quantity, range)) |
| 45 | + |
| 46 | + # def Bin(self, num, low, high, quantity, value=histogrammar.primitives.count.Count(), underflow=histogrammar.primitives.count.Count(), overflow=histogrammar.primitives.count.Count(), nanflow=histogrammar.primitives.count.Count()): |
| 47 | + # return self.histogrammar() |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + # df.histogrammar = types.MethodType(histogrammar, df) |
| 53 | + |
| 54 | + # hg.Average = types.MethodType(Average , df) |
| 55 | + # hg.Bag = types.MethodType(Bag , df) |
| 56 | + # hg.Bin = types.MethodType(Bin , df) |
| 57 | + # hg.Categorize = types.MethodType(Categorize , df) |
| 58 | + # hg.CentrallyBin = types.MethodType(CentrallyBin , df) |
| 59 | + # hg.Label = types.MethodType(Label , df) |
| 60 | + # hg.UntypedLabel = types.MethodType(UntypedLabel , df) |
| 61 | + # hg.Index = types.MethodType(Index , df) |
| 62 | + # hg.Branch = types.MethodType(Branch , df) |
| 63 | + # hg.Count = types.MethodType(Count , df) |
| 64 | + # hg.Deviate = types.MethodType(Deviate , df) |
| 65 | + # hg.Fraction = types.MethodType(Fraction , df) |
| 66 | + # hg.IrregularlyBin = types.MethodType(IrregularlyBin , df) |
| 67 | + # hg.Minimize = types.MethodType(Minimize , df) |
| 68 | + # hg.Maximize = types.MethodType(Maximize , df) |
| 69 | + # hg.Select = types.MethodType(Select , df) |
| 70 | + # hg.SparselyBin = types.MethodType(SparselyBin , df) |
| 71 | + # hg.Stack = types.MethodType(Stack , df) |
| 72 | + # hg.Sum = types.MethodType(Sum , df) |
0 commit comments