From d906f82d5ae9b3bb184dcab6ab03c599b63c93a7 Mon Sep 17 00:00:00 2001 From: Jochen Klein Date: Fri, 4 Aug 2023 09:53:43 +0200 Subject: [PATCH] Make pylint happier --- .../{analyzer_D0jets.py => analyzer_jets.py} | 14 ++++---- machine_learning_hep/logger.py | 2 +- machine_learning_hep/processer.py | 34 +++++++++---------- machine_learning_hep/processer_jet.py | 4 +-- machine_learning_hep/steer_analysis.py | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) rename machine_learning_hep/analysis/{analyzer_D0jets.py => analyzer_jets.py} (90%) diff --git a/machine_learning_hep/analysis/analyzer_D0jets.py b/machine_learning_hep/analysis/analyzer_jets.py similarity index 90% rename from machine_learning_hep/analysis/analyzer_D0jets.py rename to machine_learning_hep/analysis/analyzer_jets.py index 54dd904d50..eb7c0d97fb 100644 --- a/machine_learning_hep/analysis/analyzer_D0jets.py +++ b/machine_learning_hep/analysis/analyzer_jets.py @@ -12,13 +12,13 @@ ## along with this program. if not, see . ## ############################################################################# -from machine_learning_hep.analysis.analyzer import Analyzer - -import munch -from ROOT import TFile, TH1F import os +import munch # pylint: disable=import-error, no-name-in-module +from ROOT import TFile # pylint: disable=import-error, no-name-in-module + +from machine_learning_hep.analysis.analyzer import Analyzer -class AnalyzerD0jets(Analyzer): +class AnalyzerJets(Analyzer): species = "analyzer" def __init__(self, datap, case, typean, period): @@ -53,5 +53,5 @@ def qa(self): # pylint: disable=too-many-branches, too-many-locals histonorm = rfile.Get("histonorm") if not histonorm: self.logger.critical('histonorm not found') - self.p_nevents = histonorm.GetBinContent(1) - self.logger.debug("Number of selected event: %g" % self.p_nevents) + p_nevents = histonorm.GetBinContent(1) + self.logger.debug(f'Number of selected event: {p_nevents}') diff --git a/machine_learning_hep/logger.py b/machine_learning_hep/logger.py index 8a5391fcc8..1e401e684e 100644 --- a/machine_learning_hep/logger.py +++ b/machine_learning_hep/logger.py @@ -102,7 +102,7 @@ def configure_logger(debug, logfile=None): logger.setLevel(logging.INFO) sh = logging.StreamHandler() - formatter = MLLoggerFormatter(color=lambda : getattr(sh.stream, 'isatty', None)) # pylint: disable=C0326 + formatter = MLLoggerFormatter(color=lambda : getattr(sh.stream, 'isatty', None)) sh.setFormatter(formatter) logger.addHandler(sh) diff --git a/machine_learning_hep/processer.py b/machine_learning_hep/processer.py index 4fd0497a6c..7aadcbd174 100755 --- a/machine_learning_hep/processer.py +++ b/machine_learning_hep/processer.py @@ -322,17 +322,17 @@ def unpack(self, file_index): # df['df'] = df_no # dfreco = pd.concat([dfreco, df]) - def benchmark(func): - def inner(*args, **kwargs): - t_start = time.time() - ret = func(*args, *kwargs) - t_end = time.time() - self.logger.info("Delta t = %g", t_end - t_start) - return ret - return inner + # def benchmark(func): + # def inner(*args, **kwargs): + # t_start = time.time() + # ret = func(*args, *kwargs) + # t_end = time.time() + # self.logger.info("Delta t = %g", t_end - t_start) + # return ret + # return inner with uproot.open(self.l_root[file_index]) as rfile: - def read_df(var, tree): + def read_df(var, tree): # return tree.arrays(expressions=var, library="pd") return pd.DataFrame(columns=var, data=tree.arrays(expressions=var, library="np")) @@ -357,7 +357,7 @@ def read_df(var, tree): df['df'] = df_no dfevtorig = pd.concat([dfevtorig, df]) except Exception as e: # pylint: disable=broad-except - self.logger.critical('Failed to read event tree:', str(e)) + self.logger.critical(f'Failed to read event tree: {str(e)}') sys.exit() if self.n_treejetreco: @@ -367,7 +367,7 @@ def read_df(var, tree): df['df'] = df_no dfjetreco = pd.concat([dfjetreco, df]) except Exception as e: # pylint: disable=broad-except - self.logger.critical('Failed to read jet tree', str(e)) + self.logger.critical(f'Failed to read jet tree {str(e)}') sys.exit() if self.n_treejetsubreco: @@ -377,7 +377,7 @@ def read_df(var, tree): df['df'] = df_no dfjetsubreco = pd.concat([dfjetsubreco, df]) except Exception as e: # pylint: disable=broad-except - self.logger.critical('Failed to read jetsub tree', str(e)) + self.logger.critical(f'Failed to read jetsub tree {str(e)}') sys.exit() treereco = rfile[f'{key}/{self.n_treereco}'] @@ -386,9 +386,9 @@ def read_df(var, tree): df['df'] = df_no dfreco = pd.concat([dfreco, df]) except Exception as e: # pylint: disable=broad-except - self.logger.critical('Failed to read candidate tree:', str(e)) + self.logger.critical(f'Failed to read candidate tree: {str(e)}') sys.exit() - + dfevtorig = selectdfquery(dfevtorig, self.s_cen_unp) dfevtorig = dfevtorig.reset_index(drop=True) pickle.dump(dfevtorig, openfile(self.l_evtorig[file_index], "wb"), protocol=4) @@ -495,7 +495,7 @@ def read_df(var, tree): self.logger.debug(f'finished unpacking: {self.l_root[file_index]}') if self.mcordata == "mc": - if (self.n_treejetgen): + if self.n_treejetgen: treejetgen = uproot.open(self.l_root[file_index])[self.n_treejetgen] try: dfjetgen = treejetgen.arrays(expressions=self.v_jet, library="pd") @@ -504,7 +504,7 @@ def read_df(var, tree): print('I am sorry, I am dying ...\n \n \n') sys.exit() - if (self.n_treejetsubgen): + if self.n_treejetsubgen: treejetsubgen = uproot.open(self.l_root[file_index])[self.n_treejetsubgen] try: dfjetsubgen = treejetsubgen.arrays(expressions=self.v_jetsub, library="pd") @@ -513,7 +513,7 @@ def read_df(var, tree): print('I am sorry, I am dying ...\n \n \n') sys.exit() - if (dfjetgen and dfjetsubgen): + if dfjetgen and dfjetsubgen: dfjetgen = pd.merge(dfjetgen, dfjetsubgen, on=self.v_jetsubmatch) treegen = uproot.open(self.l_root[file_index])[self.n_treegen] diff --git a/machine_learning_hep/processer_jet.py b/machine_learning_hep/processer_jet.py index 46301f39ab..8e2987d704 100644 --- a/machine_learning_hep/processer_jet.py +++ b/machine_learning_hep/processer_jet.py @@ -12,10 +12,10 @@ ## along with this program. if not, see . ## ############################################################################# +from ROOT import TFile, TH1F # pylint: disable=import-error, no-name-in-module +import pickle from machine_learning_hep.processer import Processer from machine_learning_hep.utilities import openfile, selectdfrunlist -from ROOT import TFile, TH1F, TH2F -import pickle class ProcesserJets(Processer): # pylint: disable=invalid-name, too-many-instance-attributes species = "processer" diff --git a/machine_learning_hep/steer_analysis.py b/machine_learning_hep/steer_analysis.py index fa44feeeee..141f1cfd00 100644 --- a/machine_learning_hep/steer_analysis.py +++ b/machine_learning_hep/steer_analysis.py @@ -48,7 +48,7 @@ from machine_learning_hep.analysis.analyzerdhadrons import AnalyzerDhadrons from machine_learning_hep.analysis.analyzerdhadrons_mult import AnalyzerDhadrons_mult from machine_learning_hep.analysis.analyzer_jet import AnalyzerJet -from machine_learning_hep.analysis.analyzer_D0jets import AnalyzerD0jets +from machine_learning_hep.analysis.analyzer_jets import AnalyzerJets from machine_learning_hep.processer_jet import ProcesserJets from machine_learning_hep.analysis.systematics import SystematicsMLWP