Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 4624b74

Browse files
committed
Make code conform to pep8 except line lengths
1 parent 2133031 commit 4624b74

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

root_pandas/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import re
1414
import ROOT
1515

16+
1617
__all__ = ['read_root']
1718

19+
1820
def expand_braces(orig):
1921
r = r'.*(\{.+?[^\\]\})'
2022
p = re.compile(r)
@@ -39,21 +41,22 @@ def expand_braces(orig):
3941

4042
return list(set(res))
4143

42-
def get_matching_variables(branches, patterns, fail=True):
4344

45+
def get_matching_variables(branches, patterns, fail=True):
4446
selected = []
4547

4648
for p in patterns:
4749
found = False
4850
for b in branches:
4951
if fnmatch(b, p):
5052
found = True
51-
if fnmatch(b, p) and not b in selected:
53+
if fnmatch(b, p) and b not in selected:
5254
selected.append(b)
5355
if not found and fail:
5456
raise ValueError("Pattern '{}' didn't match any branch".format(p))
5557
return selected
5658

59+
5760
def read_root(path, key=None, columns=None, ignore=None, chunksize=None, where=None, *args, **kwargs):
5861
"""
5962
Read a ROOT file into a pandas DataFrame.
@@ -124,6 +127,7 @@ def read_root(path, key=None, columns=None, ignore=None, chunksize=None, where=N
124127
f = ROOT.TFile(path)
125128
n_entries = f.Get(key).GetEntries()
126129
f.Close()
130+
127131
def genchunks():
128132
for chunk in range(int(ceil(float(n_entries) / chunksize))):
129133
arr = root2array(path, key, all_vars, start=chunk * chunksize, stop=(chunk+1) * chunksize, selection=where, *args, **kwargs)
@@ -133,6 +137,7 @@ def genchunks():
133137
arr = root2array(path, key, all_vars, selection=where, *args, **kwargs)
134138
return convert_to_dataframe(arr)
135139

140+
136141
def convert_to_dataframe(array):
137142
indices = list(filter(lambda x: x.startswith('__index__'), array.dtype.names))
138143
if len(indices) == 0:
@@ -150,6 +155,7 @@ def convert_to_dataframe(array):
150155
raise ValueError("More than one index found in file")
151156
return df
152157

158+
153159
def to_root(df, path, key='default', mode='w', *args, **kwargs):
154160
"""
155161
Write DataFrame to a ROOT file.
@@ -162,15 +168,15 @@ def to_root(df, path, key='default', mode='w', *args, **kwargs):
162168
Name of tree that the DataFrame will be saved as
163169
mode: string, {'w', 'a'}
164170
Mode that the file should be opened in (default: 'w')
165-
171+
166172
Notes
167173
-----
168174
169175
Further *args and *kwargs are passed to root_numpy's array2root.
170176
171177
>>> df = DataFrame({'x': [1,2,3], 'y': [4,5,6]})
172178
>>> df.to_root('test.root')
173-
179+
174180
The DataFrame index will be saved as a branch called '__index__*',
175181
where * is the name of the index in the original DataFrame
176182
"""
@@ -193,6 +199,6 @@ def to_root(df, path, key='default', mode='w', *args, **kwargs):
193199
arr = df_.to_records(index=False)
194200
array2root(arr, path, key, mode=mode, *args, **kwargs)
195201

202+
196203
# Patch pandas DataFrame to support to_root method
197204
DataFrame.to_root = to_root
198-

0 commit comments

Comments
 (0)