Skip to content

Commit cd51ace

Browse files
committed
ruff lint and format
1 parent e9ce69e commit cd51ace

File tree

1 file changed

+23
-6
lines changed
  • bindings/pyroot/pythonizations/python/ROOT/_pythonization

1 file changed

+23
-6
lines changed

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

+23-6
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@
5656
\endpythondoc
5757
"""
5858

59-
from . import pythonization
60-
import cppyy
6159
import sys
6260

61+
import cppyy
62+
63+
from . import pythonization
6364

6465
_array_interface_dtype_map = {
6566
"Long64_t": "i",
@@ -75,7 +76,17 @@
7576

7677

7778
def _get_cpp_type_from_numpy_type(dtype):
78-
cpptypes = {"i2": "Short_t", "u2": "UShort_t", "i4": "int", "u4": "unsigned int", "i8": "Long64_t", "u8": "ULong64_t", "f4": "float", "f8": "double", "b1": "bool"}
79+
cpptypes = {
80+
"i2": "Short_t",
81+
"u2": "UShort_t",
82+
"i4": "int",
83+
"u4": "unsigned int",
84+
"i8": "Long64_t",
85+
"u8": "ULong64_t",
86+
"f4": "float",
87+
"f8": "double",
88+
"b1": "bool",
89+
}
7990

8091
if dtype not in cpptypes:
8192
raise RuntimeError("Object not convertible: Python object has unknown data-type '" + dtype + "'.")
@@ -95,10 +106,12 @@ def _AsRVec(arr):
95106
interface dictionary.
96107
Note that for arrays of strings, the input strings are copied into the RVec.
97108
"""
98-
import ROOT
99109
import math
110+
100111
import numpy as np
101112

113+
import ROOT
114+
102115
# Get array interface of object
103116
interface = arr.__array_interface__
104117

@@ -117,7 +130,11 @@ def _AsRVec(arr):
117130
if dtype == "O" or dtype.startswith("U"):
118131
underlying_object_types = {type(elem) for elem in arr}
119132
if len(underlying_object_types) > 1:
120-
raise TypeError("All elements in the numpy array must be of the same type. Found types: {}".format(underlying_object_types))
133+
raise TypeError(
134+
"All elements in the numpy array must be of the same type. Found types: {}".format(
135+
underlying_object_types
136+
)
137+
)
121138

122139
if underlying_object_types and underlying_object_types.pop() in [str, np.str_]:
123140
return ROOT.VecOps.RVec["std::string"](arr)
@@ -130,7 +147,7 @@ def _AsRVec(arr):
130147
+ typestr
131148
+ "' with invalid length unequal 3."
132149
)
133-
150+
134151
# Construct an RVec of the correct data-type
135152
cppdtype = _get_cpp_type_from_numpy_type(dtype)
136153
out = ROOT.VecOps.RVec[cppdtype](ROOT.module.cppyy.ll.reinterpret_cast[f"{cppdtype} *"](data), size)

0 commit comments

Comments
 (0)