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

Commit 18c94ec

Browse files
committed
Fix reading trees without index branch on Python 3
1 parent bf7ba3c commit 18c94ec

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

root_pandas/readwrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def read_root(paths, key=None, columns=None, ignore=None, chunksize=None, where=
125125
columns = [columns]
126126
# __index__* is always loaded if it exists
127127
# XXX Figure out what should happen with multi-dimensional indices
128-
index_branches = filter(lambda x: x.startswith('__index__'), branches)
128+
index_branches = list(filter(lambda x: x.startswith('__index__'), branches))
129129
if index_branches:
130130
columns = columns[:]
131131
columns.append(index_branches[0])

tests/test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ def test_read_write():
1212
df_ = read_root('tmp.root')
1313
os.remove('tmp.root')
1414

15+
df.to_root('tmp.root', key='mykey')
16+
df_ = read_root('tmp.root', key='mykey')
17+
assert_frame_equal(df, df_)
18+
os.remove('tmp.root')
19+
20+
tf = ROOT.TFile('tmp.root', 'recreate')
21+
tt = ROOT.TTree("a", "a")
22+
23+
x = np.array([1])
24+
x[0] = 42
25+
tt.Branch('x', x, 'x/D')
26+
27+
tt.Fill()
28+
x[0] = 1
29+
tt.Fill()
30+
tt.Write()
31+
tf.Close()
32+
33+
# Read when no index is present
34+
df = read_root('tmp.root', columns=['x'])
35+
os.remove('tmp.root')
36+
37+
1538
def test_persistent_index():
1639
df = pd.DataFrame({'index': [42, 0, 1], 'x': [1,2,3]})
1740
df = df.set_index('index')

0 commit comments

Comments
 (0)