Skip to content

Commit c0f080d

Browse files
committed
ruff format
1 parent 32ecc1d commit c0f080d

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
myResult.Parameters()
5252
5353
# Get the error of the first parameter
54-
myResult.ParError(0)
54+
myResult.ParError(0)
5555
\endcode
5656
5757
@@ -80,10 +80,10 @@ def myGaussian(x, pars):
8080
'''
8181
Defines a Gaussian function
8282
'''
83-
return pars[0]*np.exp(-0.5* pow(x[0] - pars[1], 2))
83+
return pars[0]*np.exp(-0.5* pow(x[0] - pars[1], 2))
8484
8585
# Initialize from the Python function with the range -5 to +5, with two parameters to fit, and a one-dimensional input x
86-
myTF1 = ROOT.TF1("myFunction", myGaussian, -5, 5, npar=2, ndim=1)
86+
myTF1 = ROOT.TF1("myFunction", myGaussian, -5, 5, npar=2, ndim=1)
8787
8888
# Create a 1D histogram and initialize it with the built-in ROOT Gaussian "gaus"
8989
myTH1D = ROOT.TH1D("th1d", "Test", 200, -5, 5)
@@ -176,6 +176,7 @@ def myGaussian(x, pars):
176176

177177
# Multiplication by constant
178178

179+
179180
def _imul(self, c):
180181
# Parameters:
181182
# - self: histogram
@@ -185,6 +186,7 @@ def _imul(self, c):
185186
self.Scale(c)
186187
return self
187188

189+
188190
# Fill with array-like data
189191
def _FillWithArrayTH1(self, *args):
190192
"""
@@ -216,12 +218,10 @@ def _FillWithArrayTH1(self, *args):
216218
data = np.asanyarray(args[0], dtype=np.float64)
217219
n = len(data)
218220

219-
if len(args) >=2 and args[1] is not None:
221+
if len(args) >= 2 and args[1] is not None:
220222
weights = np.asanyarray(args[1], dtype=np.float64)
221223
if len(weights) != n:
222-
raise ValueError(
223-
f"Length mismatch: data length ({n}) != weights length ({len(weights)})"
224-
)
224+
raise ValueError(f"Length mismatch: data length ({n}) != weights length ({len(weights)})")
225225
else:
226226
weights = np.ones(n)
227227

@@ -254,7 +254,7 @@ def _enable_numpy_fill(klass):
254254
klass.Fill = _FillWithArrayTH1
255255

256256

257-
@pythonization('TH1')
257+
@pythonization("TH1")
258258
def pythonize_th1(klass):
259259
# Parameters:
260260
# klass: class to be pythonized

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
# For the list of contributors see $ROOTSYS/README/CREDITS. #
99
################################################################################
1010

11-
from . import pythonization
1211
from ROOT._pythonization._memory_utils import inject_constructor_releasing_ownership
1312

13+
from . import pythonization
14+
1415

1516
# Fill with array-like data
1617
def _FillWithArrayTH2(self, *args):
@@ -47,23 +48,20 @@ def _FillWithArrayTH2(self, *args):
4748
y = np.asanyarray(args[1], dtype=np.float64)
4849

4950
if len(x) != len(y):
50-
raise ValueError(
51-
f"Length mismatch: x length ({len(x)}) != y length ({len(y)})"
52-
)
51+
raise ValueError(f"Length mismatch: x length ({len(x)}) != y length ({len(y)})")
5352

5453
n = len(x)
5554

56-
if len(args) >=3 and args[2] is not None:
55+
if len(args) >= 3 and args[2] is not None:
5756
weights = np.asanyarray(args[2], dtype=np.float64)
5857
if len(weights) != n:
59-
raise ValueError(
60-
f"Length mismatch: data length ({n}) != weights length ({len(weights)})"
61-
)
58+
raise ValueError(f"Length mismatch: data length ({n}) != weights length ({len(weights)})")
6259
else:
6360
weights = np.ones(n)
6461

6562
return self.FillN(n, x, y, weights)
6663

64+
6765
# The constructors need to be pythonized for each derived class separately:
6866
_th2_derived_classes_to_pythonize = [
6967
"TH2C",

bindings/pyroot/pythonizations/test/th2_fillN.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ def _run_fill_test(self, x_data, y_data):
2828

2929
for i in range(nbins):
3030
for j in range(nbins):
31-
self.assertAlmostEqual(
32-
verbose_hist.GetBinContent(i, j),
33-
simple_hist.GetBinContent(i, j)
34-
)
31+
self.assertAlmostEqual(verbose_hist.GetBinContent(i, j), simple_hist.GetBinContent(i, j))
3532

3633
# Test filling with weights
3734
weights_np = np.linspace(0.1, 0.9, n)
@@ -42,10 +39,7 @@ def _run_fill_test(self, x_data, y_data):
4239

4340
for i in range(nbins):
4441
for j in range(nbins):
45-
self.assertAlmostEqual(
46-
verbose_hist.GetBinContent(i, j),
47-
simple_hist.GetBinContent(i, j)
48-
)
42+
self.assertAlmostEqual(verbose_hist.GetBinContent(i, j), simple_hist.GetBinContent(i, j))
4943

5044
# Test mismatched weight size
5145
with self.assertRaises(ValueError):
@@ -56,10 +50,10 @@ def test_fill_arraylike(self):
5650
import numpy as np
5751

5852
inputs = [
59-
(np.array([1., 2, 3, 4, 5]), np.array([5., 4, 3, 2, 1])),
60-
([1., 2, 3, 4, 5], [5., 4, 3, 2, 1]),
53+
(np.array([1.0, 2, 3, 4, 5]), np.array([5.0, 4, 3, 2, 1])),
54+
([1.0, 2, 3, 4, 5], [5.0, 4, 3, 2, 1]),
6155
(range(1, 6), range(5, 0, -1)),
62-
([1., 2, 3, 4, 5], np.array([5., 4, 3, 2, 1])),
56+
([1.0, 2, 3, 4, 5], np.array([5.0, 4, 3, 2, 1])),
6357
]
6458

6559
for x_data, y_data in inputs:

0 commit comments

Comments
 (0)