Skip to content

Commit

Permalink
fix: improve ak.from_iter performance for long (axis=0) arrays (#1614)
Browse files Browse the repository at this point in the history
Fixes #1588
  • Loading branch information
agoose77 authored Aug 22, 2022
1 parent b1f7792 commit c045715
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/awkward/_v2/operations/ak_from_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ def _impl(iterable, highlevel, behavior, allow_record, initial, resize):
)

builder = ak.layout.ArrayBuilder(initial=initial, resize=resize)
for x in iterable:
builder.fromiter(x)
builder.fromiter(iterable)

formstr, length, buffers = builder.to_buffers()
form = ak._v2.forms.from_json(formstr)

return ak._v2.operations.from_buffers(
form, length, buffers, highlevel=highlevel, behavior=behavior
)
)[0]
6 changes: 2 additions & 4 deletions src/awkward/operations/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,8 @@ def from_iter(
)

out = ak.layout.ArrayBuilder(initial=initial, resize=resize)
for x in iterable:
out.fromiter(x)
layout = out.snapshot()
return ak._util.maybe_wrap(layout, behavior, highlevel)
out.fromiter(iterable)
return ak._util.maybe_wrap(out[0], behavior, highlevel)


def to_list(array):
Expand Down

0 comments on commit c045715

Please sign in to comment.