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

Commit aecdf63

Browse files
authored
Merge pull request #66 from chrisburr/fix-63
Fix #63
2 parents af9c422 + 389584b commit aecdf63

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

root_pandas/readwrite.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def expand_braces(orig):
8181

8282

8383
def get_nonscalar_columns(array):
84+
if len(array) == 0:
85+
return []
86+
8487
first_row = array[0]
8588
bad_cols = np.array([x.ndim != 0 for x in first_row])
8689
col_names = np.array(array.dtype.names)
@@ -246,6 +249,8 @@ def genchunks():
246249
current_index = 0
247250
for chunk in range(int(ceil(float(n_entries) / chunksize))):
248251
arr = root2array(paths, key, all_vars, start=chunk * chunksize, stop=(chunk+1) * chunksize, selection=where, *args, **kwargs)
252+
if len(arr) == 0:
253+
continue
249254
if flatten:
250255
arr = do_flatten(arr, flatten)
251256
yield convert_to_dataframe(arr, start_index=current_index)

tests/test_issues.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
import pandas as pd
4+
import root_pandas
5+
6+
7+
def test_issue_63():
8+
df = pd.DataFrame({'a': [], 'b': []})
9+
root_pandas.to_root(df, 'tmp_1.root', 'my_tree')
10+
df = pd.DataFrame({'a': list(range(10)), 'b': list(range(10))})
11+
root_pandas.to_root(df, 'tmp_2.root', 'my_tree')
12+
result = list(root_pandas.read_root(['tmp_1.root', 'tmp_2.root'], 'my_tree', where='a > 2', chunksize=1))
13+
assert len(result) == 7
14+
assert all(len(df) == 1 for df in result)
15+
os.remove('tmp_1.root')
16+
os.remove('tmp_2.root')

0 commit comments

Comments
 (0)