scikit-hep / awkward-0.x

Manipulate arrays of complex data structures as easily as Numpy.
BSD 3-Clause "New" or "Revised" License
215 stars 39 forks source link

JaggedArray.pad fails when content is empty #190

Closed benkrikler closed 5 years ago

benkrikler commented 5 years ago

Jagged array's pad method has troubles when the array contents is empty (even if starts or stops is not). This is the case with the latest release at least, so version 0.12.9

To recreate:

from awkward import JaggedArray
vals = [[], []]
a = JaggedArray.fromiter(vals)
print(a.pad(1, clip=True))

output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/.conda/envs/fast-carpenter/lib/python2.7/site-packages/awkward/array/jagged.py", line 1861, in pad
    content = self._content[index]
IndexError: index -1 is out of bounds for axis 0 with size 0

Same is true if clip=False or if vals=[[]]

jpivarski commented 5 years ago

Thanks for pointing this out!

Recently, the majority of bugs can be labeled, "Numpy corner cases," like this one. That's one of the main motivations for the C++ version: implementations of methods like pad will be more straightforward (internally as for loops) where this kind of gaffe would more likely be noticed.

jpivarski commented 5 years ago

This will be awkward 0.12.10.