Skip to content

Commit 8637917

Browse files
committed
[Python] Apply suggestions by ruff
1 parent 2d1f14d commit 8637917

File tree

6 files changed

+76
-76
lines changed

6 files changed

+76
-76
lines changed

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_roofit/_rooglobalfunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
"""
3939

40-
from ._utils import _kwargs_to_roocmdargs, _dict_to_flat_map, cpp_signature
40+
from ._utils import _dict_to_flat_map, _kwargs_to_roocmdargs, cpp_signature
4141

4242

4343
@cpp_signature(

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_th1.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ def myGaussian(x, pars):
166166
\endpythondoc
167167
"""
168168

169+
from ROOT._pythonization._memory_utils import (
170+
_SetDirectory_SetOwnership,
171+
inject_clone_releasing_ownership,
172+
inject_constructor_releasing_ownership,
173+
)
174+
169175
from . import pythonization
170-
from ROOT._pythonization._memory_utils import inject_constructor_releasing_ownership, inject_clone_releasing_ownership, _SetDirectory_SetOwnership
171176

172177
# Multiplication by constant
173178

@@ -204,7 +209,7 @@ def _FillWithNumpyArray(self, *args):
204209
# If the first argument has no len() method, we don't even need to consider
205210
# the array code path.
206211
if not isinstance(args[0], collections.abc.Sized):
207-
return self._Fill(*args)
212+
return self._Fill(*args)
208213

209214
import numpy as np
210215

tutorials/analysis/dataframe/df036_missingBranches.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ class DatasetContext:
2424
filenames = [
2525
"df036_missingBranches_py_file_1.root",
2626
"df036_missingBranches_py_file_2.root",
27-
"df036_missingBranches_py_file_3.root"
27+
"df036_missingBranches_py_file_3.root",
2828
]
2929
treenames = ["tree_1", "tree_2", "tree_3"]
3030
nentries = 5
3131

3232
def __init__(self):
33-
with ROOT.TFile(self.filenames[0], "RECREATE") as f:
33+
with ROOT.TFile(self.filenames[0], "RECREATE"):
3434
t = ROOT.TTree(self.treenames[0], self.treenames[0])
35-
x = array.array('i', [0]) # any array can also be a numpy array
36-
y = array.array('i', [0])
35+
x = array.array("i", [0]) # any array can also be a numpy array
36+
y = array.array("i", [0])
3737
t.Branch("x", x, "x/I")
3838
t.Branch("y", y, "y/I")
3939

@@ -44,9 +44,9 @@ def __init__(self):
4444

4545
t.Write()
4646

47-
with ROOT.TFile(self.filenames[1], "RECREATE") as f:
47+
with ROOT.TFile(self.filenames[1], "RECREATE"):
4848
t = ROOT.TTree(self.treenames[1], self.treenames[1])
49-
y = array.array('i', [0]) # any array can also be a numpy array
49+
y = array.array("i", [0]) # any array can also be a numpy array
5050
t.Branch("y", y, "y/I")
5151

5252
for i in range(1, self.nentries + 1):
@@ -55,9 +55,9 @@ def __init__(self):
5555

5656
t.Write()
5757

58-
with ROOT.TFile(self.filenames[2], "RECREATE") as f:
58+
with ROOT.TFile(self.filenames[2], "RECREATE"):
5959
t = ROOT.TTree(self.treenames[2], self.treenames[2])
60-
x = array.array('i', [0]) # any array can also be a numpy array
60+
x = array.array("i", [0]) # any array can also be a numpy array
6161
t.Branch("x", x, "x/I")
6262

6363
for i in range(1, self.nentries + 1):
@@ -101,11 +101,7 @@ def df036_missingBranches(dataset: DatasetContext):
101101

102102
# Example 2: provide a default value for branch y, but skip events where
103103
# branch x is missing
104-
display_2 = (
105-
df.DefaultValueFor("y", default_value)
106-
.FilterAvailable("x")
107-
.Display(columnList=("x", "y"), nRows=15)
108-
)
104+
display_2 = df.DefaultValueFor("y", default_value).FilterAvailable("x").Display(columnList=("x", "y"), nRows=15)
109105

110106
# Example 3: only keep events where branch y is missing and display values for branch x
111107
display_3 = df.FilterMissing("y").Display(columnList=("x",), nRows=15)

tutorials/analysis/dataframe/df037_TTreeEventMatching.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class DatasetContext:
3030
aux_tree_name_2 = "auxdata_2"
3131

3232
def __init__(self):
33-
with ROOT.TFile(self.main_file, "RECREATE") as f:
33+
with ROOT.TFile(self.main_file, "RECREATE"):
3434
main_tree = ROOT.TTree(self.main_tree_name, self.main_tree_name)
35-
idx = array.array('i', [0]) # any array can also be a numpy array
36-
x = array.array('i', [0])
35+
idx = array.array("i", [0]) # any array can also be a numpy array
36+
x = array.array("i", [0])
3737
main_tree.Branch("idx", idx, "idx/I")
3838
main_tree.Branch("x", x, "x/I")
3939

@@ -50,10 +50,10 @@ def __init__(self):
5050
main_tree.Write()
5151

5252
# The first auxiliary file has matching indices 1 and 2, but not 3
53-
with ROOT.TFile(self.aux_file_1, "RECREATE") as f:
53+
with ROOT.TFile(self.aux_file_1, "RECREATE"):
5454
aux_tree_1 = ROOT.TTree(self.aux_tree_name_1, self.aux_tree_name_1)
55-
idx = array.array('i', [0]) # any array can also be a numpy array
56-
y = array.array('i', [0])
55+
idx = array.array("i", [0]) # any array can also be a numpy array
56+
y = array.array("i", [0])
5757
aux_tree_1.Branch("idx", idx, "idx/I")
5858
aux_tree_1.Branch("y", y, "y/I")
5959

@@ -67,10 +67,10 @@ def __init__(self):
6767
aux_tree_1.Write()
6868

6969
# The second auxiliary file has matching indices 1 and 3, but not 2
70-
with ROOT.TFile(self.aux_file_2, "RECREATE") as f:
70+
with ROOT.TFile(self.aux_file_2, "RECREATE"):
7171
aux_tree_2 = ROOT.TTree(self.aux_tree_name_2, self.aux_tree_name_2)
72-
idx = array.array('i', [0]) # any array can also be a numpy array
73-
z = array.array('i', [0])
72+
idx = array.array("i", [0]) # any array can also be a numpy array
73+
z = array.array("i", [0])
7474
aux_tree_2.Branch("idx", idx, "idx/I")
7575
aux_tree_2.Branch("z", z, "z/I")
7676

@@ -132,8 +132,7 @@ def df037_TTreeEventMatching(dataset: DatasetContext):
132132
.DefaultValueFor(aux_tree_1_coly, default_value)
133133
.DefaultValueFor(aux_tree_2_colidx, default_value)
134134
.DefaultValueFor(aux_tree_2_colz, default_value)
135-
.Display(
136-
("idx", aux_tree_1_colidx, aux_tree_2_colidx, "x", aux_tree_1_coly, aux_tree_2_colz))
135+
.Display(("idx", aux_tree_1_colidx, aux_tree_2_colidx, "x", aux_tree_1_coly, aux_tree_2_colz))
137136
)
138137

139138
# Example 2: skip the entire entry when there was no match for a column
@@ -143,12 +142,11 @@ def df037_TTreeEventMatching(dataset: DatasetContext):
143142
df.DefaultValueFor(aux_tree_2_colidx, default_value)
144143
.DefaultValueFor(aux_tree_2_colz, default_value)
145144
.FilterAvailable(aux_tree_1_coly)
146-
.Display(
147-
("idx", aux_tree_1_colidx, aux_tree_2_colidx, "x", aux_tree_1_coly, aux_tree_2_colz))
145+
.Display(("idx", aux_tree_1_colidx, aux_tree_2_colidx, "x", aux_tree_1_coly, aux_tree_2_colz))
148146
)
149147

150-
# Example 3: Keep entries from the main tree for which there is no
151-
# corresponding match in entries of the first auxiliary tree
148+
# Example 3: Keep entries from the main tree for which there is no
149+
# corresponding match in entries of the first auxiliary tree
152150
display_3 = df.FilterMissing(aux_tree_1_colidx).Display(("idx", "x"))
153151

154152
print("Example 1: provide default values for all columns")

tutorials/roofit/roostats/StandardHypoTestDemo.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
# \author Lorenzo Moneta (C++ version), and P. P. (Python translation)
3030

3131
import array
32-
from warnings import warn
3332
from gc import collect
33+
from warnings import warn
3434

3535
import ROOT
3636

@@ -151,7 +151,7 @@ def StandardHypoTestDemo(
151151
# get the workspace out of the file
152152
w = file.Get(workspaceName)
153153
if not w:
154-
print(f"workspace not found")
154+
print("workspace not found")
155155
return
156156

157157
w.Print()
@@ -165,7 +165,7 @@ def StandardHypoTestDemo(
165165
# make sure ingredients are found
166166
if not data or not sbModel:
167167
w.Print()
168-
print(f"data or ModelConfig was not found")
168+
print("data or ModelConfig was not found")
169169
return
170170

171171
# make b model
@@ -176,14 +176,14 @@ def StandardHypoTestDemo(
176176
if noSystematics:
177177
nuisPar = sbModel.GetNuisanceParameters()
178178
if nuisPar and nuisPar.getSize() > 0:
179-
print(f"StandardHypoTestInvDemo")
179+
print("StandardHypoTestInvDemo")
180180
print(" - Switch off all systematics by setting them constant to their initial values")
181-
RooStats.SetAllConstant(nuisPar)
181+
ROOT.RooStats.SetAllConstant(nuisPar)
182182

183183
if bModel:
184184
bnuisPar = bModel.GetNuisanceParameters()
185185
if bnuisPar:
186-
RooStats.SetAllConstant(bnuisPar)
186+
ROOT.RooStats.SetAllConstant(bnuisPar)
187187

188188
if not bModel:
189189
ROOT.Info("StandardHypoTestInvDemo", "The background model {} does not exist".format(modelBName))
@@ -298,7 +298,7 @@ def StandardHypoTestDemo(
298298
nuisPdf.GetName(),
299299
)
300300
else:
301-
Error(
301+
ROOT.Error(
302302
"StandardHypoTestDemo",
303303
"Cannot run Hybrid calculator because no prior on the nuisance parameter is "
304304
"specified or can be derived",
@@ -396,8 +396,8 @@ def StandardHypoTestDemo(
396396
htExp = ROOT.RooStats.HypoTestResult("Expected Result")
397397
htExp.Append(htr)
398398
# find quantiles in alt (S+B) distribution
399-
p = array.array('d', [i for i in range(5)])
400-
q = array.array('d', [0.5 for i in range(5)])
399+
p = array.array("d", [i for i in range(5)])
400+
q = array.array("d", [0.5 for i in range(5)])
401401
for i in range(5):
402402
sig = -2 + i
403403
p[i] = ROOT.Math.normal_cdf(sig, 1)

0 commit comments

Comments
 (0)