Skip to content

Commit 3aeb567

Browse files
committed
Mega linter autofix
1 parent e45b4e0 commit 3aeb567

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

machine_learning_hep/processer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def dfread(rdir, trees, cols, idx_name=None):
417417
if idx_name:
418418
# df.rename_axis(idx_name, inplace=True)
419419
df[idx_name] = df.index
420-
df.set_index(["df", idx_name], inplace=True)
420+
df = df.set_index(["df", idx_name])
421421
return df
422422
except Exception as e:
423423
self.logger.exception("Failed to read data from trees: %s", str(e))

machine_learning_hep/processerdhadrons.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def __init__(
9292
self.p_mass_fit_lim = datap["analysis"][self.typean]["mass_fit_lim"]
9393
self.p_bin_width = datap["analysis"][self.typean]["bin_width"]
9494
limits_mass = datap["analysis"][self.typean]["mass_fit_lim"]
95-
nbins_mass = int(round((limits_mass[1] - limits_mass[0]) / self.p_bin_width))
96-
self.p_num_bins = int(round((self.p_mass_fit_lim[1] - self.p_mass_fit_lim[0]) / self.p_bin_width))
95+
nbins_mass = round((limits_mass[1] - limits_mass[0]) / self.p_bin_width)
96+
self.p_num_bins = round((self.p_mass_fit_lim[1] - self.p_mass_fit_lim[0]) / self.p_bin_width)
9797
self.s_presel_gen_eff = datap["analysis"][self.typean]["presel_gen_eff"]
9898

9999
self.lpt_finbinmin = datap["analysis"][self.typean]["sel_an_binmin"]
@@ -113,10 +113,7 @@ def process_histomass_single(self, index):
113113
myfile = TFile.Open(self.l_histomass[index], "recreate")
114114
dfevtorig = read_df(self.l_evtorig[index])
115115
neventsorig = len(dfevtorig)
116-
if self.s_evtsel is not None:
117-
dfevtevtsel = dfevtorig.query(self.s_evtsel)
118-
else:
119-
dfevtevtsel = dfevtorig
116+
dfevtevtsel = dfevtorig.query(self.s_evtsel) if self.s_evtsel is not None else dfevtorig
120117
neventsafterevtsel = len(dfevtevtsel)
121118

122119
# validation plot for event selection
@@ -246,14 +243,11 @@ def do_eff_single(ipt, bin_id, df_mc_gen, df_mc_reco, sel_column, bincounter, hi
246243
df_gen_sel = df_mc_gen.loc[(df_mc_gen[sel_column] == 1) & (df_mc_gen.ismcsignal == 1)]
247244
df_reco_presel = df_mc_reco.loc[(df_mc_reco[sel_column] == 1) & (df_mc_reco.ismcsignal == 1)]
248245
df_reco_sel = None
249-
if self.doml is True:
250-
df_reco_sel = df_reco_presel.query(self.l_selml[bin_id])
251-
else:
252-
df_reco_sel = df_reco_presel.copy()
246+
df_reco_sel = df_reco_presel.query(self.l_selml[bin_id]) if self.doml is True else df_reco_presel.copy()
253247
if self.do_custom_analysis_cuts:
254248
df_reco_sel = self.apply_cuts_ptbin(df_reco_sel, ipt)
255249

256-
for df, hist in zip((df_gen_sel, df_reco_presel, df_reco_sel), hists):
250+
for df, hist in zip((df_gen_sel, df_reco_presel, df_reco_sel), hists, strict=False):
257251
val = len(df)
258252
err = math.sqrt(val)
259253
hist.SetBinContent(bincounter + 1, val)

machine_learning_hep/utilities.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ def write_df(dfo, path):
128128

129129
def read_df(path, **kwargs):
130130
try:
131-
if path.endswith(".parquet"):
132-
df = pd.read_parquet(path, **kwargs)
133-
else:
134-
df = pickle.load(openfile(path, "rb"))
131+
df = pd.read_parquet(path, **kwargs) if path.endswith(".parquet") else pickle.load(openfile(path, "rb"))
135132
except Exception as e: # pylint: disable=broad-except
136133
logger.critical("failed to open file <%s>: %s", path, str(e))
137134
sys.exit()
@@ -160,7 +157,7 @@ def conv_none(value):
160157
mask_by_value_dict[mc["column"]] = {mc["find_by_value"]: conv_none(mc["mask_with"])}
161158

162159
# Mask all we can do by value
163-
df_to_mask.replace(mask_by_value_dict, inplace=True)
160+
df_to_mask = df_to_mask.replace(mask_by_value_dict)
164161

165162
# Now mask all which are searched by query
166163
for mc in mask_by_query_list:
@@ -308,12 +305,12 @@ def make_latex_table(column_names, row_names, rows, caption=None, save_path="./t
308305
columns = "|".join(["c"] * (len(column_names) + 1))
309306
f.write("\\begin{tabular}{" + columns + "}\n")
310307
f.write("\\hline\n")
311-
columns = "&".join([""] + column_names)
308+
columns = "&".join(["", *column_names])
312309
columns = columns.replace("_", "\\_")
313310
f.write(columns + "\\\\\n")
314311
f.write("\\hline\\hline\n")
315-
for rn, row in zip(row_names, rows):
316-
row_string = "&".join([rn] + row)
312+
for rn, row in zip(row_names, rows, strict=False):
313+
row_string = "&".join([rn, *row])
317314
row_string = row_string.replace("_", "\\_")
318315
f.write(row_string + "\\\\\n")
319316
f.write("\\end{tabular}\n")
@@ -411,10 +408,7 @@ def equal_axis_list(axis1, list2, precision=10):
411408
bins = get_bins(axis1)
412409
if len(bins) != len(list2):
413410
return False
414-
for i, j in zip(bins, list2):
415-
if round(i, precision) != round(j, precision):
416-
return False
417-
return True
411+
return all(round(i, precision) == round(j, precision) for i, j in zip(bins, list2, strict=False))
418412

419413

420414
def equal_binning(his1, his2):
@@ -432,9 +426,7 @@ def equal_binning_lists(his, list_x=None, list_y=None, list_z=None):
432426
return False
433427
if list_y is not None and not equal_axis_list(his.GetYaxis(), list_y):
434428
return False
435-
if list_z is not None and not equal_axis_list(his.GetZaxis(), list_z):
436-
return False
437-
return True
429+
return not (list_z is not None and not equal_axis_list(his.GetZaxis(), list_z))
438430

439431

440432
def folding(h_input, response_matrix, h_output):
@@ -943,13 +935,13 @@ def plot_latex(latex):
943935
# set canvas margins
944936
if isinstance(margins_c, list) and len(margins_c) > 0:
945937
for setter, value in zip(
946-
[can.SetBottomMargin, can.SetLeftMargin, can.SetTopMargin, can.SetRightMargin], margins_c
938+
[can.SetBottomMargin, can.SetLeftMargin, can.SetTopMargin, can.SetRightMargin], margins_c, strict=False
947939
):
948940
setter(value)
949941
# set logarithmic scale for selected axes
950942
log_y = False
951943
if isinstance(logscale, str) and len(logscale) > 0:
952-
for setter, axis in zip([can.SetLogx, can.SetLogy, can.SetLogz], ["x", "y", "z"]):
944+
for setter, axis in zip([can.SetLogx, can.SetLogy, can.SetLogz], ["x", "y", "z"], strict=False):
953945
if axis in logscale:
954946
setter()
955947
if axis == "y":

0 commit comments

Comments
 (0)