Skip to content

Commit

Permalink
fix: drop lengths recursively (#2775)
Browse files Browse the repository at this point in the history
* fix: drop lengths recursively

* test: ensure slicing from-typetracer works
  • Loading branch information
agoose77 authored Oct 27, 2023
1 parent a79b9ad commit 8f2285a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/awkward/contents/bitmaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
tt = TypeTracer.instance()
return BitMaskedArray(
self._mask.to_nplike(tt),
self._content._to_typetracer(False),
self._content._to_typetracer(forget_length),
self._valid_when,
unknown_length if forget_length else self.length,
self._lsb_order,
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/contents/bytemaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
mask = self._mask.to_nplike(tt)
return ByteMaskedArray(
mask.forget_length() if forget_length else mask,
self._content._to_typetracer(False),
self._content._to_typetracer(forget_length),
self._valid_when,
parameters=self._parameters,
)
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/contents/indexedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
index = self._index.to_nplike(TypeTracer.instance())
return IndexedArray(
index.forget_length() if forget_length else index,
self._content._to_typetracer(False),
self._content._to_typetracer(forget_length),
parameters=self._parameters,
)

Expand Down
2 changes: 1 addition & 1 deletion src/awkward/contents/indexedoptionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
index = self._index.to_nplike(TypeTracer.instance())
return IndexedOptionArray(
index.forget_length() if forget_length else index,
self._content._to_typetracer(False),
self._content._to_typetracer(forget_length),
parameters=self._parameters,
)

Expand Down
2 changes: 1 addition & 1 deletion src/awkward/contents/listarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
return ListArray(
starts.forget_length() if forget_length else starts,
self._stops.to_nplike(tt),
self._content._to_typetracer(False),
self._content._to_typetracer(forget_length),
parameters=self._parameters,
)

Expand Down
2 changes: 1 addition & 1 deletion src/awkward/contents/listoffsetarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
offsets = self._offsets.to_nplike(TypeTracer.instance())
return ListOffsetArray(
offsets.forget_length() if forget_length else offsets,
self._content._to_typetracer(False),
self._content._to_typetracer(forget_length),
parameters=self._parameters,
)

Expand Down
2 changes: 1 addition & 1 deletion src/awkward/contents/unionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def _to_typetracer(self, forget_length: bool) -> Self:
return UnionArray(
tags.forget_length() if forget_length else tags,
self._index.to_nplike(tt),
[x._to_typetracer(False) for x in self._contents],
[x._to_typetracer(forget_length) for x in self._contents],
parameters=self._parameters,
)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_2765_slice_from_typetracer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import awkward as ak


def test():
array = ak.typetracer.typetracer_from_form(
ak.forms.from_type(
ak.types.from_datashape("{x: var * {y:int64}}", highlevel=False)
)
)
sliced = array[0, "x", 0]
assert sliced.type.is_equal_to(
ak.types.ScalarType(
ak.types.RecordType([ak.types.NumpyType("int64")], ["y"]), None
)
)

0 comments on commit 8f2285a

Please sign in to comment.