scikit-hep / uproot5

ROOT I/O in pure Python and NumPy.
https://uproot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
233 stars 73 forks source link

`uproot.lazy()` fails on TTrees with zero entries #450

Closed masonproffitt closed 2 years ago

masonproffitt commented 2 years ago

The title says it all, and it's clear where the problem is from the example below. I'm just not 100% sure if this should be handled in Uproot or in Awkward.

>>> import uproot
>>> uproot.__version__
'4.1.2'
>>> with uproot.recreate('test.root') as file_for_writing:
...     file_for_writing['tree'] = {'branch': []}
...
>>> uproot.open('test.root')['tree'].arrays()
<Array [] type='0 * {"branch": float64}'>
>>> uproot.lazy('test.root:tree')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mproffit/miniconda3/lib/python3.9/site-packages/uproot/behaviors/TBranch.py", line 683, in lazy
    out = awkward.partition.IrregularlyPartitionedArray(partitions, global_offsets[1:])
  File "/home/mproffit/miniconda3/lib/python3.9/site-packages/awkward/partition.py", line 685, in __init__
    self._ext = ak._ext.IrregularlyPartitionedArray(nextpartitions, nextstops)
ValueError: PartitionedArray must have at least one partition

(https://github.com/scikit-hep/awkward-1.0/blob/1.5.0/src/libawkward/partition/PartitionedArray.cpp#L19)

The expected behavior would of course be for uproot.lazy() to return an empty Array like arrays() does.

jpivarski commented 2 years ago

PR #451.

I intend to fix a lot of these issues this week, but I'm going backward, starting with the most recently posted.