Skip to content

Commit

Permalink
Fix error when using from_awkward on an empty array (#330)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Doug Davis <[email protected]>
  • Loading branch information
jrueb and douglasdavis authored Jul 25, 2023
1 parent 4886779 commit 75fee25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dask_awkward/lib/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ def from_awkward(
"""
nrows = len(source)
chunksize = int(math.ceil(nrows / npartitions))
locs = list(range(0, nrows, chunksize)) + [nrows]
if nrows == 0:
locs = [None, None]
else:
chunksize = int(math.ceil(nrows / npartitions))
locs = list(range(0, nrows, chunksize)) + [nrows]
starts = locs[:-1]
stops = locs[1:]
meta = typetracer_array(source)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,19 @@ def test_to_dataframe_str(
df = ak.to_dataframe(caa)

assert_eq(dd, df, check_index=False)


def test_from_awkward_empty_array(daa) -> None:
# no form
c1 = ak.Array([])
assert len(c1) == 0
a1 = dak.from_awkward(c1, npartitions=1)
assert_eq(a1, c1)
assert len(a1) == 0

# with a form
c2 = ak.Array(daa.layout.form.length_zero_array(highlevel=False))
assert len(c2) == 0
a2 = dak.from_awkward(c2, npartitions=1)
assert len(a2) == 0
daa.layout.form == a2.layout.form

0 comments on commit 75fee25

Please sign in to comment.