Skip to content

Commit

Permalink
fix: make from_iter require iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Apr 4, 2023
1 parent 35c3ed9 commit 8c48428
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/awkward/operations/ak_from_iter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
__all__ = ("from_iter",)

from collections.abc import Iterable

from awkward_cpp.lib import _ext

import awkward as ak
Expand Down Expand Up @@ -72,6 +74,13 @@ def from_iter(


def _impl(iterable, highlevel, behavior, allow_record, initial, resize):
if not isinstance(iterable, Iterable):
raise ak._errors.wrap_error(
TypeError(
f"cannot produce an array from a non-iterable object ({type(iterable)!r})"
)
)

if isinstance(iterable, dict):
if allow_record:
return _impl(
Expand All @@ -89,6 +98,7 @@ def _impl(iterable, highlevel, behavior, allow_record, initial, resize):
)
)

# Ensure that tuples are treated as iterables, not records
if isinstance(iterable, tuple):
iterable = list(iterable)

Expand Down

0 comments on commit 8c48428

Please sign in to comment.