Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions root_pandas/readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def expand_braces(orig):


def get_nonscalar_columns(array):
if len(array) == 0:
return []

first_row = array[0]
bad_cols = np.array([x.ndim != 0 for x in first_row])
col_names = np.array(array.dtype.names)
Expand Down Expand Up @@ -246,6 +249,8 @@ def genchunks():
current_index = 0
for chunk in range(int(ceil(float(n_entries) / chunksize))):
arr = root2array(paths, key, all_vars, start=chunk * chunksize, stop=(chunk+1) * chunksize, selection=where, *args, **kwargs)
if len(arr) == 0:
continue
if flatten:
arr = do_flatten(arr, flatten)
yield convert_to_dataframe(arr, start_index=current_index)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

import pandas as pd
import root_pandas


def test_issue_63():
df = pd.DataFrame({'a': [], 'b': []})
root_pandas.to_root(df, 'tmp_1.root', 'my_tree')
df = pd.DataFrame({'a': list(range(10)), 'b': list(range(10))})
root_pandas.to_root(df, 'tmp_2.root', 'my_tree')
result = list(root_pandas.read_root(['tmp_1.root', 'tmp_2.root'], 'my_tree', where='a > 2', chunksize=1))
assert len(result) == 7
assert all(len(df) == 1 for df in result)
os.remove('tmp_1.root')
os.remove('tmp_2.root')