Skip to content

Commit

Permalink
fix: support UnknownLength in ak.types.ArrayType (#2031)
Browse files Browse the repository at this point in the history
* fix: support UnknownLength in `ak.types.ArrayType`

* fix: loosen positive to >= 0

* fix: `ArrayBuilder` doesn't have a `length`
  • Loading branch information
agoose77 authored Dec 22, 2022
1 parent c15c99a commit c7a1b79
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/awkward/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def type(self):
wrapped by an #ak.types.ArrayType.
"""
return ak.types.ArrayType(
self._layout.form.type_from_behavior(self._behavior), len(self._layout)
self._layout.form.type_from_behavior(self._behavior), self._layout.length
)

@property
Expand All @@ -468,7 +468,7 @@ def __len__(self):
is `3`, not `5`.
"""
return len(self._layout)

This comment has been minimized.

Copy link
@agoose77

agoose77 Dec 29, 2022

Author Collaborator

N.B. this change doesn't make any functional difference — len(X) is required to return an integer.

return self._layout.length

def __iter__(self):
"""
Expand Down
8 changes: 5 additions & 3 deletions src/awkward/types/arraytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys

import awkward as ak
import awkward.types.type


class ArrayType:
Expand All @@ -16,10 +15,13 @@ def __init__(self, content, length):
)
)
)
if not ak._util.is_integer(length) or length < 0:
if not (
(ak._util.is_integer(length) and length >= 0)
or length is ak._typetracer.UnknownLength
):
raise ak._errors.wrap_error(
ValueError(
"{} 'length' must be of a positive integer, not {}".format(
"{} 'length' must be a non-negative integer or unknown length, not {}".format(
type(self).__name__, repr(length)
)
)
Expand Down

0 comments on commit c7a1b79

Please sign in to comment.