From 8f2285a714e01da6885101977c4b6f1bba56a154 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 27 Oct 2023 10:31:37 +0100 Subject: [PATCH] fix: drop lengths recursively (#2775) * fix: drop lengths recursively * test: ensure slicing from-typetracer works --- src/awkward/contents/bitmaskedarray.py | 2 +- src/awkward/contents/bytemaskedarray.py | 2 +- src/awkward/contents/indexedarray.py | 2 +- src/awkward/contents/indexedoptionarray.py | 2 +- src/awkward/contents/listarray.py | 2 +- src/awkward/contents/listoffsetarray.py | 2 +- src/awkward/contents/unionarray.py | 2 +- tests/test_2765_slice_from_typetracer.py | 15 +++++++++++++++ 8 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 tests/test_2765_slice_from_typetracer.py diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index ae5e8e2fe5..b5c1370efd 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -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, diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index ab82e40764..1ba6f8966d 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -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, ) diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index d990dea323..eb5f595337 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -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, ) diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index f1d9568a55..cee5e77326 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -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, ) diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 98f153925b..26f872f421 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -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, ) diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index c6aa5f1d8f..d3efb08698 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -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, ) diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index 2d0647ce77..95ddfca6e4 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -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, ) diff --git a/tests/test_2765_slice_from_typetracer.py b/tests/test_2765_slice_from_typetracer.py new file mode 100644 index 0000000000..b144e7f9be --- /dev/null +++ b/tests/test_2765_slice_from_typetracer.py @@ -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 + ) + )