Skip to content

Commit

Permalink
Make pylint happier
Browse files Browse the repository at this point in the history
  • Loading branch information
qgp committed Aug 4, 2023
1 parent c098213 commit d906f82
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
## along with this program. if not, see <https://www.gnu.org/licenses/>. ##
#############################################################################

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):
Expand Down Expand Up @@ -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}')
2 changes: 1 addition & 1 deletion machine_learning_hep/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions machine_learning_hep/processer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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}']
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions machine_learning_hep/processer_jet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
## along with this program. if not, see <https://www.gnu.org/licenses/>. ##
#############################################################################

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"
Expand Down
2 changes: 1 addition & 1 deletion machine_learning_hep/steer_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d906f82

Please sign in to comment.