From bc033a4678d1cd6d8f80ff1e69bca582e05588e1 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 21 Nov 2023 11:10:08 +0000 Subject: [PATCH 01/12] refactor: move mergeable to `_do` --- src/awkward/__init__.py | 3 +- src/awkward/_do/__init__.py | 0 src/awkward/_meta/bitmaskedmeta.py | 13 +++++ src/awkward/_meta/bytemaskedmeta.py | 13 +++++ src/awkward/_meta/emptymeta.py | 3 + src/awkward/_meta/indexedmeta.py | 13 +++++ src/awkward/_meta/indexedoptionmeta.py | 13 +++++ src/awkward/_meta/listmeta.py | 20 +++++++ src/awkward/_meta/listoffsetmeta.py | 20 +++++++ src/awkward/_meta/meta.py | 3 + src/awkward/_meta/numpymeta.py | 64 +++++++++++++++++++++- src/awkward/_meta/recordmeta.py | 37 +++++++++++++ src/awkward/_meta/regularmeta.py | 18 ++++++ src/awkward/_meta/unionmeta.py | 3 + src/awkward/_meta/unmaskedmeta.py | 13 +++++ src/awkward/contents/bitmaskedarray.py | 15 ----- src/awkward/contents/bytemaskedarray.py | 13 ----- src/awkward/contents/emptyarray.py | 3 - src/awkward/contents/indexedarray.py | 13 ----- src/awkward/contents/indexedoptionarray.py | 13 ----- src/awkward/contents/listarray.py | 25 --------- src/awkward/contents/listoffsetarray.py | 27 --------- src/awkward/contents/numpyarray.py | 52 +----------------- src/awkward/contents/recordarray.py | 37 ------------- src/awkward/contents/regulararray.py | 25 --------- src/awkward/contents/unionarray.py | 3 - src/awkward/contents/unmaskedarray.py | 13 ----- src/awkward/forms/numpyform.py | 5 +- 28 files changed, 238 insertions(+), 242 deletions(-) create mode 100644 src/awkward/_do/__init__.py diff --git a/src/awkward/__init__.py b/src/awkward/__init__.py index c82e83777f..02ca695c0b 100644 --- a/src/awkward/__init__.py +++ b/src/awkward/__init__.py @@ -16,7 +16,8 @@ import awkward.forms # internal -import awkward._do +import awkward._do.content +import awkward._do.meta import awkward._slicing import awkward._broadcasting import awkward._reducers diff --git a/src/awkward/_do/__init__.py b/src/awkward/_do/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/awkward/_meta/bitmaskedmeta.py b/src/awkward/_meta/bitmaskedmeta.py index d0e5ff188c..de672e4aac 100644 --- a/src/awkward/_meta/bitmaskedmeta.py +++ b/src/awkward/_meta/bitmaskedmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -55,3 +56,15 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # We can only combine option types whose array-record parameters agree + elif other.is_option or other.is_indexed: + return self._content._mergeable_next( + other.content, mergebool + ) and type_parameters_equal(self._parameters, other._parameters) + else: + return self._content._mergeable_next(other, mergebool) diff --git a/src/awkward/_meta/bytemaskedmeta.py b/src/awkward/_meta/bytemaskedmeta.py index 94e4cb2276..7bf2a77f3d 100644 --- a/src/awkward/_meta/bytemaskedmeta.py +++ b/src/awkward/_meta/bytemaskedmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -55,3 +56,15 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # We can only combine option types whose array-record parameters agree + elif other.is_option or other.is_indexed: + return self._content._mergeable_next( + other.content, mergebool + ) and type_parameters_equal(self._parameters, other._parameters) + else: + return self._content._mergeable_next(other, mergebool) diff --git a/src/awkward/_meta/emptymeta.py b/src/awkward/_meta/emptymeta.py index a84d7d0a41..8707913188 100644 --- a/src/awkward/_meta/emptymeta.py +++ b/src/awkward/_meta/emptymeta.py @@ -44,3 +44,6 @@ def is_tuple(self) -> bool: @property def dimension_optiontype(self) -> bool: return False + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + return True diff --git a/src/awkward/_meta/indexedmeta.py b/src/awkward/_meta/indexedmeta.py index bcb3c2dfb5..8c2b7bbdab 100644 --- a/src/awkward/_meta/indexedmeta.py +++ b/src/awkward/_meta/indexedmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -56,3 +57,15 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # We can only combine option/indexed types whose array-record parameters agree + elif other.is_option or other.is_indexed: + return self._content._mergeable_next( + other.content, mergebool + ) and type_parameters_equal(self._parameters, other._parameters) + else: + return self._content._mergeable_next(other, mergebool) diff --git a/src/awkward/_meta/indexedoptionmeta.py b/src/awkward/_meta/indexedoptionmeta.py index c1baf022b3..cf28cd854b 100644 --- a/src/awkward/_meta/indexedoptionmeta.py +++ b/src/awkward/_meta/indexedoptionmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -57,3 +58,15 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # We can only combine option/indexed types whose array-record parameters agree + elif other.is_option or other.is_indexed: + return self._content._mergeable_next( + other.content, mergebool + ) and type_parameters_equal(self._parameters, other._parameters) + else: + return self._content._mergeable_next(other, mergebool) diff --git a/src/awkward/_meta/listmeta.py b/src/awkward/_meta/listmeta.py index ceba1ffad6..4be469072e 100644 --- a/src/awkward/_meta/listmeta.py +++ b/src/awkward/_meta/listmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -67,3 +68,22 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # Check against option contents + elif other.is_option or other.is_indexed: + return self._mergeable_next(other.content, mergebool) + # Otherwise, do the parameters match? If not, we can't merge. + elif not type_parameters_equal(self._parameters, other._parameters): + return False + elif other.is_list: + return self._content._mergeable_next(other.content, mergebool) + elif other.is_numpy and len(other.inner_shape) > 0: + return self._mergeable_next( + other._to_regular_primitive(), mergebool + ) # TODO + else: + return False diff --git a/src/awkward/_meta/listoffsetmeta.py b/src/awkward/_meta/listoffsetmeta.py index 4411339f4f..862c029fe0 100644 --- a/src/awkward/_meta/listoffsetmeta.py +++ b/src/awkward/_meta/listoffsetmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -67,3 +68,22 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # Check against option contents + elif other.is_option or other.is_indexed: + return self._mergeable_next(other.content, mergebool) + # Otherwise, do the parameters match? If not, we can't merge. + elif not type_parameters_equal(self._parameters, other._parameters): + return False + elif other.is_list: + return self._content._mergeable_next(other.content, mergebool) + elif other.is_numpy and len(other.inner_shape) > 0: + return self._mergeable_next( + other._to_regular_primitive(), mergebool + ) # TODO + else: + return False diff --git a/src/awkward/_meta/meta.py b/src/awkward/_meta/meta.py index 65233f9821..ab8fea9090 100644 --- a/src/awkward/_meta/meta.py +++ b/src/awkward/_meta/meta.py @@ -118,3 +118,6 @@ def dimension_optiontype(self) -> bool: def copy(self, *, parameters: JSONMapping | None | Sentinel = UNSET) -> Self: raise NotImplementedError + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + raise NotImplementedError diff --git a/src/awkward/_meta/numpymeta.py b/src/awkward/_meta/numpymeta.py index 8ffa1597e5..5b377ae3e9 100644 --- a/src/awkward/_meta/numpymeta.py +++ b/src/awkward/_meta/numpymeta.py @@ -4,10 +4,16 @@ from awkward._meta.meta import Meta from awkward._nplikes.shape import ShapeItem -from awkward._typing import JSONSerializable +from awkward._parameters import type_parameters_equal +from awkward._typing import TYPE_CHECKING, Generic, JSONSerializable, TypeVar +if TYPE_CHECKING: + from awkward._meta.regularmeta import RegularMeta -class NumpyMeta(Meta): +T = TypeVar("T", bound=Meta) + + +class NumpyMeta(Meta, Generic[T]): is_numpy = True is_leaf = True inner_shape: tuple[ShapeItem, ...] @@ -51,3 +57,57 @@ def is_tuple(self) -> bool: @property def dimension_optiontype(self) -> bool: return False + + def _to_regular_primitive(self) -> RegularMeta[T]: + raise NotImplementedError + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # Check against option contents + elif other.is_option or other.is_indexed: + return self._mergeable_next(other.content, mergebool) + # Otherwise, do the parameters match? If not, we can't merge. + elif not type_parameters_equal(self._parameters, other._parameters): + return False + # Simplify *this* branch to be 1D self + elif len(self.inner_shape) > 0: + return self._to_regular_primitive()._mergeable_next( + other, mergebool + ) # TODO + + elif other.is_numpy: + if len(self.inner_shape) != len(other.inner_shape): + return False + + # Obvious fast-path + if self.dtype == other.dtype: # TODO + return True + + # Special-case booleans i.e. {bool, number} + elif ( + np.issubdtype(self.dtype, np.bool_) + and np.issubdtype(other.dtype, np.number) + or np.issubdtype(self.dtype, np.number) + and np.issubdtype(other.dtype, np.bool_) + ): + return mergebool + + # Currently we're less permissive than NumPy on merging datetimes / timedeltas + elif ( + np.issubdtype(self.dtype, np.datetime64) + or np.issubdtype(self.dtype, np.timedelta64) + or np.issubdtype(other.dtype, np.datetime64) + or np.issubdtype(other.dtype, np.timedelta64) + ): + return False + + # Default merging (can we cast one to the other) + else: + return self.backend.nplike.can_cast( + self.dtype, other.dtype + ) or self.backend.nplike.can_cast(other.dtype, self.dtype) + + else: + return False diff --git a/src/awkward/_meta/recordmeta.py b/src/awkward/_meta/recordmeta.py index 4a7cb0d535..d51f0f788c 100644 --- a/src/awkward/_meta/recordmeta.py +++ b/src/awkward/_meta/recordmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._regularize import is_integer from awkward._typing import Generic, JSONSerializable, TypeVar from awkward.errors import FieldNotFoundError @@ -141,3 +142,39 @@ def content(self, index_or_field: int | str) -> T: ) ) return self._contents[index] # type: ignore[index] + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # Check against option contents + elif other.is_option or other.is_indexed: + return self._mergeable_next(other.content, mergebool) + # Otherwise, do the parameters match? If not, we can't merge. + elif not type_parameters_equal(self._parameters, other._parameters): + return False + elif other.is_record: + if self.is_tuple and other.is_tuple: + if len(self.contents) == len(other.contents): + for self_cont, other_cont in zip(self.contents, other.contents): + if not self_cont._mergeable_next(other_cont, mergebool): + return False + + return True + + elif not self.is_tuple and not other.is_tuple: + if set(self._fields) != set(other._fields): + return False + + for i, field in enumerate(self._fields): + x = self._contents[i] + y = other.contents[other.field_to_index(field)] + if not x._mergeable_next(y, mergebool): + return False + return True + + else: + return False + + else: + return False diff --git a/src/awkward/_meta/regularmeta.py b/src/awkward/_meta/regularmeta.py index ef43c6f5f9..09ef21c10c 100644 --- a/src/awkward/_meta/regularmeta.py +++ b/src/awkward/_meta/regularmeta.py @@ -4,6 +4,7 @@ from awkward._meta.meta import Meta from awkward._nplikes.shape import ShapeItem +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -70,3 +71,20 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # Check against option contents + elif other.is_option or other.is_indexed: + return self._mergeable_next(other.content, mergebool) + # Otherwise, do the parameters match? If not, we can't merge. + elif not type_parameters_equal(self._parameters, other._parameters): + return False + elif other.is_list: + return self._content._mergeable_next(other.content, mergebool) + elif other.is_numpy and len(other.inner_shape) > 0: + return self._mergeable_next(other._to_regular_primitive(), mergebool) + else: + return False diff --git a/src/awkward/_meta/unionmeta.py b/src/awkward/_meta/unionmeta.py index eefce689b2..08e3b25a5f 100644 --- a/src/awkward/_meta/unionmeta.py +++ b/src/awkward/_meta/unionmeta.py @@ -105,3 +105,6 @@ def content(self, index: int) -> T: @property def contents(self) -> list[T]: return self._contents + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + return True diff --git a/src/awkward/_meta/unmaskedmeta.py b/src/awkward/_meta/unmaskedmeta.py index 49dcffba25..da03764b10 100644 --- a/src/awkward/_meta/unmaskedmeta.py +++ b/src/awkward/_meta/unmaskedmeta.py @@ -3,6 +3,7 @@ from __future__ import annotations from awkward._meta.meta import Meta +from awkward._parameters import type_parameters_equal from awkward._typing import Generic, JSONSerializable, TypeVar T = TypeVar("T", bound=Meta) @@ -55,3 +56,15 @@ def dimension_optiontype(self) -> bool: @property def content(self) -> T: return self._content + + def _mergeable_next(self, other: T, mergebool: bool) -> bool: + # Is the other content is an identity, or a union? + if other.is_identity_like or other.is_union: + return True + # We can only combine option types whose array-record parameters agree + elif other.is_option or other.is_indexed: + return self._mergeable_next( + other.content, mergebool + ) and type_parameters_equal(self._parameters, other._parameters) + else: + return self._content._mergeable_next(other, mergebool) diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index 6790ac7bc0..4fe3b6a25d 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -15,9 +15,6 @@ from awkward._nplikes.numpy_like import IndexType, NumpyMetadata from awkward._nplikes.shape import ShapeItem, unknown_length from awkward._nplikes.typetracer import MaybeNone, TypeTracer -from awkward._parameters import ( - type_parameters_equal, -) from awkward._regularize import is_integer, is_integer_like from awkward._slicing import NO_HEAD from awkward._typing import ( @@ -573,18 +570,6 @@ def project(self, mask=None): def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]: return self.to_ByteMaskedArray._offsets_and_flattened(axis, depth) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # We can only combine option types whose array-record parameters agree - elif other.is_option or other.is_indexed: - return self._content._mergeable_next( - other.content, mergebool - ) and type_parameters_equal(self._parameters, other._parameters) - else: - return self._content._mergeable_next(other, mergebool) - def _reverse_merge(self, other): return self.to_IndexedOptionArray64()._reverse_merge(other) diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index 5738ae3803..aa57c60f18 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -18,7 +18,6 @@ from awkward._nplikes.typetracer import MaybeNone, TypeTracer from awkward._parameters import ( parameters_intersect, - type_parameters_equal, ) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD @@ -717,18 +716,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] ) return (outoffsets, flattened) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # We can only combine option types whose array-record parameters agree - elif other.is_option or other.is_indexed: - return self._content._mergeable_next( - other.content, mergebool - ) and type_parameters_equal(self._parameters, other._parameters) - else: - return self._content._mergeable_next(other, mergebool) - def _reverse_merge(self, other): return self.to_IndexedOptionArray64()._reverse_merge(other) diff --git a/src/awkward/contents/emptyarray.py b/src/awkward/contents/emptyarray.py index 831d8c3810..0cc55c80ba 100644 --- a/src/awkward/contents/emptyarray.py +++ b/src/awkward/contents/emptyarray.py @@ -269,9 +269,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] EmptyArray(backend=self._backend), ) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - return True - def _mergemany(self, others: Sequence[Content]) -> Content: if len(others) == 0: return self diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index ee5cb28c10..51f761b10d 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -17,7 +17,6 @@ from awkward._parameters import ( parameters_intersect, parameters_union, - type_parameters_equal, ) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD @@ -496,18 +495,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] else: return self.project()._offsets_and_flattened(axis, depth) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # We can only combine option/indexed types whose array-record parameters agree - elif other.is_option or other.is_indexed: - return self._content._mergeable_next( - other.content, mergebool - ) and type_parameters_equal(self._parameters, other._parameters) - else: - return self._content._mergeable_next(other, mergebool) - def _merging_strategy(self, others): if len(others) == 0: raise ValueError( diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index 396aece3a1..2a426c3a69 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -17,7 +17,6 @@ from awkward._parameters import ( parameters_intersect, parameters_union, - type_parameters_equal, ) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD @@ -629,18 +628,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] ) return (outoffsets, flattened) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # We can only combine option/indexed types whose array-record parameters agree - elif other.is_option or other.is_indexed: - return self._content._mergeable_next( - other.content, mergebool - ) and type_parameters_equal(self._parameters, other._parameters) - else: - return self._content._mergeable_next(other, mergebool) - def _merging_strategy(self, others): if len(others) == 0: raise ValueError( diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index d4751cef9d..161c50e2d9 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -15,7 +15,6 @@ from awkward._nplikes.typetracer import TypeTracer from awkward._parameters import ( parameters_intersect, - type_parameters_equal, ) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD @@ -1072,30 +1071,6 @@ def _getitem_next( def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]: return self.to_ListOffsetArray64(True)._offsets_and_flattened(axis, depth) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # Check against option contents - elif other.is_option or other.is_indexed: - return self._mergeable_next(other.content, mergebool) - # Otherwise, do the parameters match? If not, we can't merge. - elif not type_parameters_equal(self._parameters, other._parameters): - return False - elif isinstance( - other, - ( - ak.contents.RegularArray, - ak.contents.ListArray, - ak.contents.ListOffsetArray, - ), - ): - return self._content._mergeable_next(other.content, mergebool) - elif isinstance(other, ak.contents.NumpyArray) and len(other.shape) > 1: - return self._mergeable_next(other._to_regular_primitive(), mergebool) - else: - return False - def _mergemany(self, others: Sequence[Content]) -> Content: if len(others) == 0: return self diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 1b54e108a9..4d34724e48 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -14,9 +14,6 @@ from awkward._nplikes.numpy_like import IndexType, NumpyMetadata from awkward._nplikes.shape import ShapeItem, unknown_length from awkward._nplikes.typetracer import TypeTracer, is_unknown_scalar -from awkward._parameters import ( - type_parameters_equal, -) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD from awkward._typing import ( @@ -781,30 +778,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] ListOffsetArray(tooffsets, flattened, parameters=self._parameters), ) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # Check against option contents - elif other.is_option or other.is_indexed: - return self._mergeable_next(other.content, mergebool) - # Otherwise, do the parameters match? If not, we can't merge. - elif not type_parameters_equal(self._parameters, other._parameters): - return False - elif isinstance( - other, - ( - ak.contents.RegularArray, - ak.contents.ListArray, - ak.contents.ListOffsetArray, - ), - ): - return self._content._mergeable_next(other.content, mergebool) - elif isinstance(other, ak.contents.NumpyArray) and len(other.shape) > 1: - return self._mergeable_next(other._to_regular_primitive(), mergebool) - else: - return False - def _mergemany(self, others: Sequence[Content]) -> Content: if len(others) == 0: return self diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index 5bf111d2db..a0a4d1698f 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -22,7 +22,6 @@ from awkward._nplikes.typetracer import TypeTracerArray from awkward._parameters import ( parameters_intersect, - type_parameters_equal, ) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD @@ -57,7 +56,7 @@ @final -class NumpyArray(NumpyMeta, Content): +class NumpyArray(NumpyMeta[Content], Content): """ A NumpyArray describes 1-dimensional or rectilinear data using a NumPy `np.ndarray`, a CuPy `cp.ndarray`, etc., depending on the backend. @@ -447,55 +446,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] else: raise AxisError(f"axis={axis} exceeds the depth of this array ({depth})") - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # Check against option contents - elif other.is_option or other.is_indexed: - return self._mergeable_next(other.content, mergebool) - # Otherwise, do the parameters match? If not, we can't merge. - elif not type_parameters_equal(self._parameters, other._parameters): - return False - # Simplify *this* branch to be 1D self - elif len(self.shape) > 1: - return self._to_regular_primitive()._mergeable_next(other, mergebool) - - elif isinstance(other, ak.contents.NumpyArray): - if self._data.ndim != other._data.ndim: - return False - - # Obvious fast-path - if self.dtype == other.dtype: - return True - - # Special-case booleans i.e. {bool, number} - elif ( - np.issubdtype(self.dtype, np.bool_) - and np.issubdtype(other.dtype, np.number) - or np.issubdtype(self.dtype, np.number) - and np.issubdtype(other.dtype, np.bool_) - ): - return mergebool - - # Currently we're less permissive than NumPy on merging datetimes / timedeltas - elif ( - np.issubdtype(self.dtype, np.datetime64) - or np.issubdtype(self.dtype, np.timedelta64) - or np.issubdtype(other.dtype, np.datetime64) - or np.issubdtype(other.dtype, np.timedelta64) - ): - return False - - # Default merging (can we cast one to the other) - else: - return self.backend.nplike.can_cast( - self.dtype, other.dtype - ) or self.backend.nplike.can_cast(other.dtype, self.dtype) - - else: - return False - def _mergemany(self, others: Sequence[Content]) -> Content: if len(others) == 0: return self diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 30697f6f8f..92d07c13a8 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -19,7 +19,6 @@ from awkward._nplikes.shape import ShapeItem, unknown_length from awkward._parameters import ( parameters_intersect, - type_parameters_equal, ) from awkward._slicing import NO_HEAD from awkward._typing import ( @@ -646,42 +645,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] ), ) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # Check against option contents - elif other.is_option or other.is_indexed: - return self._mergeable_next(other.content, mergebool) - # Otherwise, do the parameters match? If not, we can't merge. - elif not type_parameters_equal(self._parameters, other._parameters): - return False - elif isinstance(other, RecordArray): - if self.is_tuple and other.is_tuple: - if len(self._contents) == len(other._contents): - for self_cont, other_cont in zip(self._contents, other._contents): - if not self_cont._mergeable_next(other_cont, mergebool): - return False - - return True - - elif not self.is_tuple and not other.is_tuple: - if set(self._fields) != set(other._fields): - return False - - for i, field in enumerate(self._fields): - x = self._contents[i] - y = other._contents[other.field_to_index(field)] - if not x._mergeable_next(y, mergebool): - return False - return True - - else: - return False - - else: - return False - def _mergemany(self, others: Sequence[Content]) -> Content: if len(others) == 0: return self diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index eed2ae428e..d3a828388f 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -16,7 +16,6 @@ from awkward._parameters import ( parameters_intersect, parameters_union, - type_parameters_equal, ) from awkward._regularize import is_integer, is_integer_like from awkward._slicing import NO_HEAD @@ -726,30 +725,6 @@ def _getitem_next( def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]: return self.to_ListOffsetArray64(True)._offsets_and_flattened(axis, depth) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # Check against option contents - elif other.is_option or other.is_indexed: - return self._mergeable_next(other.content, mergebool) - # Otherwise, do the parameters match? If not, we can't merge. - elif not type_parameters_equal(self._parameters, other._parameters): - return False - elif isinstance( - other, - ( - ak.contents.RegularArray, - ak.contents.ListArray, - ak.contents.ListOffsetArray, - ), - ): - return self._content._mergeable_next(other.content, mergebool) - elif isinstance(other, ak.contents.NumpyArray) and len(other.shape) > 1: - return self._mergeable_next(other._to_regular_primitive(), mergebool) - else: - return False - def _mergemany(self, others: Sequence[Content]) -> Content: if len(others) == 0: return self diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index aa81b495da..f9b1b5a43e 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -985,9 +985,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] ), ) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - return True - def _merging_strategy(self, others): if len(others) == 0: raise ValueError( diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index 2f560827ad..1d694c3b8a 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -18,7 +18,6 @@ from awkward._parameters import ( parameters_intersect, parameters_union, - type_parameters_equal, ) from awkward._regularize import is_integer_like from awkward._slicing import NO_HEAD @@ -336,18 +335,6 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content] else: return (offsets, flattened) - def _mergeable_next(self, other: Content, mergebool: bool) -> bool: - # Is the other content is an identity, or a union? - if other.is_identity_like or other.is_union: - return True - # We can only combine option types whose array-record parameters agree - elif other.is_option or other.is_indexed: - return self._mergeable_next( - other.content, mergebool - ) and type_parameters_equal(self._parameters, other._parameters) - else: - return self._content._mergeable_next(other, mergebool) - def _reverse_merge(self, other): return self.to_IndexedOptionArray64()._reverse_merge(other) diff --git a/src/awkward/forms/numpyform.py b/src/awkward/forms/numpyform.py index 3af48d5e19..f40308d9ed 100644 --- a/src/awkward/forms/numpyform.py +++ b/src/awkward/forms/numpyform.py @@ -64,7 +64,7 @@ def from_dtype( @final -class NumpyForm(NumpyMeta, Form): +class NumpyForm(NumpyMeta[Form], Form): def __init__( self, primitive, @@ -259,6 +259,9 @@ def _expected_from_buffers( yield (getkey(self, "data"), primitive_to_dtype(self.primitive)) + def _to_regular_primitive(self) -> RegularForm: + return self.to_RegularForm() + def _is_equal_to(self, other: Any, all_parameters: bool, form_key: bool) -> bool: return self._is_equal_to_generic(other, all_parameters, form_key) and ( self._primitive == other._primitive From 985d3c84a8027e7361b71d4d3590e781edb0b0cf Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 21 Nov 2023 11:10:54 +0000 Subject: [PATCH 02/12] refactor: split `_do` --- src/awkward/{_do.py => _do/content.py} | 4 ---- src/awkward/_do/meta.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) rename src/awkward/{_do.py => _do/content.py} (99%) create mode 100644 src/awkward/_do/meta.py diff --git a/src/awkward/_do.py b/src/awkward/_do/content.py similarity index 99% rename from src/awkward/_do.py rename to src/awkward/_do/content.py index f7925c2b6b..271a175e56 100644 --- a/src/awkward/_do.py +++ b/src/awkward/_do/content.py @@ -246,10 +246,6 @@ def num(layout, axis): return layout._num(axis, 0) -def mergeable(one: Content, two: Content, mergebool: bool = True) -> bool: - return one._mergeable_next(two, mergebool=mergebool) - - def mergemany(contents: list[Content]) -> Content: assert len(contents) != 0 return contents[0]._mergemany(contents[1:]) diff --git a/src/awkward/_do/meta.py b/src/awkward/_do/meta.py new file mode 100644 index 0000000000..8053eb47b9 --- /dev/null +++ b/src/awkward/_do/meta.py @@ -0,0 +1,12 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE + +from __future__ import annotations + +from awkward._nplikes.numpy_like import NumpyMetadata +from awkward.contents.content import Content + +np = NumpyMetadata.instance() + + +def mergeable(one: Content, two: Content, mergebool: bool = True) -> bool: + return one._mergeable_next(two, mergebool=mergebool) From 6759fc42f3d09589d7d2c376068e5ee03f057eec Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 21 Nov 2023 11:12:37 +0000 Subject: [PATCH 03/12] handle split --- src/awkward/_connect/numpy.py | 7 +++---- src/awkward/operations/ak_all.py | 3 ++- src/awkward/operations/ak_any.py | 3 ++- src/awkward/operations/ak_argmax.py | 3 ++- src/awkward/operations/ak_argmin.py | 3 ++- src/awkward/operations/ak_count.py | 3 ++- src/awkward/operations/ak_count_nonzero.py | 3 ++- src/awkward/operations/ak_max.py | 3 ++- src/awkward/operations/ak_min.py | 3 ++- src/awkward/operations/ak_prod.py | 3 ++- src/awkward/operations/ak_sum.py | 3 ++- 11 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/awkward/_connect/numpy.py b/src/awkward/_connect/numpy.py index 4529677dfb..7702047d24 100644 --- a/src/awkward/_connect/numpy.py +++ b/src/awkward/_connect/numpy.py @@ -21,6 +21,7 @@ find_ufunc_generic, ) from awkward._categorical import as_hashable +from awkward._do.content import reduce as do_reduce from awkward._layout import wrap_layout from awkward._nplikes import to_nplike from awkward._parameters import parameters_intersect @@ -316,11 +317,9 @@ def _array_ufunc_string_likes( nplike = left.backend.nplike # first condition: string lengths must be the same - left_counts_layout = ak._do.reduce(left, ak._reducers.Count(), axis=-1, mask=False) + left_counts_layout = do_reduce(left, ak._reducers.Count(), axis=-1, mask=False) assert left_counts_layout.is_numpy - right_counts_layout = ak._do.reduce( - right, ak._reducers.Count(), axis=-1, mask=False - ) + right_counts_layout = do_reduce(right, ak._reducers.Count(), axis=-1, mask=False) assert right_counts_layout.is_numpy counts1 = nplike.asarray(left_counts_layout.data) diff --git a/src/awkward/operations/ak_all.py b/src/awkward/operations/ak_all.py index 859bfd98cb..acd0ac485f 100644 --- a/src/awkward/operations/ak_all.py +++ b/src/awkward/operations/ak_all.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -72,7 +73,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.All() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_any.py b/src/awkward/operations/ak_any.py index 79c9cc6b83..d7d83a5e8b 100644 --- a/src/awkward/operations/ak_any.py +++ b/src/awkward/operations/ak_any.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -72,7 +73,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.Any() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_argmax.py b/src/awkward/operations/ak_argmax.py index a4dbe947bd..ef83975c28 100644 --- a/src/awkward/operations/ak_argmax.py +++ b/src/awkward/operations/ak_argmax.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -137,7 +138,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.ArgMax() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_argmin.py b/src/awkward/operations/ak_argmin.py index 7f21fb3aa8..68067fd974 100644 --- a/src/awkward/operations/ak_argmin.py +++ b/src/awkward/operations/ak_argmin.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -135,7 +136,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): reducer = ak._reducers.ArgMin() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_count.py b/src/awkward/operations/ak_count.py index 85f43a27ee..a9c693c1c8 100644 --- a/src/awkward/operations/ak_count.py +++ b/src/awkward/operations/ak_count.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -114,7 +115,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.Count() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_count_nonzero.py b/src/awkward/operations/ak_count_nonzero.py index 919a6abf22..db73b0b411 100644 --- a/src/awkward/operations/ak_count_nonzero.py +++ b/src/awkward/operations/ak_count_nonzero.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -73,7 +74,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.CountNonzero() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_max.py b/src/awkward/operations/ak_max.py index 471101309d..21f544e190 100644 --- a/src/awkward/operations/ak_max.py +++ b/src/awkward/operations/ak_max.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -147,7 +148,7 @@ def _impl(array, axis, keepdims, initial, mask_identity, highlevel, behavior, at layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.Max(initial) - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_min.py b/src/awkward/operations/ak_min.py index 081bc91faf..b8403df44a 100644 --- a/src/awkward/operations/ak_min.py +++ b/src/awkward/operations/ak_min.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -147,7 +148,7 @@ def _impl(array, axis, keepdims, initial, mask_identity, highlevel, behavior, at layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.Min(initial) - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_prod.py b/src/awkward/operations/ak_prod.py index cde898f174..c84850b940 100644 --- a/src/awkward/operations/ak_prod.py +++ b/src/awkward/operations/ak_prod.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -124,7 +125,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.Prod() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, diff --git a/src/awkward/operations/ak_sum.py b/src/awkward/operations/ak_sum.py index f00434083e..8cdb54b4b0 100644 --- a/src/awkward/operations/ak_sum.py +++ b/src/awkward/operations/ak_sum.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import reduce as do_reduce from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -274,7 +275,7 @@ def _impl(array, axis, keepdims, mask_identity, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") reducer = ak._reducers.Sum() - out = ak._do.reduce( + out = do_reduce( layout, reducer, axis=axis, From a6eb28a1df72ce590fad5bf4e0e4a1e1220c20f7 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 21 Nov 2023 17:02:14 +0000 Subject: [PATCH 04/12] refactor: drop meta --- src/awkward/_connect/jax/trees.py | 7 +- src/awkward/_do/meta.py | 67 +- src/awkward/_meta/bitmaskedmeta.py | 17 +- src/awkward/_meta/bytemaskedmeta.py | 17 +- src/awkward/_meta/emptymeta.py | 2 +- src/awkward/_meta/indexedmeta.py | 15 +- src/awkward/_meta/indexedoptionmeta.py | 15 +- src/awkward/_meta/listmeta.py | 24 +- src/awkward/_meta/listoffsetmeta.py | 24 +- src/awkward/_meta/meta.py | 2 +- src/awkward/_meta/numpymeta.py | 15 +- src/awkward/_meta/recordmeta.py | 31 +- src/awkward/_meta/regularmeta.py | 20 +- src/awkward/_meta/unionmeta.py | 14 +- src/awkward/_meta/unmaskedmeta.py | 19 +- src/awkward/_slicing.py | 9 +- src/awkward/_typing.py | 14 +- src/awkward/contents/bitmaskedarray.py | 6 +- src/awkward/contents/bytemaskedarray.py | 6 +- src/awkward/contents/content.py | 2 + src/awkward/contents/indexedarray.py | 9 +- src/awkward/contents/indexedoptionarray.py | 9 +- src/awkward/contents/listarray.py | 6 +- src/awkward/contents/listoffsetarray.py | 6 +- src/awkward/contents/numpyarray.py | 2 +- src/awkward/contents/recordarray.py | 6 +- src/awkward/contents/regulararray.py | 6 +- src/awkward/contents/unionarray.py | 9 +- src/awkward/contents/unmaskedarray.py | 6 +- src/awkward/forms/bitmaskedform.py | 18 +- src/awkward/forms/bytemaskedform.py | 18 +- src/awkward/forms/form.py | 2 + src/awkward/forms/indexedform.py | 20 +- src/awkward/forms/indexedoptionform.py | 20 +- src/awkward/forms/listform.py | 18 +- src/awkward/forms/listoffsetform.py | 10 +- src/awkward/forms/numpyform.py | 4 +- src/awkward/forms/recordform.py | 25 +- src/awkward/forms/regularform.py | 18 +- src/awkward/forms/unionform.py | 18 +- src/awkward/forms/unmaskedform.py | 20 +- src/awkward/operations/ak_argcombinations.py | 6 +- src/awkward/operations/ak_argsort.py | 3 +- src/awkward/operations/ak_cartesian.py | 5 +- src/awkward/operations/ak_categories.py | 4 +- src/awkward/operations/ak_combinations.py | 4 +- src/awkward/operations/ak_concatenate.py | 6 +- src/awkward/operations/ak_drop_none.py | 6 +- src/awkward/operations/ak_enforce_type.py | 6 +- src/awkward/operations/ak_fill_none.py | 8 +- src/awkward/operations/ak_firsts.py | 3 +- src/awkward/operations/ak_flatten.py | 8 +- src/awkward/operations/ak_from_arrow.py | 3 +- src/awkward/operations/ak_from_categorical.py | 3 +- src/awkward/operations/ak_from_json.py | 3 +- src/awkward/operations/ak_from_regular.py | 6 +- src/awkward/operations/ak_full_like.py | 3 +- src/awkward/operations/ak_is_none.py | 3 +- src/awkward/operations/ak_local_index.py | 4 +- .../operations/ak_merge_option_of_records.py | 5 +- .../operations/ak_merge_union_of_records.py | 3 +- src/awkward/operations/ak_nan_to_none.py | 3 +- src/awkward/operations/ak_nan_to_num.py | 3 +- src/awkward/operations/ak_num.py | 3 +- src/awkward/operations/ak_pad_none.py | 4 +- src/awkward/operations/ak_ravel.py | 5 +- src/awkward/operations/ak_run_lengths.py | 3 +- src/awkward/operations/ak_singletons.py | 3 +- src/awkward/operations/ak_sort.py | 3 +- src/awkward/operations/ak_strings_astype.py | 3 +- src/awkward/operations/ak_to_buffers.py | 3 +- src/awkward/operations/ak_to_regular.py | 6 +- src/awkward/operations/ak_transform.py | 2 +- src/awkward/operations/ak_unflatten.py | 3 +- src/awkward/operations/ak_unzip.py | 3 +- src/awkward/operations/ak_validity_error.py | 3 +- src/awkward/operations/ak_with_field.py | 3 +- src/awkward/operations/ak_with_name.py | 3 +- src/awkward/operations/ak_without_field.py | 5 +- .../operations/ak_without_parameters.py | 4 +- .../operations/str/akstr_capitalize.py | 3 +- src/awkward/operations/str/akstr_center.py | 3 +- .../operations/str/akstr_count_substring.py | 3 +- .../str/akstr_count_substring_regex.py | 3 +- src/awkward/operations/str/akstr_ends_with.py | 3 +- .../operations/str/akstr_extract_regex.py | 3 +- .../operations/str/akstr_find_substring.py | 3 +- .../str/akstr_find_substring_regex.py | 3 +- src/awkward/operations/str/akstr_index_in.py | 4 +- src/awkward/operations/str/akstr_is_alnum.py | 3 +- src/awkward/operations/str/akstr_is_alpha.py | 3 +- src/awkward/operations/str/akstr_is_ascii.py | 3 +- .../operations/str/akstr_is_decimal.py | 3 +- src/awkward/operations/str/akstr_is_digit.py | 3 +- src/awkward/operations/str/akstr_is_in.py | 4 +- src/awkward/operations/str/akstr_is_lower.py | 3 +- .../operations/str/akstr_is_numeric.py | 3 +- .../operations/str/akstr_is_printable.py | 3 +- src/awkward/operations/str/akstr_is_space.py | 3 +- src/awkward/operations/str/akstr_is_title.py | 3 +- src/awkward/operations/str/akstr_is_upper.py | 3 +- src/awkward/operations/str/akstr_join.py | 3 +- src/awkward/operations/str/akstr_length.py | 3 +- src/awkward/operations/str/akstr_lower.py | 3 +- src/awkward/operations/str/akstr_lpad.py | 3 +- src/awkward/operations/str/akstr_ltrim.py | 3 +- .../operations/str/akstr_ltrim_whitespace.py | 3 +- .../operations/str/akstr_match_like.py | 3 +- .../operations/str/akstr_match_substring.py | 3 +- .../str/akstr_match_substring_regex.py | 3 +- src/awkward/operations/str/akstr_repeat.py | 3 +- .../operations/str/akstr_replace_slice.py | 3 +- .../operations/str/akstr_replace_substring.py | 3 +- .../str/akstr_replace_substring_regex.py | 3 +- src/awkward/operations/str/akstr_reverse.py | 3 +- src/awkward/operations/str/akstr_rpad.py | 3 +- src/awkward/operations/str/akstr_rtrim.py | 3 +- .../operations/str/akstr_rtrim_whitespace.py | 3 +- src/awkward/operations/str/akstr_slice.py | 4 +- .../operations/str/akstr_split_pattern.py | 3 +- .../str/akstr_split_pattern_regex.py | 3 +- .../operations/str/akstr_split_whitespace.py | 3 +- .../operations/str/akstr_starts_with.py | 3 +- src/awkward/operations/str/akstr_swapcase.py | 3 +- src/awkward/operations/str/akstr_title.py | 3 +- .../operations/str/akstr_to_categorical.py | 4 +- src/awkward/operations/str/akstr_trim.py | 3 +- .../operations/str/akstr_trim_whitespace.py | 3 +- src/awkward/operations/str/akstr_upper.py | 3 +- src/awkward/record.py | 3 +- tests/test_0072_fillna_operation.py | 22 +- tests/test_0078_argcross_and_cross.py | 18 +- ..._flatpandas_multiindex_rows_and_columns.py | 1 - ...093_simplify_uniontypes_and_optiontypes.py | 40 +- tests/test_0127_tomask_operation.py | 14 +- tests/test_0150_flatten.py | 12 +- tests/test_0184_concatenate_operation.py | 6 +- .../test_0397_arrays_as_constants_in_numba.py | 1 - tests/test_0404_array_validity_check.py | 138 +-- tests/test_1059_localindex.py | 531 +++++------ tests/test_1074_combinations.py | 308 ++++--- tests/test_1135_rpad_operation.py | 824 ++++++++---------- tests/test_1142_numbers_to_type.py | 214 ++--- tests/test_1149_datetime_sort.py | 10 +- .../test_1240_v2_implementation_of_numba_1.py | 1 - tests/test_2408_layoutbuilder_in_numba.py | 1 - tests/test_2616_use_pyarrow_for_strings.py | 1 - tests/test_2808_dtype_ufunc_bool.py | 1 - 148 files changed, 1520 insertions(+), 1510 deletions(-) diff --git a/src/awkward/_connect/jax/trees.py b/src/awkward/_connect/jax/trees.py index 27ea8a57fd..a0d90c86db 100644 --- a/src/awkward/_connect/jax/trees.py +++ b/src/awkward/_connect/jax/trees.py @@ -9,6 +9,7 @@ from awkward._backends.backend import Backend from awkward._backends.jax import JaxBackend from awkward._behavior import behavior_of +from awkward._do.content import recursively_apply from awkward._layout import wrap_layout from awkward._nplikes.jax import Jax from awkward._nplikes.numpy import Numpy @@ -30,9 +31,7 @@ def action(node, **kwargs): if isinstance(node, ak.contents.NumpyArray): data_ptrs.append(node.data) - ak._do.recursively_apply( - layout, action=action, return_array=False, numpy_to_regular=False - ) + recursively_apply(layout, action=action, return_array=False, numpy_to_regular=False) return data_ptrs @@ -54,7 +53,7 @@ def action(node, **kwargs): buffer, parameters=node.parameters, backend=backend ) - return ak._do.recursively_apply(layout, action=action, numpy_to_regular=False) + return recursively_apply(layout, action=action, numpy_to_regular=False) T = TypeVar( diff --git a/src/awkward/_do/meta.py b/src/awkward/_do/meta.py index 8053eb47b9..7333049952 100644 --- a/src/awkward/_do/meta.py +++ b/src/awkward/_do/meta.py @@ -3,10 +3,73 @@ from __future__ import annotations from awkward._nplikes.numpy_like import NumpyMetadata -from awkward.contents.content import Content +from awkward._typing import TYPE_CHECKING, TypeGuard, TypeVar + +if TYPE_CHECKING: + from awkward._meta.bitmaskedmeta import BitMaskedMeta + from awkward._meta.bytemaskedmeta import ByteMaskedMeta + from awkward._meta.indexedmeta import IndexedMeta + from awkward._meta.indexedoptionmeta import IndexedOptionMeta + from awkward._meta.listmeta import ListMeta + from awkward._meta.listoffsetmeta import ListOffsetMeta + from awkward._meta.meta import Meta + from awkward._meta.numpymeta import NumpyMeta + from awkward._meta.recordmeta import RecordMeta + from awkward._meta.regularmeta import RegularMeta + from awkward._meta.unionmeta import UnionMeta + from awkward._meta.unmaskedmeta import UnmaskedMeta np = NumpyMetadata.instance() -def mergeable(one: Content, two: Content, mergebool: bool = True) -> bool: +T = TypeVar("T", bound="Meta") + + +def is_option( + meta: Meta +) -> TypeGuard[IndexedOptionMeta | BitMaskedMeta | ByteMaskedMeta | UnmaskedMeta]: + return meta.is_option + + +def is_list(meta: Meta) -> TypeGuard[RegularMeta | ListOffsetMeta | ListMeta]: + return meta.is_list + + +def is_numpy(meta: Meta) -> TypeGuard[NumpyMeta]: + return meta.is_numpy + + +def is_regular(meta: Meta) -> TypeGuard[RegularMeta]: + return meta.is_regular + + +def is_union(meta: Meta) -> TypeGuard[UnionMeta]: + return meta.is_union + + +def is_record(meta: Meta) -> TypeGuard[RecordMeta]: + return meta.is_record + + +def is_indexed(meta: Meta) -> TypeGuard[IndexedOptionMeta, IndexedMeta]: + return meta.is_indexed + + +class ImplementsTuple(RecordMeta): # Intersection + _fields: None + + +def is_record_tuple(meta: Meta) -> TypeGuard[ImplementsTuple]: + return meta.is_record and meta.is_tuple + + +class ImplementsRecord(RecordMeta): + _fields: list[str] + + +def is_record_record(meta: Meta) -> TypeGuard[ImplementsRecord]: + return meta.is_record and not meta.is_tuple + + +def mergeable(one: Meta, two: Meta, mergebool: bool = True) -> bool: return one._mergeable_next(two, mergebool=mergebool) diff --git a/src/awkward/_meta/bitmaskedmeta.py b/src/awkward/_meta/bitmaskedmeta.py index de672e4aac..55e70ef3a4 100644 --- a/src/awkward/_meta/bitmaskedmeta.py +++ b/src/awkward/_meta/bitmaskedmeta.py @@ -2,15 +2,14 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class BitMaskedMeta(Meta, Generic[T]): - _content: T +class BitMaskedMeta(Meta): + _content: Meta is_option = True @property @@ -54,15 +53,15 @@ def dimension_optiontype(self) -> bool: return True @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True - # We can only combine option types whose array-record parameters agree - elif other.is_option or other.is_indexed: + # We can only combine option/indexed types whose array-record parameters agree + elif is_option(other) or is_indexed(other): return self._content._mergeable_next( other.content, mergebool ) and type_parameters_equal(self._parameters, other._parameters) diff --git a/src/awkward/_meta/bytemaskedmeta.py b/src/awkward/_meta/bytemaskedmeta.py index 7bf2a77f3d..6945ddd8fd 100644 --- a/src/awkward/_meta/bytemaskedmeta.py +++ b/src/awkward/_meta/bytemaskedmeta.py @@ -2,15 +2,14 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class ByteMaskedMeta(Meta, Generic[T]): - _content: T +class ByteMaskedMeta(Meta): + _content: Meta is_option = True @property @@ -54,15 +53,15 @@ def dimension_optiontype(self) -> bool: return True @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True - # We can only combine option types whose array-record parameters agree - elif other.is_option or other.is_indexed: + # We can only combine option/indexed types whose array-record parameters agree + elif is_option(other) or is_indexed(other): return self._content._mergeable_next( other.content, mergebool ) and type_parameters_equal(self._parameters, other._parameters) diff --git a/src/awkward/_meta/emptymeta.py b/src/awkward/_meta/emptymeta.py index 8707913188..c9553d14b3 100644 --- a/src/awkward/_meta/emptymeta.py +++ b/src/awkward/_meta/emptymeta.py @@ -45,5 +45,5 @@ def is_tuple(self) -> bool: def dimension_optiontype(self) -> bool: return False - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: return True diff --git a/src/awkward/_meta/indexedmeta.py b/src/awkward/_meta/indexedmeta.py index 8c2b7bbdab..cf5f0aac48 100644 --- a/src/awkward/_meta/indexedmeta.py +++ b/src/awkward/_meta/indexedmeta.py @@ -2,17 +2,16 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class IndexedMeta(Meta, Generic[T]): +class IndexedMeta(Meta): is_indexed = True - _content: T + _content: Meta def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -55,15 +54,15 @@ def dimension_optiontype(self) -> bool: return False @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # We can only combine option/indexed types whose array-record parameters agree - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): return self._content._mergeable_next( other.content, mergebool ) and type_parameters_equal(self._parameters, other._parameters) diff --git a/src/awkward/_meta/indexedoptionmeta.py b/src/awkward/_meta/indexedoptionmeta.py index cf28cd854b..5891a36e91 100644 --- a/src/awkward/_meta/indexedoptionmeta.py +++ b/src/awkward/_meta/indexedoptionmeta.py @@ -2,18 +2,17 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class IndexedOptionMeta(Meta, Generic[T]): +class IndexedOptionMeta(Meta): is_indexed = True is_option = True - _content: T + _content: Meta def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -56,15 +55,15 @@ def dimension_optiontype(self) -> bool: return True @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # We can only combine option/indexed types whose array-record parameters agree - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): return self._content._mergeable_next( other.content, mergebool ) and type_parameters_equal(self._parameters, other._parameters) diff --git a/src/awkward/_meta/listmeta.py b/src/awkward/_meta/listmeta.py index 4be469072e..887f6b162a 100644 --- a/src/awkward/_meta/listmeta.py +++ b/src/awkward/_meta/listmeta.py @@ -2,17 +2,16 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_list, is_numpy, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class ListMeta(Meta, Generic[T]): +class ListMeta(Meta): is_list = True - _content: T + _content: Meta def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -66,24 +65,23 @@ def dimension_optiontype(self) -> bool: return False @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # Check against option contents - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): + assert hasattr(other, "content") return self._mergeable_next(other.content, mergebool) # Otherwise, do the parameters match? If not, we can't merge. elif not type_parameters_equal(self._parameters, other._parameters): return False - elif other.is_list: + elif is_list(other): return self._content._mergeable_next(other.content, mergebool) - elif other.is_numpy and len(other.inner_shape) > 0: - return self._mergeable_next( - other._to_regular_primitive(), mergebool - ) # TODO + elif is_numpy(other) and len(other.inner_shape) > 0: + return self._mergeable_next(other._to_regular_primitive(), mergebool) else: return False diff --git a/src/awkward/_meta/listoffsetmeta.py b/src/awkward/_meta/listoffsetmeta.py index 862c029fe0..f82918e1c6 100644 --- a/src/awkward/_meta/listoffsetmeta.py +++ b/src/awkward/_meta/listoffsetmeta.py @@ -2,17 +2,16 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_list, is_numpy, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class ListOffsetMeta(Meta, Generic[T]): +class ListOffsetMeta(Meta): is_list = True - _content: T + _content: Meta def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -66,24 +65,23 @@ def dimension_optiontype(self) -> bool: return False @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # Check against option contents - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): + assert hasattr(other, "content") return self._mergeable_next(other.content, mergebool) # Otherwise, do the parameters match? If not, we can't merge. elif not type_parameters_equal(self._parameters, other._parameters): return False - elif other.is_list: + elif is_list(other): return self._content._mergeable_next(other.content, mergebool) - elif other.is_numpy and len(other.inner_shape) > 0: - return self._mergeable_next( - other._to_regular_primitive(), mergebool - ) # TODO + elif is_numpy(other) and len(other.inner_shape) > 0: + return self._mergeable_next(other._to_regular_primitive(), mergebool) else: return False diff --git a/src/awkward/_meta/meta.py b/src/awkward/_meta/meta.py index ab8fea9090..31ddb6b7fc 100644 --- a/src/awkward/_meta/meta.py +++ b/src/awkward/_meta/meta.py @@ -119,5 +119,5 @@ def dimension_optiontype(self) -> bool: def copy(self, *, parameters: JSONMapping | None | Sentinel = UNSET) -> Self: raise NotImplementedError - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: raise NotImplementedError diff --git a/src/awkward/_meta/numpymeta.py b/src/awkward/_meta/numpymeta.py index 5b377ae3e9..7175cd7ac7 100644 --- a/src/awkward/_meta/numpymeta.py +++ b/src/awkward/_meta/numpymeta.py @@ -2,18 +2,17 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_numpy, is_option from awkward._meta.meta import Meta from awkward._nplikes.shape import ShapeItem from awkward._parameters import type_parameters_equal -from awkward._typing import TYPE_CHECKING, Generic, JSONSerializable, TypeVar +from awkward._typing import TYPE_CHECKING, JSONSerializable if TYPE_CHECKING: from awkward._meta.regularmeta import RegularMeta -T = TypeVar("T", bound=Meta) - -class NumpyMeta(Meta, Generic[T]): +class NumpyMeta(Meta): is_numpy = True is_leaf = True inner_shape: tuple[ShapeItem, ...] @@ -58,15 +57,15 @@ def is_tuple(self) -> bool: def dimension_optiontype(self) -> bool: return False - def _to_regular_primitive(self) -> RegularMeta[T]: + def _to_regular_primitive(self) -> RegularMeta | NumpyMeta: raise NotImplementedError - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # Check against option contents - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): return self._mergeable_next(other.content, mergebool) # Otherwise, do the parameters match? If not, we can't merge. elif not type_parameters_equal(self._parameters, other._parameters): @@ -77,7 +76,7 @@ def _mergeable_next(self, other: T, mergebool: bool) -> bool: other, mergebool ) # TODO - elif other.is_numpy: + elif is_numpy(other): if len(self.inner_shape) != len(other.inner_shape): return False diff --git a/src/awkward/_meta/recordmeta.py b/src/awkward/_meta/recordmeta.py index d51f0f788c..7448227159 100644 --- a/src/awkward/_meta/recordmeta.py +++ b/src/awkward/_meta/recordmeta.py @@ -2,19 +2,24 @@ from __future__ import annotations +from awkward._do.meta import ( + is_indexed, + is_option, + is_record, + is_record_record, + is_record_tuple, +) from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal from awkward._regularize import is_integer -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable from awkward.errors import FieldNotFoundError -T = TypeVar("T", bound=Meta) - -class RecordMeta(Meta, Generic[T]): +class RecordMeta(Meta): is_record = True - _contents: list[T] + _contents: list[Meta] _fields: list[str] | None @property @@ -78,7 +83,7 @@ def is_leaf(self) -> bool: # type: ignore[override] return len(self._contents) == 0 @property - def contents(self) -> list[T]: + def contents(self) -> list[Meta]: return self._contents @property @@ -130,7 +135,7 @@ def has_field(self, field: str) -> bool: else: return field in self._fields - def content(self, index_or_field: int | str) -> T: + def content(self, index_or_field: int | str) -> Meta: if is_integer(index_or_field): index = index_or_field elif isinstance(index_or_field, str): @@ -143,26 +148,28 @@ def content(self, index_or_field: int | str) -> T: ) return self._contents[index] # type: ignore[index] - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # Check against option contents - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): return self._mergeable_next(other.content, mergebool) # Otherwise, do the parameters match? If not, we can't merge. elif not type_parameters_equal(self._parameters, other._parameters): return False - elif other.is_record: - if self.is_tuple and other.is_tuple: + elif is_record(other): + if is_record_tuple(self) and is_record_tuple(other): if len(self.contents) == len(other.contents): for self_cont, other_cont in zip(self.contents, other.contents): if not self_cont._mergeable_next(other_cont, mergebool): return False return True + else: + return False - elif not self.is_tuple and not other.is_tuple: + elif is_record_record(self) and is_record_record(other): if set(self._fields) != set(other._fields): return False diff --git a/src/awkward/_meta/regularmeta.py b/src/awkward/_meta/regularmeta.py index 09ef21c10c..2b91d46d4e 100644 --- a/src/awkward/_meta/regularmeta.py +++ b/src/awkward/_meta/regularmeta.py @@ -2,20 +2,19 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_list, is_numpy, is_option from awkward._meta.meta import Meta from awkward._nplikes.shape import ShapeItem from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class RegularMeta(Meta, Generic[T]): +class RegularMeta(Meta): is_list = True is_regular = True size: ShapeItem - _content: T + _content: Meta def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -69,22 +68,23 @@ def dimension_optiontype(self) -> bool: return False @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True # Check against option contents - elif other.is_option or other.is_indexed: + elif is_option(other) or is_indexed(other): + assert hasattr(other, "content") return self._mergeable_next(other.content, mergebool) # Otherwise, do the parameters match? If not, we can't merge. elif not type_parameters_equal(self._parameters, other._parameters): return False - elif other.is_list: + elif is_list(other): return self._content._mergeable_next(other.content, mergebool) - elif other.is_numpy and len(other.inner_shape) > 0: + elif is_numpy(other) and len(other.inner_shape) > 0: return self._mergeable_next(other._to_regular_primitive(), mergebool) else: return False diff --git a/src/awkward/_meta/unionmeta.py b/src/awkward/_meta/unionmeta.py index 08e3b25a5f..b455d45f97 100644 --- a/src/awkward/_meta/unionmeta.py +++ b/src/awkward/_meta/unionmeta.py @@ -5,15 +5,13 @@ from collections import Counter from awkward._meta.meta import Meta -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class UnionMeta(Meta, Generic[T]): +class UnionMeta(Meta): is_union = True - _contents: list[T] + _contents: list[Meta] def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -99,12 +97,12 @@ def dimension_optiontype(self) -> bool: return True return False - def content(self, index: int) -> T: + def content(self, index: int) -> Meta: return self._contents[index] @property - def contents(self) -> list[T]: + def contents(self) -> list[Meta]: return self._contents - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: return True diff --git a/src/awkward/_meta/unmaskedmeta.py b/src/awkward/_meta/unmaskedmeta.py index da03764b10..d6a03379c3 100644 --- a/src/awkward/_meta/unmaskedmeta.py +++ b/src/awkward/_meta/unmaskedmeta.py @@ -2,16 +2,15 @@ from __future__ import annotations +from awkward._do.meta import is_indexed, is_option from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal -from awkward._typing import Generic, JSONSerializable, TypeVar +from awkward._typing import JSONSerializable -T = TypeVar("T", bound=Meta) - -class UnmaskedMeta(Meta, Generic[T]): +class UnmaskedMeta(Meta): is_option = True - _content: T + _content: Meta def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: @@ -54,16 +53,16 @@ def dimension_optiontype(self) -> bool: return True @property - def content(self) -> T: + def content(self) -> Meta: return self._content - def _mergeable_next(self, other: T, mergebool: bool) -> bool: + def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Is the other content is an identity, or a union? if other.is_identity_like or other.is_union: return True - # We can only combine option types whose array-record parameters agree - elif other.is_option or other.is_indexed: - return self._mergeable_next( + # We can only combine option/indexed types whose array-record parameters agree + elif is_option(other) or is_indexed(other): + return self._content._mergeable_next( other.content, mergebool ) and type_parameters_equal(self._parameters, other._parameters) else: diff --git a/src/awkward/_slicing.py b/src/awkward/_slicing.py index bb266c3b53..0ed174c66e 100644 --- a/src/awkward/_slicing.py +++ b/src/awkward/_slicing.py @@ -6,6 +6,7 @@ import awkward as ak from awkward._backends.backend import Backend +from awkward._do.content import flatten, local_index from awkward._nplikes import to_nplike from awkward._nplikes.dispatch import nplike_of_obj from awkward._nplikes.jax import Jax @@ -506,10 +507,10 @@ def _normalise_item_bool_to_int(item: Content, backend: Backend) -> Content: ): if item_backend.nplike.known_data: item = item.to_ListOffsetArray64(True) - localindex = ak._do.local_index(item, axis=1) + localindex = local_index(item, axis=1) - flat_index = ak._do.flatten(localindex, axis=1) - flat_mask = ak._do.flatten(item, axis=1) + flat_index = flatten(localindex, axis=1) + flat_mask = flatten(item, axis=1) assert flat_index.is_numpy and flat_mask.is_numpy nextcontent = flat_index.data[flat_mask.data] @@ -558,7 +559,7 @@ def _normalise_item_bool_to_int(item: Content, backend: Backend) -> Content: safeindex.shape[0], dtype=np.bool_ ) - localindex = ak._do.local_index(item, axis=1) + localindex = local_index(item, axis=1) # nextcontent does not include missing values expanded[isnegative] = False diff --git a/src/awkward/_typing.py b/src/awkward/_typing.py index 3b1ffaf894..afca0fe43f 100644 --- a/src/awkward/_typing.py +++ b/src/awkward/_typing.py @@ -30,9 +30,6 @@ } ) - -AxisMaybeNone = TypeVar("AxisMaybeNone", int, None) # noqa: F405 - if sys.version_info < (3, 11): from typing import ClassVar, Final, SupportsIndex, runtime_checkable @@ -71,3 +68,14 @@ JSONMapping: TypeAlias = "dict[str, JSONSerializable]" DType: TypeAlias = numpy.dtype + + +AxisMaybeNone = TypeVar("AxisMaybeNone", int, None) # noqa: F405 + + +T = TypeVar("T") + + +class ImplementsReadOnlyProperty(Protocol[T]): + def __get__(self, instance, owner=None) -> T: + ... diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index 4fe3b6a25d..0a542b54b1 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -22,6 +22,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -48,7 +49,7 @@ @final -class BitMaskedArray(BitMaskedMeta[Content], Content): +class BitMaskedArray(BitMaskedMeta, Content): """ Like #ak.contents.ByteMaskedArray, BitMaskedArray implements an #ak.types.OptionType with two buffers, `mask` and `content`. @@ -132,6 +133,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__( self, mask, content, valid_when, length, lsb_order, *, parameters=None ): diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index aa57c60f18..7ed3314d8d 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -26,6 +26,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -52,7 +53,7 @@ @final -class ByteMaskedArray(ByteMaskedMeta[Content], Content): +class ByteMaskedArray(ByteMaskedMeta, Content): """ The ByteMaskedArray implements an #ak.types.OptionType with two aligned buffers, a boolean `mask` and `content`. At any element `i` where @@ -109,6 +110,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, mask, content, valid_when, *, parameters=None): if not (isinstance(mask, Index) and mask.dtype == np.dtype(np.int8)): raise TypeError( diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index 3812fec414..f2b3ac83c4 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -122,6 +122,8 @@ class ToArrowOptions(TypedDict): class Content(Meta): + _mergeable_next: Callable[[Content, bool], bool] + def _init(self, parameters: dict[str, Any] | None, backend: Backend): if parameters is None: pass diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index 51f761b10d..9036ae1f48 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -7,6 +7,7 @@ import awkward as ak from awkward._backends.backend import Backend +from awkward._do.content import is_unique from awkward._layout import maybe_posaxis from awkward._meta.indexedmeta import IndexedMeta from awkward._nplikes.array_like import ArrayLike @@ -25,6 +26,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -51,7 +53,7 @@ @final -class IndexedArray(IndexedMeta[Content], Content): +class IndexedArray(IndexedMeta, Content): """ IndexedArray is a general-purpose tool for *lazily* changing the order of and/or duplicating some `content` with a @@ -102,6 +104,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, index, content, *, parameters=None): if not ( isinstance(index, Index) @@ -946,7 +951,7 @@ def _reduce_next( def _validity_error(self, path): if self.parameter("__array__") == "categorical": - if not ak._do.is_unique(self._content): + if not is_unique(self._content): return 'at {} ("{}"): __array__ = "categorical" requires contents to be unique'.format( path, type(self) ) diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index 2a426c3a69..857ae334c4 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -7,6 +7,7 @@ import awkward as ak from awkward._backends.backend import Backend +from awkward._do.content import is_unique from awkward._layout import maybe_posaxis from awkward._meta.indexedoptionmeta import IndexedOptionMeta from awkward._nplikes.array_like import ArrayLike @@ -25,6 +26,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -50,7 +52,7 @@ @final -class IndexedOptionArray(IndexedOptionMeta[Content], Content): +class IndexedOptionArray(IndexedOptionMeta, Content): """ IndexedOptionArray is an #ak.contents.IndexedArray for which negative values in the index are interpreted as missing. It represents @@ -98,6 +100,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, index, content, *, parameters=None): if not ( isinstance(index, Index) @@ -1465,7 +1470,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): def _validity_error(self, path): if self.parameter("__array__") == "categorical": - if not ak._do.is_unique(self._content): + if not is_unique(self._content): return 'at {} ("{}"): __array__ = "categorical" requires contents to be unique'.format( path, type(self) ) diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 161c50e2d9..0ae42cce54 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -23,6 +23,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -47,7 +48,7 @@ @final -class ListArray(ListMeta[Content], Content): +class ListArray(ListMeta, Content): """ ListArray generalizes #ak.contents.ListOffsetArray by not requiring its `content` to be in increasing order and by allowing it to @@ -119,6 +120,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, starts, stops, content, *, parameters=None): if not isinstance(starts, Index) and starts.dtype in ( np.dtype(np.int32), diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 4d34724e48..da20c44fae 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -21,6 +21,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -46,7 +47,7 @@ @final -class ListOffsetArray(ListOffsetMeta[Content], Content): +class ListOffsetArray(ListOffsetMeta, Content): """ ListOffsetArray describes unequal-length lists (often called a "jagged" or "ragged" array). Like #ak.contents.RegularArray, the @@ -110,6 +111,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, offsets, content, *, parameters=None): if not isinstance(offsets, Index) and offsets.dtype in ( np.dtype(np.int32), diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index a0a4d1698f..75f48f0940 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -56,7 +56,7 @@ @final -class NumpyArray(NumpyMeta[Content], Content): +class NumpyArray(NumpyMeta, Content): """ A NumpyArray describes 1-dimensional or rectilinear data using a NumPy `np.ndarray`, a CuPy `cp.ndarray`, etc., depending on the backend. diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 92d07c13a8..b3c8071821 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -26,6 +26,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -59,7 +60,7 @@ def _apply_record_reducer(reducer, layout: Content, mask: bool, behavior) -> Con @final -class RecordArray(RecordMeta[Content], Content): +class RecordArray(RecordMeta, Content): """ RecordArray represents an array of tuples or records, all with the same type. Its `contents` is an ordered list of arrays. @@ -145,6 +146,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _contents: list[Content] + contents: ImplementsReadOnlyProperty[list[Content]] + def __init__( self, contents: Iterable[Content], diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index d3a828388f..d15d2061f6 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -24,6 +24,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -49,7 +50,7 @@ @final -class RegularArray(RegularMeta[Content], Content): +class RegularArray(RegularMeta, Content): """ RegularArray describes lists that all have the same length, the single integer `size`. Its underlying `content` is a flattened view of the data; @@ -119,6 +120,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, content, size, zeros_length=0, *, parameters=None): if not isinstance(content, Content): raise TypeError( diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index f9b1b5a43e..b43ebafcb6 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -9,6 +9,7 @@ import awkward as ak from awkward._backends.backend import Backend +from awkward._do.meta import mergeable from awkward._layout import maybe_posaxis from awkward._meta.unionmeta import UnionMeta from awkward._nplikes.array_like import ArrayLike @@ -24,6 +25,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -49,7 +51,7 @@ @final -class UnionArray(UnionMeta[Content], Content): +class UnionArray(UnionMeta, Content): """ UnionArray represents data drawn from an ordered list of `contents`, which can have different types, using @@ -103,6 +105,9 @@ def __getitem__(self, where): raise AssertionError(where) """ + _contents: list[Content] + contents: ImplementsReadOnlyProperty[list[Content]] + def __init__(self, tags, index, contents, *, parameters=None): if not (isinstance(tags, Index) and tags.dtype == np.dtype(np.int8)): raise TypeError( @@ -1403,7 +1408,7 @@ def _validity_error(self, path): for i, content_i in enumerate(self._contents): for j in range(i): content_j = self._contents[j] - if ak._do.mergeable(content_i, content_j, mergebool=False): + if mergeable(content_i, content_j, mergebool=False): return f"at {path}: content({i}) is mergeable with content({j})" for i, content in enumerate(self._contents): diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index 1d694c3b8a..cab02c7ab5 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -26,6 +26,7 @@ Any, Callable, Final, + ImplementsReadOnlyProperty, Self, SupportsIndex, final, @@ -52,7 +53,7 @@ @final -class UnmaskedArray(UnmaskedMeta[Content], Content): +class UnmaskedArray(UnmaskedMeta, Content): """ UnmaskedArray implements an #ak.types.OptionType for which the values are never, in fact, missing. It exists to satisfy systems that formally require this @@ -85,6 +86,9 @@ def __getitem__(self, where): return UnmaskedArray(self.content[where]) """ + _content: Content + content: ImplementsReadOnlyProperty[Content] + def __init__(self, content, *, parameters=None): if not isinstance(content, Content): raise TypeError( diff --git a/src/awkward/forms/bitmaskedform.py b/src/awkward/forms/bitmaskedform.py index b875ee16d5..b68a724b68 100644 --- a/src/awkward/forms/bitmaskedform.py +++ b/src/awkward/forms/bitmaskedform.py @@ -7,7 +7,14 @@ import awkward as ak from awkward._meta.bitmaskedmeta import BitMaskedMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import Any, DType, Iterator, Self, final +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, +) from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher, index_to_dtype @@ -17,8 +24,9 @@ @final -class BitMaskedForm(BitMaskedMeta[Form], Form): - _content: Form +class BitMaskedForm(BitMaskedMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -61,10 +69,6 @@ def __init__( def mask(self): return self._mask - @property - def content(self): - return self._content - @property def valid_when(self): return self._valid_when diff --git a/src/awkward/forms/bytemaskedform.py b/src/awkward/forms/bytemaskedform.py index 1b40caf085..338058d4df 100644 --- a/src/awkward/forms/bytemaskedform.py +++ b/src/awkward/forms/bytemaskedform.py @@ -7,7 +7,14 @@ import awkward as ak from awkward._meta.bytemaskedmeta import ByteMaskedMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import Any, DType, Iterator, Self, final +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, +) from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher, index_to_dtype @@ -17,8 +24,9 @@ @final -class ByteMaskedForm(ByteMaskedMeta[Form], Form): - _content: Form +class ByteMaskedForm(ByteMaskedMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -55,10 +63,6 @@ def __init__( def mask(self): return self._mask - @property - def content(self): - return self._content - @property def valid_when(self): return self._valid_when diff --git a/src/awkward/forms/form.py b/src/awkward/forms/form.py index 18f16a0198..fe963a6044 100644 --- a/src/awkward/forms/form.py +++ b/src/awkward/forms/form.py @@ -379,6 +379,8 @@ def getkey(form, attribute): class Form(Meta): + _mergeable_next: Callable[[Form, bool], bool] # type: ignore[assignment] + def _init(self, *, parameters: JSONMapping | None, form_key: str | None): if parameters is not None and not isinstance(parameters, dict): raise TypeError( diff --git a/src/awkward/forms/indexedform.py b/src/awkward/forms/indexedform.py index e9936b4912..a76b347a7d 100644 --- a/src/awkward/forms/indexedform.py +++ b/src/awkward/forms/indexedform.py @@ -7,10 +7,15 @@ import awkward as ak from awkward._meta.indexedmeta import IndexedMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._parameters import ( - parameters_union, +from awkward._parameters import parameters_union +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, ) -from awkward._typing import Any, DType, Iterator, Self, final from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher, index_to_dtype @@ -20,8 +25,9 @@ @final -class IndexedForm(IndexedMeta[Form], Form): - _content: Form +class IndexedForm(IndexedMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -50,10 +56,6 @@ def __init__( def index(self): return self._index - @property - def content(self): - return self._content - def copy( self, index=UNSET, diff --git a/src/awkward/forms/indexedoptionform.py b/src/awkward/forms/indexedoptionform.py index 6d54be5e0c..3ad52de4b9 100644 --- a/src/awkward/forms/indexedoptionform.py +++ b/src/awkward/forms/indexedoptionform.py @@ -7,10 +7,15 @@ import awkward as ak from awkward._meta.indexedoptionmeta import IndexedOptionMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._parameters import ( - parameters_union, +from awkward._parameters import parameters_union +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, ) -from awkward._typing import Any, DType, Iterator, Self, final from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher, index_to_dtype @@ -20,8 +25,9 @@ @final -class IndexedOptionForm(IndexedOptionMeta[Form], Form): - _content: Form +class IndexedOptionForm(IndexedOptionMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -50,10 +56,6 @@ def __init__( def index(self): return self._index - @property - def content(self): - return self._content - def copy( self, index=UNSET, diff --git a/src/awkward/forms/listform.py b/src/awkward/forms/listform.py index 6ed46d5d41..4181f2f92a 100644 --- a/src/awkward/forms/listform.py +++ b/src/awkward/forms/listform.py @@ -7,7 +7,14 @@ import awkward as ak from awkward._meta.listmeta import ListMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import Any, DType, Iterator, Self, final +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, +) from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher, index_to_dtype @@ -17,8 +24,9 @@ @final -class ListForm(ListMeta[Form], Form): - _content: Form +class ListForm(ListMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -61,10 +69,6 @@ def starts(self): def stops(self): return self._stops - @property - def content(self): - return self._content - def copy( self, starts=UNSET, diff --git a/src/awkward/forms/listoffsetform.py b/src/awkward/forms/listoffsetform.py index 75a495b666..c2fc4826a8 100644 --- a/src/awkward/forms/listoffsetform.py +++ b/src/awkward/forms/listoffsetform.py @@ -10,6 +10,7 @@ from awkward._typing import ( Any, DType, + ImplementsReadOnlyProperty, Iterator, JSONMapping, Self, @@ -24,8 +25,9 @@ @final -class ListOffsetForm(ListOffsetMeta[Form], Form): - _content: Form +class ListOffsetForm(ListOffsetMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -50,10 +52,6 @@ def __init__( def offsets(self): return self._offsets - @property - def content(self): - return self._content - def copy( self, offsets=UNSET, diff --git a/src/awkward/forms/numpyform.py b/src/awkward/forms/numpyform.py index f40308d9ed..11de6bcf87 100644 --- a/src/awkward/forms/numpyform.py +++ b/src/awkward/forms/numpyform.py @@ -64,7 +64,7 @@ def from_dtype( @final -class NumpyForm(NumpyMeta[Form], Form): +class NumpyForm(NumpyMeta, Form): def __init__( self, primitive, @@ -259,7 +259,7 @@ def _expected_from_buffers( yield (getkey(self, "data"), primitive_to_dtype(self.primitive)) - def _to_regular_primitive(self) -> RegularForm: + def _to_regular_primitive(self) -> RegularForm | NumpyForm: return self.to_RegularForm() def _is_equal_to(self, other: Any, all_parameters: bool, form_key: bool) -> bool: diff --git a/src/awkward/forms/recordform.py b/src/awkward/forms/recordform.py index 04f4d66a9d..860be071cb 100644 --- a/src/awkward/forms/recordform.py +++ b/src/awkward/forms/recordform.py @@ -7,7 +7,14 @@ import awkward as ak from awkward._meta.recordmeta import RecordMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import Any, DType, Self, final +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, +) from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher @@ -17,7 +24,10 @@ @final -class RecordForm(RecordMeta[Form], Form): +class RecordForm(RecordMeta, Form): + _contents: list[Form] # type: ignore[assignment] + contents: ImplementsReadOnlyProperty[list[Form]] # type: ignore[assignment] + def __init__( self, contents, @@ -50,17 +60,6 @@ def __init__( assert len(self._fields) == len(self._contents) self._init(parameters=parameters, form_key=form_key) - @property - def contents(self): - return self._contents - - @property - def fields(self) -> list[str]: - if self._fields is None: - return [str(i) for i in range(len(self._contents))] - else: - return self._fields - def copy( self, contents=UNSET, diff --git a/src/awkward/forms/regularform.py b/src/awkward/forms/regularform.py index 10596bad2a..5eeb30a595 100644 --- a/src/awkward/forms/regularform.py +++ b/src/awkward/forms/regularform.py @@ -9,7 +9,14 @@ from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import unknown_length from awkward._regularize import is_integer -from awkward._typing import Any, DType, Self, final +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, +) from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher @@ -19,8 +26,9 @@ @final -class RegularForm(RegularMeta[Form], Form): - _content: Form +class RegularForm(RegularMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__(self, content, size, *, parameters=None, form_key=None): if not isinstance(content, Form): @@ -40,10 +48,6 @@ def __init__(self, content, size, *, parameters=None, form_key=None): self._size = size self._init(parameters=parameters, form_key=form_key) - @property - def content(self): - return self._content - @property def size(self): return self._size diff --git a/src/awkward/forms/unionform.py b/src/awkward/forms/unionform.py index fd6d439acc..05b0eb7bde 100644 --- a/src/awkward/forms/unionform.py +++ b/src/awkward/forms/unionform.py @@ -8,7 +8,14 @@ import awkward as ak from awkward._meta.unionmeta import UnionMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import Any, DType, Iterator, Self, final +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, +) from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher, index_to_dtype @@ -18,7 +25,10 @@ @final -class UnionForm(UnionMeta[Form], Form): +class UnionForm(UnionMeta, Form): + _contents: list[Form] # type: ignore[assignment] + contents: ImplementsReadOnlyProperty[list[Form]] # type: ignore[assignment] + def __init__( self, tags, @@ -63,10 +73,6 @@ def tags(self): def index(self): return self._index - @property - def contents(self): - return self._contents - def copy( self, tags=UNSET, diff --git a/src/awkward/forms/unmaskedform.py b/src/awkward/forms/unmaskedform.py index 99dd441c06..15ec3791a9 100644 --- a/src/awkward/forms/unmaskedform.py +++ b/src/awkward/forms/unmaskedform.py @@ -7,10 +7,15 @@ import awkward as ak from awkward._meta.unmaskedmeta import UnmaskedMeta from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._parameters import ( - parameters_union, +from awkward._parameters import parameters_union +from awkward._typing import ( + Any, + DType, + ImplementsReadOnlyProperty, + Iterator, + Self, + final, ) -from awkward._typing import Any, DType, Self, final from awkward._util import UNSET from awkward.forms.form import Form, _SpecifierMatcher @@ -20,8 +25,9 @@ @final -class UnmaskedForm(UnmaskedMeta[Form], Form): - _content: Form +class UnmaskedForm(UnmaskedMeta, Form): + _content: Form # type: ignore[assignment] + content: ImplementsReadOnlyProperty[Form] # type: ignore[assignment] def __init__( self, @@ -40,10 +46,6 @@ def __init__( self._content = content self._init(parameters=parameters, form_key=form_key) - @property - def content(self): - return self._content - def copy( self, content=UNSET, diff --git a/src/awkward/operations/ak_argcombinations.py b/src/awkward/operations/ak_argcombinations.py index 98a2643855..310b448104 100644 --- a/src/awkward/operations/ak_argcombinations.py +++ b/src/awkward/operations/ak_argcombinations.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import combinations, local_index from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -105,11 +105,11 @@ def _impl( raise ValueError("the 'axis' for argcombinations must be non-negative") else: with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: - layout = ak._do.local_index( + layout = local_index( ctx.unwrap(array, allow_record=False, primitive_policy="error"), axis, ) - out = ak._do.combinations( + out = combinations( layout, n, replacement=replacement, diff --git a/src/awkward/operations/ak_argsort.py b/src/awkward/operations/ak_argsort.py index bade378b20..fe90c1aee7 100644 --- a/src/awkward/operations/ak_argsort.py +++ b/src/awkward/operations/ak_argsort.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import argsort as do_argsort from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -73,7 +74,7 @@ def _impl(array, axis, ascending, stable, highlevel, behavior, attrs): axis = regularize_axis(axis) with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.argsort(layout, axis, ascending, stable) + out = do_argsort(layout, axis, ascending, stable) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_cartesian.py b/src/awkward/operations/ak_cartesian.py index 20d431cf7d..9453cfc916 100644 --- a/src/awkward/operations/ak_cartesian.py +++ b/src/awkward/operations/ak_cartesian.py @@ -7,6 +7,7 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -355,7 +356,7 @@ def apply_pad_inner_list_at_axis(layout, depth, lateral_context, **kwargs): "ak.cartesian does not compute combinations of the " "characters of a string; please split it into lists" ) - nextlayout = ak._do.recursively_apply( + nextlayout = recursively_apply( layout, apply_pad_inner_list, lateral_context={"n": n_inside}, @@ -375,7 +376,7 @@ def apply_pad_inner_list_at_axis(layout, depth, lateral_context, **kwargs): axes_to_flatten.reverse() new_layouts = [ - ak._do.recursively_apply( + recursively_apply( layout, apply_pad_inner_list_at_axis, lateral_context={"i": i}, diff --git a/src/awkward/operations/ak_categories.py b/src/awkward/operations/ak_categories.py index cd7f6ccf4c..4dbe407971 100644 --- a/src/awkward/operations/ak_categories.py +++ b/src/awkward/operations/ak_categories.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("categories",) @@ -49,6 +49,6 @@ def action(layout, **kwargs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - ak._do.recursively_apply(layout, action) + recursively_apply(layout, action) return ctx.wrap(output, highlevel=highlevel) diff --git a/src/awkward/operations/ak_combinations.py b/src/awkward/operations/ak_combinations.py index d22708cb4a..ed4e8d15b6 100644 --- a/src/awkward/operations/ak_combinations.py +++ b/src/awkward/operations/ak_combinations.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import combinations as do_combinations from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -225,7 +225,7 @@ def _impl( with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.combinations( + out = do_combinations( layout, n, replacement=replacement, diff --git a/src/awkward/operations/ak_concatenate.py b/src/awkward/operations/ak_concatenate.py index 18143b6840..2d1974099e 100644 --- a/src/awkward/operations/ak_concatenate.py +++ b/src/awkward/operations/ak_concatenate.py @@ -6,6 +6,8 @@ from awkward._backends.dispatch import backend_of_obj from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import mergemany +from awkward._do.meta import mergeable from awkward._layout import HighLevelContext, ensure_same_backend, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import unknown_length @@ -149,12 +151,12 @@ def _impl(arrays, axis, mergebool, highlevel, behavior, attrs): batches = [[content_or_others[0]]] for x in content_or_others[1:]: batch = batches[-1] - if ak._do.mergeable(batch[-1], x, mergebool=mergebool): + if mergeable(batch[-1], x, mergebool=mergebool): batch.append(x) else: batches.append([x]) - contents = [ak._do.mergemany(b) for b in batches] + contents = [mergemany(b) for b in batches] if len(contents) > 1: out = _merge_as_union(contents) else: diff --git a/src/awkward/operations/ak_drop_none.py b/src/awkward/operations/ak_drop_none.py index c6c06014db..08234d3342 100644 --- a/src/awkward/operations/ak_drop_none.py +++ b/src/awkward/operations/ak_drop_none.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -115,9 +115,9 @@ def action(layout, depth, **kwargs): return layout.drop_none() options = {"none_indexes": []} - out = ak._do.recursively_apply(layout, action, depth_context=options) + out = recursively_apply(layout, action, depth_context=options) if len(options["none_indexes"]) > 0: - out = ak._do.recursively_apply(out, recompute_offsets, depth_context=options) + out = recursively_apply(out, recompute_offsets, depth_context=options) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_enforce_type.py b/src/awkward/operations/ak_enforce_type.py index e207d46e47..6c002a9db5 100644 --- a/src/awkward/operations/ak_enforce_type.py +++ b/src/awkward/operations/ak_enforce_type.py @@ -7,6 +7,8 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import mergemany +from awkward._do.meta import mergeable from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import unknown_length @@ -942,8 +944,8 @@ def _recurse_union_non_union( # Merge the results for content in next_contents[1:]: - assert ak._do.mergeable(next_contents[0], content, mergebool=False) - next_content = ak._do.mergemany(next_contents) + assert mergeable(next_contents[0], content, mergebool=False) + next_content = mergemany(next_contents) # Index over them index = ak.index.Index64(index_data) diff --git a/src/awkward/operations/ak_fill_none.py b/src/awkward/operations/ak_fill_none.py index 739bed11a7..a1c4cf32d1 100644 --- a/src/awkward/operations/ak_fill_none.py +++ b/src/awkward/operations/ak_fill_none.py @@ -5,6 +5,8 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import fill_none as do_fill_none +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -107,7 +109,7 @@ def _impl(array, value, axis, highlevel, behavior, attrs): def action(layout, continuation, **kwargs): if layout.is_option: - return ak._do.fill_none(continuation(), value_layout) + return do_fill_none(continuation(), value_layout) else: @@ -115,7 +117,7 @@ def action(layout, depth, **kwargs): posaxis = maybe_posaxis(layout, axis, depth) if posaxis is not None and posaxis + 1 == depth: if layout.is_option: - return ak._do.fill_none(layout, value_layout) + return do_fill_none(layout, value_layout) elif layout.is_union or layout.is_record or layout.is_indexed: return None else: @@ -126,5 +128,5 @@ def action(layout, depth, **kwargs): f"axis={axis} exceeds the depth of this array ({depth})" ) - out = ak._do.recursively_apply(array_layout, action) + out = recursively_apply(array_layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_firsts.py b/src/awkward/operations/ak_firsts.py index 44e816b832..48e7b38f19 100644 --- a/src/awkward/operations/ak_firsts.py +++ b/src/awkward/operations/ak_firsts.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import is_integer, regularize_axis @@ -100,6 +101,6 @@ def action(layout, depth, backend, **kwargs): f"axis={axis} exceeds the depth of this array ({depth})" ) - out = ak._do.recursively_apply(layout, action, numpy_to_regular=True) + out = recursively_apply(layout, action, numpy_to_regular=True) return ctx.wrap(out, highlevel=highlevel, allow_other=True) diff --git a/src/awkward/operations/ak_flatten.py b/src/awkward/operations/ak_flatten.py index b246870463..da467f0806 100644 --- a/src/awkward/operations/ak_flatten.py +++ b/src/awkward/operations/ak_flatten.py @@ -4,6 +4,8 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import flatten as do_flatten +from awkward._do.content import mergemany, remove_structure from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -178,12 +180,12 @@ def _impl(array, axis, highlevel, behavior, attrs): layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") if axis is None: - out = ak._do.remove_structure(layout, function_name="ak.flatten") + out = remove_structure(layout, function_name="ak.flatten") assert isinstance(out, tuple) and all( isinstance(x, ak.contents.Content) for x in out ) - out = ak._do.mergemany(out) + out = mergemany(out) elif axis == 0 or maybe_posaxis(layout, axis, 1) == 0: @@ -233,5 +235,5 @@ def apply(layout): out = apply(layout) else: - out = ak._do.flatten(layout, axis) + out = do_flatten(layout, axis) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_from_arrow.py b/src/awkward/operations/ak_from_arrow.py index 460f09f5e4..9d08ebc0e4 100644 --- a/src/awkward/operations/ak_from_arrow.py +++ b/src/awkward/operations/ak_from_arrow.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -76,6 +77,6 @@ def remove_revertable(layout, **kwargs): if hasattr(layout, "__pyarrow_original"): del layout.__pyarrow_original - ak._do.recursively_apply(out, remove_revertable) + recursively_apply(out, remove_revertable) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_from_categorical.py b/src/awkward/operations/ak_from_categorical.py index 778bf4ca7f..50f20a1378 100644 --- a/src/awkward/operations/ak_from_categorical.py +++ b/src/awkward/operations/ak_from_categorical.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("from_categorical",) @@ -50,5 +51,5 @@ def action(layout, **kwargs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel, allow_other=True) diff --git a/src/awkward/operations/ak_from_json.py b/src/awkward/operations/ak_from_json.py index 5480d0952c..a883b97351 100644 --- a/src/awkward/operations/ak_from_json.py +++ b/src/awkward/operations/ak_from_json.py @@ -13,6 +13,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, wrap_layout from awkward._nplikes.numpy import Numpy from awkward._nplikes.numpy_like import NumpyMetadata @@ -419,7 +420,7 @@ def action(node, **kwargs): f"expected record with fields {complex_record_fields[0]!r} and {complex_record_fields[1]!r} to have integer or floating point types, not {str(real.form.type)!r} and {str(imag.form.type)!r}" ) - return ak._do.recursively_apply(layout, action) + return recursively_apply(layout, action) else: raise TypeError("complex_record_fields must be None or a pair of strings") diff --git a/src/awkward/operations/ak_from_regular.py b/src/awkward/operations/ak_from_regular.py index b3f840ef31..b547d07f30 100644 --- a/src/awkward/operations/ak_from_regular.py +++ b/src/awkward/operations/ak_from_regular.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -63,7 +63,7 @@ def action(layout, continuation, **kwargs): if layout.is_regular: return continuation().to_ListOffsetArray64(False) - out = ak._do.recursively_apply(layout, action, numpy_to_regular=True) + out = recursively_apply(layout, action, numpy_to_regular=True) elif maybe_posaxis(layout, axis, 1) == 0: out = layout # the top-level is already regular (ArrayType) @@ -81,6 +81,6 @@ def action(layout, depth, **kwargs): f"axis={axis} exceeds the depth of this array ({depth})" ) - out = ak._do.recursively_apply(layout, action, numpy_to_regular=True) + out = recursively_apply(layout, action, numpy_to_regular=True) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_full_like.py b/src/awkward/operations/ak_full_like.py index 8411f8ca98..bcdbbf37c0 100644 --- a/src/awkward/operations/ak_full_like.py +++ b/src/awkward/operations/ak_full_like.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.typetracer import is_unknown_scalar @@ -227,7 +228,7 @@ def action(layout, backend, **kwargs): else: return None - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_is_none.py b/src/awkward/operations/ak_is_none.py index 078c86bde6..0e96378f6b 100644 --- a/src/awkward/operations/ak_is_none.py +++ b/src/awkward/operations/ak_is_none.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import is_integer, regularize_axis @@ -66,6 +67,6 @@ def action(layout, depth, backend, lateral_context, **kwargs): elif layout.is_leaf: raise AxisError(f"axis={axis} exceeds the depth of this array ({depth})") - out = ak._do.recursively_apply(layout, action, numpy_to_regular=True) + out = recursively_apply(layout, action, numpy_to_regular=True) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_local_index.py b/src/awkward/operations/ak_local_index.py index 2231ac229f..cd33df6580 100644 --- a/src/awkward/operations/ak_local_index.py +++ b/src/awkward/operations/ak_local_index.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import local_index as do_local_index from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -91,5 +91,5 @@ def _impl(array, axis, highlevel, behavior, attrs): axis = regularize_axis(axis) with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.local_index(layout, axis) + out = do_local_index(layout, axis) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_merge_option_of_records.py b/src/awkward/operations/ak_merge_option_of_records.py index 80b6dfdfb2..e1482c94e3 100644 --- a/src/awkward/operations/ak_merge_option_of_records.py +++ b/src/awkward/operations/ak_merge_option_of_records.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -73,7 +74,7 @@ def apply_displace_index(layout, backend, **kwargs): backend=backend, ) - layout = ak._do.recursively_apply(layout, apply_displace_index) + layout = recursively_apply(layout, apply_displace_index) def apply(layout, depth, backend, **kwargs): posaxis = maybe_posaxis(layout, axis, depth) @@ -96,5 +97,5 @@ def apply(layout, depth, backend, **kwargs): backend=backend, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_merge_union_of_records.py b/src/awkward/operations/ak_merge_union_of_records.py index dd6dfe5b53..faf167e8ad 100644 --- a/src/awkward/operations/ak_merge_union_of_records.py +++ b/src/awkward/operations/ak_merge_union_of_records.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import ArrayLike, NumpyMetadata from awkward._regularize import regularize_axis @@ -265,5 +266,5 @@ def apply(layout, depth, backend, **kwargs): layout.tags.data, layout.index.data, layout.contents ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_nan_to_none.py b/src/awkward/operations/ak_nan_to_none.py index 7dabbfe828..97f3a0d8e3 100644 --- a/src/awkward/operations/ak_nan_to_none.py +++ b/src/awkward/operations/ak_nan_to_none.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -55,5 +56,5 @@ def action(layout, continuation, backend, **kwargs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_nan_to_num.py b/src/awkward/operations/ak_nan_to_num.py index 4c7472a06f..1f3d357d5c 100644 --- a/src/awkward/operations/ak_nan_to_num.py +++ b/src/awkward/operations/ak_nan_to_num.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend from awkward._nplikes.numpy_like import NumpyMetadata @@ -106,7 +107,7 @@ def action(layout, backend, **kwargs): else: return None - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) else: diff --git a/src/awkward/operations/ak_num.py b/src/awkward/operations/ak_num.py index ad9b4e746c..22f19f921d 100644 --- a/src/awkward/operations/ak_num.py +++ b/src/awkward/operations/ak_num.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import is_integer, regularize_axis @@ -107,6 +108,6 @@ def action(layout, depth, **kwargs): elif layout.is_leaf: raise AxisError(f"axis={axis} exceeds the depth of this array ({depth})") - out = ak._do.recursively_apply(layout, action, numpy_to_regular=True) + out = recursively_apply(layout, action, numpy_to_regular=True) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_pad_none.py b/src/awkward/operations/ak_pad_none.py index 34355a8546..ccd078bad8 100644 --- a/src/awkward/operations/ak_pad_none.py +++ b/src/awkward/operations/ak_pad_none.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import pad_none as do_pad_none from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -116,6 +116,6 @@ def _impl(array, target, axis, clip, highlevel, behavior, attrs): axis = regularize_axis(axis) with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.pad_none(layout, target, axis, clip=clip) + out = do_pad_none(layout, target, axis, clip=clip) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_ravel.py b/src/awkward/operations/ak_ravel.py index 66a3e3a55d..0a19a548e1 100644 --- a/src/awkward/operations/ak_ravel.py +++ b/src/awkward/operations/ak_ravel.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import mergemany, remove_structure from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -68,12 +69,12 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.remove_structure(layout, function_name="ak.ravel", drop_nones=False) + out = remove_structure(layout, function_name="ak.ravel", drop_nones=False) assert isinstance(out, tuple) and all( isinstance(x, ak.contents.Content) for x in out ) - result = ak._do.mergemany(out) + result = mergemany(out) return ctx.wrap(result, highlevel=highlevel) diff --git a/src/awkward/operations/ak_run_lengths.py b/src/awkward/operations/ak_run_lengths.py index ba5702ea54..2107f4ca82 100644 --- a/src/awkward/operations/ak_run_lengths.py +++ b/src/awkward/operations/ak_run_lengths.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import unknown_length @@ -225,5 +226,5 @@ def action(layout, **kwargs): else: return None - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_singletons.py b/src/awkward/operations/ak_singletons.py index 35f60d5c97..a53556c31b 100644 --- a/src/awkward/operations/ak_singletons.py +++ b/src/awkward/operations/ak_singletons.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import is_integer, regularize_axis @@ -88,6 +89,6 @@ def action(layout, depth, backend, **kwargs): elif layout.is_leaf: raise AxisError(f"axis={axis} exceeds the depth of this array ({depth})") - out = ak._do.recursively_apply(layout, action, numpy_to_regular=True) + out = recursively_apply(layout, action, numpy_to_regular=True) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_sort.py b/src/awkward/operations/ak_sort.py index 5e82e91604..5cbfa1e8c4 100644 --- a/src/awkward/operations/ak_sort.py +++ b/src/awkward/operations/ak_sort.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._connect.numpy import UNSUPPORTED from awkward._dispatch import high_level_function +from awkward._do.content import sort as do_sort from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -62,7 +63,7 @@ def _impl(array, axis, ascending, stable, highlevel, behavior, attrs): axis = regularize_axis(axis) with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.sort(layout, axis, ascending, stable) + out = do_sort(layout, axis, ascending, stable) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_strings_astype.py b/src/awkward/operations/ak_strings_astype.py index b0834db3a6..16ff6eeba0 100644 --- a/src/awkward/operations/ak_strings_astype.py +++ b/src/awkward/operations/ak_strings_astype.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy import Numpy from awkward._nplikes.numpy_like import NumpyMetadata @@ -82,5 +83,5 @@ def action(layout, **kwargs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_to_buffers.py b/src/awkward/operations/ak_to_buffers.py index 38853728e8..be5edadbe1 100644 --- a/src/awkward/operations/ak_to_buffers.py +++ b/src/awkward/operations/ak_to_buffers.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._backends.dispatch import regularize_backend from awkward._dispatch import high_level_function +from awkward._do.content import to_buffers as do_to_buffers from awkward._nplikes.numpy_like import NumpyMetadata __all__ = ("to_buffers",) @@ -139,7 +140,7 @@ def _impl(array, container, buffer_key, form_key, id_start, backend, byteorder): if backend is not None: backend = regularize_backend(backend) - return ak._do.to_buffers( + return do_to_buffers( layout, container=container, buffer_key=buffer_key, diff --git a/src/awkward/operations/ak_to_regular.py b/src/awkward/operations/ak_to_regular.py index b72e48d7c5..96e97e70bf 100644 --- a/src/awkward/operations/ak_to_regular.py +++ b/src/awkward/operations/ak_to_regular.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import regularize_axis @@ -76,7 +76,7 @@ def action(layout, continuation, **kwargs): if layout.is_list: return continuation().to_RegularArray() - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) elif maybe_posaxis(layout, axis, 1) == 0: out = layout # the top-level can only be regular (ArrayType) @@ -93,6 +93,6 @@ def action(layout, depth, **kwargs): f"axis={axis} exceeds the depth of this array ({depth})" ) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_transform.py b/src/awkward/operations/ak_transform.py index 23b4dbfd4e..2335203f82 100644 --- a/src/awkward/operations/ak_transform.py +++ b/src/awkward/operations/ak_transform.py @@ -529,7 +529,7 @@ def action(layout, **kwargs): f"transformation must return a Content or None, not {type(out)}\n\n{out!r}" ) - # An exception to the rule of ak._do.recursively_apply, for symmetry with + # An exception to the rule of recursively_apply, for symmetry with # ak._broadcasting.apply_step, below. ak_transform._impl knows implementation details. out = layouts[0]._recursively_apply( action, diff --git a/src/awkward/operations/ak_unflatten.py b/src/awkward/operations/ak_unflatten.py index f83479138f..e7a81b7ae0 100644 --- a/src/awkward/operations/ak_unflatten.py +++ b/src/awkward/operations/ak_unflatten.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend, maybe_posaxis from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import unknown_length @@ -245,7 +246,7 @@ def apply(layout, depth, backend, **kwargs): return ak.contents.ListOffsetArray(ak.index.Index64(positions), content) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) if ( current_offsets is not None diff --git a/src/awkward/operations/ak_unzip.py b/src/awkward/operations/ak_unzip.py index 8d0bfc229a..c7e824dfd7 100644 --- a/src/awkward/operations/ak_unzip.py +++ b/src/awkward/operations/ak_unzip.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -64,7 +65,7 @@ def check_for_union(layout, **kwargs): "union of different sets of fields, cannot ak.unzip" ) - ak._do.recursively_apply(layout, check_for_union, return_array=False) + recursively_apply(layout, check_for_union, return_array=False) if len(fields) == 0: return (ctx.wrap(layout, highlevel=highlevel, allow_other=True),) diff --git a/src/awkward/operations/ak_validity_error.py b/src/awkward/operations/ak_validity_error.py index 923a11101f..e6ae3dd54e 100644 --- a/src/awkward/operations/ak_validity_error.py +++ b/src/awkward/operations/ak_validity_error.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import validity_error as do_validity_error __all__ = ("validity_error",) @@ -35,7 +36,7 @@ def _impl(array, exception): layout = ak.operations.to_layout( array, allow_record=False, primitive_policy="error" ) - out = ak._do.validity_error(layout, path="highlevel") + out = do_validity_error(layout, path="highlevel") if out not in (None, "") and exception: raise ValueError(out) diff --git a/src/awkward/operations/ak_with_field.py b/src/awkward/operations/ak_with_field.py index 9998356be6..e3f6977f56 100644 --- a/src/awkward/operations/ak_with_field.py +++ b/src/awkward/operations/ak_with_field.py @@ -7,6 +7,7 @@ import awkward as ak from awkward._backends.numpy import NumpyBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend from awkward._nplikes.numpy_like import NumpyMetadata from awkward._regularize import is_non_string_like_sequence @@ -110,7 +111,7 @@ def action_is_record(input, **kwargs): else: return None - ak._do.recursively_apply(layout, action_is_record, return_array=False) + recursively_apply(layout, action_is_record, return_array=False) return result if not purelist_is_record(base): diff --git a/src/awkward/operations/ak_with_name.py b/src/awkward/operations/ak_with_name.py index 34a9e1cb89..32b07cd052 100644 --- a/src/awkward/operations/ak_with_name.py +++ b/src/awkward/operations/ak_with_name.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -60,6 +61,6 @@ def action(layout, **ignore): else: return None - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_without_field.py b/src/awkward/operations/ak_without_field.py index 2fc06da053..b0df5c2cef 100644 --- a/src/awkward/operations/ak_without_field.py +++ b/src/awkward/operations/ak_without_field.py @@ -6,6 +6,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -68,7 +69,7 @@ def action(layout, depth_context, **kwargs): for i, content in enumerate(layout.contents): if i == i_field: # Visit this content to remove the next item in `where` - next_content = ak._do.recursively_apply( + next_content = recursively_apply( content, action, depth_context={"where": next_where}, @@ -94,5 +95,5 @@ def action(layout, depth_context, **kwargs): else: return None - out = ak._do.recursively_apply(base, action, depth_context={"where": where}) + out = recursively_apply(base, action, depth_context={"where": where}) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/ak_without_parameters.py b/src/awkward/operations/ak_without_parameters.py index f414915a45..504b6fe1e6 100644 --- a/src/awkward/operations/ak_without_parameters.py +++ b/src/awkward/operations/ak_without_parameters.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -41,7 +41,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") - out = ak._do.recursively_apply( + out = recursively_apply( layout, lambda layout, **kwargs: None, keep_parameters=False ) diff --git a/src/awkward/operations/str/akstr_capitalize.py b/src/awkward/operations/str/akstr_capitalize.py index 3f62b50e67..4083b0fa22 100644 --- a/src/awkward/operations/str/akstr_capitalize.py +++ b/src/awkward/operations/str/akstr_capitalize.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("capitalize",) @@ -52,7 +53,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_capitalize, pc.ascii_capitalize, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_center.py b/src/awkward/operations/str/akstr_center.py index df98529a1b..f5ed95a3bc 100644 --- a/src/awkward/operations/str/akstr_center.py +++ b/src/awkward/operations/str/akstr_center.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("center",) @@ -58,7 +59,7 @@ def _impl(array, width, padding, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_center, pc.ascii_center, width, padding, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_count_substring.py b/src/awkward/operations/str/akstr_count_substring.py index 5e9074e5a3..e35bd82b56 100644 --- a/src/awkward/operations/str/akstr_count_substring.py +++ b/src/awkward/operations/str/akstr_count_substring.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("count_substring",) @@ -66,6 +67,6 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_count_substring_regex.py b/src/awkward/operations/str/akstr_count_substring_regex.py index 0540d6818d..ee34185663 100644 --- a/src/awkward/operations/str/akstr_count_substring_regex.py +++ b/src/awkward/operations/str/akstr_count_substring_regex.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("count_substring_regex",) @@ -66,6 +67,6 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_ends_with.py b/src/awkward/operations/str/akstr_ends_with.py index 3bfe4072ea..8b68fdc9fc 100644 --- a/src/awkward/operations/str/akstr_ends_with.py +++ b/src/awkward/operations/str/akstr_ends_with.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("ends_with",) @@ -64,5 +65,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_extract_regex.py b/src/awkward/operations/str/akstr_extract_regex.py index 769974a1cd..d2670ee208 100644 --- a/src/awkward/operations/str/akstr_extract_regex.py +++ b/src/awkward/operations/str/akstr_extract_regex.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("extract_regex",) @@ -69,7 +70,7 @@ def _impl(array, pattern, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.extract_regex, diff --git a/src/awkward/operations/str/akstr_find_substring.py b/src/awkward/operations/str/akstr_find_substring.py index b19059f308..5d73ef94e3 100644 --- a/src/awkward/operations/str/akstr_find_substring.py +++ b/src/awkward/operations/str/akstr_find_substring.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("find_substring",) @@ -66,5 +67,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_find_substring_regex.py b/src/awkward/operations/str/akstr_find_substring_regex.py index 1b630e2ea2..8516293a5d 100644 --- a/src/awkward/operations/str/akstr_find_substring_regex.py +++ b/src/awkward/operations/str/akstr_find_substring_regex.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("find_substring_regex",) @@ -66,5 +67,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_index_in.py b/src/awkward/operations/str/akstr_index_in.py index 11cbe09cef..35a90df8c0 100644 --- a/src/awkward/operations/str/akstr_index_in.py +++ b/src/awkward/operations/str/akstr_index_in.py @@ -2,9 +2,9 @@ from __future__ import annotations -import awkward as ak from awkward._backends.typetracer import TypeTracerBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend __all__ = ("index_in",) @@ -82,6 +82,6 @@ def apply(layout, **kwargs): generate_bitmasks=True, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_is_alnum.py b/src/awkward/operations/str/akstr_is_alnum.py index acfe71b590..57dd4caad9 100644 --- a/src/awkward/operations/str/akstr_is_alnum.py +++ b/src/awkward/operations/str/akstr_is_alnum.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_alnum",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_alnum, pc.ascii_is_alnum, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_alpha.py b/src/awkward/operations/str/akstr_is_alpha.py index bca754a613..c9a77c3df5 100644 --- a/src/awkward/operations/str/akstr_is_alpha.py +++ b/src/awkward/operations/str/akstr_is_alpha.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_alpha",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_alpha, pc.ascii_is_alpha, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_ascii.py b/src/awkward/operations/str/akstr_is_ascii.py index 8e2cbd5e75..4ec210ead8 100644 --- a/src/awkward/operations/str/akstr_is_ascii.py +++ b/src/awkward/operations/str/akstr_is_ascii.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_ascii",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.string_is_ascii, pc.string_is_ascii, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_decimal.py b/src/awkward/operations/str/akstr_is_decimal.py index 46e8746d6e..1ed231eca1 100644 --- a/src/awkward/operations/str/akstr_is_decimal.py +++ b/src/awkward/operations/str/akstr_is_decimal.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_decimal",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_decimal, pc.ascii_is_decimal, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_digit.py b/src/awkward/operations/str/akstr_is_digit.py index da1e605066..46e22bce98 100644 --- a/src/awkward/operations/str/akstr_is_digit.py +++ b/src/awkward/operations/str/akstr_is_digit.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_digit",) @@ -53,7 +54,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_digit, pc.utf8_is_digit, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_in.py b/src/awkward/operations/str/akstr_is_in.py index b44a698423..46adfc54e7 100644 --- a/src/awkward/operations/str/akstr_is_in.py +++ b/src/awkward/operations/str/akstr_is_in.py @@ -2,9 +2,9 @@ from __future__ import annotations -import awkward as ak from awkward._backends.typetracer import TypeTracerBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend __all__ = ("is_in",) @@ -76,6 +76,6 @@ def apply(layout, **kwargs): pc.is_in, layout, value_set_layout, skip_nulls=skip_nones ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_is_lower.py b/src/awkward/operations/str/akstr_is_lower.py index 2add221fe1..9fd92ecd29 100644 --- a/src/awkward/operations/str/akstr_is_lower.py +++ b/src/awkward/operations/str/akstr_is_lower.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_lower",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_lower, pc.ascii_is_lower, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_numeric.py b/src/awkward/operations/str/akstr_is_numeric.py index 1a3e2696d0..80a3bb02dc 100644 --- a/src/awkward/operations/str/akstr_is_numeric.py +++ b/src/awkward/operations/str/akstr_is_numeric.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_numeric",) @@ -53,7 +54,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_numeric, pc.utf8_is_numeric, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_printable.py b/src/awkward/operations/str/akstr_is_printable.py index 11e8d3006b..1f3bdacf73 100644 --- a/src/awkward/operations/str/akstr_is_printable.py +++ b/src/awkward/operations/str/akstr_is_printable.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_printable",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_printable, pc.ascii_is_printable, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_space.py b/src/awkward/operations/str/akstr_is_space.py index d5bc716029..b6ca337bd9 100644 --- a/src/awkward/operations/str/akstr_is_space.py +++ b/src/awkward/operations/str/akstr_is_space.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_space",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_space, pc.ascii_is_space, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_title.py b/src/awkward/operations/str/akstr_is_title.py index 84de708a31..bb9d8d906f 100644 --- a/src/awkward/operations/str/akstr_is_title.py +++ b/src/awkward/operations/str/akstr_is_title.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_title",) @@ -55,7 +56,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_title, pc.ascii_is_title, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_is_upper.py b/src/awkward/operations/str/akstr_is_upper.py index cbbfc72547..6c637b60ab 100644 --- a/src/awkward/operations/str/akstr_is_upper.py +++ b/src/awkward/operations/str/akstr_is_upper.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("is_upper",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_is_upper, diff --git a/src/awkward/operations/str/akstr_join.py b/src/awkward/operations/str/akstr_join.py index a5ab638ba5..6878a203e6 100644 --- a/src/awkward/operations/str/akstr_join.py +++ b/src/awkward/operations/str/akstr_join.py @@ -5,6 +5,7 @@ import awkward as ak from awkward._backends.typetracer import TypeTracerBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend __all__ = ("join",) @@ -94,7 +95,7 @@ def apply_unary(layout, **kwargs): bytestring_to32=True, ) - out = ak._do.recursively_apply(layout, apply_unary) + out = recursively_apply(layout, apply_unary) else: def apply_binary(layouts, **kwargs): diff --git a/src/awkward/operations/str/akstr_length.py b/src/awkward/operations/str/akstr_length.py index 690ff15a5a..6bf818f80d 100644 --- a/src/awkward/operations/str/akstr_length.py +++ b/src/awkward/operations/str/akstr_length.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("length",) @@ -50,7 +51,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_length, pc.binary_length, bytestring_to_string=False diff --git a/src/awkward/operations/str/akstr_lower.py b/src/awkward/operations/str/akstr_lower.py index 8c8dc44e3f..5d7b852fa5 100644 --- a/src/awkward/operations/str/akstr_lower.py +++ b/src/awkward/operations/str/akstr_lower.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("lower",) @@ -50,7 +51,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_lower, pc.ascii_lower, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_lpad.py b/src/awkward/operations/str/akstr_lpad.py index 8f0fe7f6e4..28af73052a 100644 --- a/src/awkward/operations/str/akstr_lpad.py +++ b/src/awkward/operations/str/akstr_lpad.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("lpad",) @@ -57,7 +58,7 @@ def _impl(array, width, padding, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_lpad, pc.ascii_lpad, width, padding, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_ltrim.py b/src/awkward/operations/str/akstr_ltrim.py index e6eaa4dcfa..b2887c5799 100644 --- a/src/awkward/operations/str/akstr_ltrim.py +++ b/src/awkward/operations/str/akstr_ltrim.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("ltrim",) @@ -58,7 +59,7 @@ def _impl(array, characters, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_ltrim, pc.ascii_ltrim, characters, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_ltrim_whitespace.py b/src/awkward/operations/str/akstr_ltrim_whitespace.py index dea616a4c7..f19c219069 100644 --- a/src/awkward/operations/str/akstr_ltrim_whitespace.py +++ b/src/awkward/operations/str/akstr_ltrim_whitespace.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("ltrim_whitespace",) @@ -49,7 +50,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_ltrim_whitespace, diff --git a/src/awkward/operations/str/akstr_match_like.py b/src/awkward/operations/str/akstr_match_like.py index 4680c85f62..1b3bfbd48c 100644 --- a/src/awkward/operations/str/akstr_match_like.py +++ b/src/awkward/operations/str/akstr_match_like.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("match_like",) @@ -69,5 +70,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_match_substring.py b/src/awkward/operations/str/akstr_match_substring.py index fe01d2c17f..dcdb29c9a9 100644 --- a/src/awkward/operations/str/akstr_match_substring.py +++ b/src/awkward/operations/str/akstr_match_substring.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("match_substring",) @@ -64,5 +65,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_match_substring_regex.py b/src/awkward/operations/str/akstr_match_substring_regex.py index 908e33b8bb..14bdc54265 100644 --- a/src/awkward/operations/str/akstr_match_substring_regex.py +++ b/src/awkward/operations/str/akstr_match_substring_regex.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("match_substring_regex",) @@ -64,5 +65,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_repeat.py b/src/awkward/operations/str/akstr_repeat.py index de929c57b7..7a88c267de 100644 --- a/src/awkward/operations/str/akstr_repeat.py +++ b/src/awkward/operations/str/akstr_repeat.py @@ -7,6 +7,7 @@ import awkward as ak from awkward._backends.typetracer import TypeTracerBackend from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext, ensure_same_backend from awkward._nplikes.numpy_like import NumpyMetadata @@ -96,6 +97,6 @@ def action(layout, **kwargs): ): return _apply_through_arrow(pc.binary_repeat, layout, num_repeats) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_replace_slice.py b/src/awkward/operations/str/akstr_replace_slice.py index c8e5cb98b4..706d79868c 100644 --- a/src/awkward/operations/str/akstr_replace_slice.py +++ b/src/awkward/operations/str/akstr_replace_slice.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("replace_slice",) @@ -60,7 +61,7 @@ def _impl(array, start, stop, replacement, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_replace_slice, pc.binary_replace_slice, start, stop, replacement diff --git a/src/awkward/operations/str/akstr_replace_substring.py b/src/awkward/operations/str/akstr_replace_substring.py index 41f2869389..f402f9013d 100644 --- a/src/awkward/operations/str/akstr_replace_substring.py +++ b/src/awkward/operations/str/akstr_replace_substring.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("replace_substring",) @@ -69,7 +70,7 @@ def _impl(array, pattern, replacement, max_replacements, highlevel, behavior, at with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.replace_substring, diff --git a/src/awkward/operations/str/akstr_replace_substring_regex.py b/src/awkward/operations/str/akstr_replace_substring_regex.py index cca19f1a28..f1e94cb5e6 100644 --- a/src/awkward/operations/str/akstr_replace_substring_regex.py +++ b/src/awkward/operations/str/akstr_replace_substring_regex.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("replace_substring_regex",) @@ -69,7 +70,7 @@ def _impl(array, pattern, replacement, max_replacements, highlevel, behavior, at with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.replace_substring_regex, diff --git a/src/awkward/operations/str/akstr_reverse.py b/src/awkward/operations/str/akstr_reverse.py index e29f59451a..b6b480964a 100644 --- a/src/awkward/operations/str/akstr_reverse.py +++ b/src/awkward/operations/str/akstr_reverse.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("reverse",) @@ -52,7 +53,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_reverse, pc.binary_reverse, bytestring_to_string=False diff --git a/src/awkward/operations/str/akstr_rpad.py b/src/awkward/operations/str/akstr_rpad.py index 6b6494c315..b4c9d76c98 100644 --- a/src/awkward/operations/str/akstr_rpad.py +++ b/src/awkward/operations/str/akstr_rpad.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("rpad",) @@ -58,7 +59,7 @@ def _impl(array, width, padding, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_rpad, pc.ascii_rpad, width, padding, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_rtrim.py b/src/awkward/operations/str/akstr_rtrim.py index 4d39f914b3..aaf7e25d3e 100644 --- a/src/awkward/operations/str/akstr_rtrim.py +++ b/src/awkward/operations/str/akstr_rtrim.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("rtrim",) @@ -57,7 +58,7 @@ def _impl(array, characters, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_rtrim, pc.ascii_rtrim, characters, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_rtrim_whitespace.py b/src/awkward/operations/str/akstr_rtrim_whitespace.py index 103207d31c..9140183cc5 100644 --- a/src/awkward/operations/str/akstr_rtrim_whitespace.py +++ b/src/awkward/operations/str/akstr_rtrim_whitespace.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("rtrim_whitespace",) @@ -49,7 +50,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_rtrim_whitespace, diff --git a/src/awkward/operations/str/akstr_slice.py b/src/awkward/operations/str/akstr_slice.py index 27c5b5063f..84ec97b468 100644 --- a/src/awkward/operations/str/akstr_slice.py +++ b/src/awkward/operations/str/akstr_slice.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("slice",) @@ -74,6 +74,6 @@ def action(layout, **absorb): primitive_policy="error", string_policy="as-characters", ) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_split_pattern.py b/src/awkward/operations/str/akstr_split_pattern.py index 07a086172c..8cabd42879 100644 --- a/src/awkward/operations/str/akstr_split_pattern.py +++ b/src/awkward/operations/str/akstr_split_pattern.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("split_pattern",) @@ -76,6 +77,6 @@ def _impl(array, pattern, max_splits, reverse, highlevel, behavior, attrs): reverse=reverse, bytestring_to_string=False, ) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_split_pattern_regex.py b/src/awkward/operations/str/akstr_split_pattern_regex.py index 161fe29125..39dfe90cb6 100644 --- a/src/awkward/operations/str/akstr_split_pattern_regex.py +++ b/src/awkward/operations/str/akstr_split_pattern_regex.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("split_pattern_regex",) @@ -80,6 +81,6 @@ def _impl(array, pattern, max_splits, reverse, highlevel, behavior, attrs): reverse=reverse, bytestring_to_string=False, ) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_split_whitespace.py b/src/awkward/operations/str/akstr_split_whitespace.py index b1a35c886f..8cb4138d67 100644 --- a/src/awkward/operations/str/akstr_split_whitespace.py +++ b/src/awkward/operations/str/akstr_split_whitespace.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("split_whitespace",) @@ -77,6 +78,6 @@ def _impl(array, max_splits, reverse, highlevel, behavior, attrs): reverse=reverse, bytestring_to_string=True, ) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_starts_with.py b/src/awkward/operations/str/akstr_starts_with.py index 18d2c59046..33433bc709 100644 --- a/src/awkward/operations/str/akstr_starts_with.py +++ b/src/awkward/operations/str/akstr_starts_with.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("starts_with",) @@ -64,5 +65,5 @@ def _impl(array, pattern, ignore_case, highlevel, behavior, attrs): ignore_case=ignore_case, pattern=pattern, ) - out = ak._do.recursively_apply(layout, apply) + out = recursively_apply(layout, apply) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_swapcase.py b/src/awkward/operations/str/akstr_swapcase.py index a3af83df86..004ad60d6a 100644 --- a/src/awkward/operations/str/akstr_swapcase.py +++ b/src/awkward/operations/str/akstr_swapcase.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("swapcase",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_swapcase, pc.ascii_swapcase, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_title.py b/src/awkward/operations/str/akstr_title.py index 8f4f4e06e9..56557ebcf0 100644 --- a/src/awkward/operations/str/akstr_title.py +++ b/src/awkward/operations/str/akstr_title.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("title",) @@ -53,7 +54,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_title, pc.ascii_title, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_to_categorical.py b/src/awkward/operations/str/akstr_to_categorical.py index c835394124..60b9a1d8f4 100644 --- a/src/awkward/operations/str/akstr_to_categorical.py +++ b/src/awkward/operations/str/akstr_to_categorical.py @@ -2,8 +2,8 @@ from __future__ import annotations -import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("to_categorical",) @@ -68,6 +68,6 @@ def action(layout, **kwargs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply(layout, action) + out = recursively_apply(layout, action) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/akstr_trim.py b/src/awkward/operations/str/akstr_trim.py index 7e29ec2f4e..a867226781 100644 --- a/src/awkward/operations/str/akstr_trim.py +++ b/src/awkward/operations/str/akstr_trim.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("trim",) @@ -58,7 +59,7 @@ def _impl(array, characters, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_trim, pc.ascii_trim, characters, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_trim_whitespace.py b/src/awkward/operations/str/akstr_trim_whitespace.py index 99eb529e1a..0caafe3e5d 100644 --- a/src/awkward/operations/str/akstr_trim_whitespace.py +++ b/src/awkward/operations/str/akstr_trim_whitespace.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("trim_whitespace",) @@ -50,7 +51,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_trim_whitespace, pc.ascii_trim_whitespace, bytestring_to_string=True diff --git a/src/awkward/operations/str/akstr_upper.py b/src/awkward/operations/str/akstr_upper.py index 68e1acccb2..3636825c87 100644 --- a/src/awkward/operations/str/akstr_upper.py +++ b/src/awkward/operations/str/akstr_upper.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import recursively_apply from awkward._layout import HighLevelContext __all__ = ("upper",) @@ -51,7 +52,7 @@ def _impl(array, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array) - out = ak._do.recursively_apply( + out = recursively_apply( layout, ak.operations.str._get_ufunc_action( pc.utf8_upper, pc.ascii_upper, bytestring_to_string=True diff --git a/src/awkward/record.py b/src/awkward/record.py index 7a4d529c41..6011510777 100644 --- a/src/awkward/record.py +++ b/src/awkward/record.py @@ -12,6 +12,7 @@ regularize_backend, ) from awkward._behavior import get_record_class +from awkward._do.content import validity_error as do_validity_error from awkward._layout import wrap_layout from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import unknown_length @@ -98,7 +99,7 @@ def _repr(self, indent, pre, post): return "".join(out) def validity_error(self, path="layout.array"): - return ak._do.validity_error(self._array, path) + return do_validity_error(self._array, path) @property def parameters(self): diff --git a/tests/test_0072_fillna_operation.py b/tests/test_0072_fillna_operation.py index 305531df95..b0335967f2 100644 --- a/tests/test_0072_fillna_operation.py +++ b/tests/test_0072_fillna_operation.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.content import fill_none, pad_none to_list = ak.operations.to_list @@ -15,30 +15,30 @@ def test_fillna_empty_array(): value = ak.contents.NumpyArray(np.array([10])) assert to_list(empty) == [] - array = ak._do.pad_none(empty, 5, 0) + array = pad_none(empty, 5, 0) assert to_list(array) == [None, None, None, None, None] - assert to_list(ak._do.fill_none(array, value)) == [10, 10, 10, 10, 10] + assert to_list(fill_none(array, value)) == [10, 10, 10, 10, 10] def test_fillna_numpy_array(): content = ak.contents.NumpyArray(np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]])) value = ak.contents.NumpyArray(np.array([0])) - array = ak._do.pad_none(content, 3, 0) + array = pad_none(content, 3, 0) assert to_list(array) == [[1.1, 2.2, 3.3], [4.4, 5.5, 6.6], None] - assert to_list(ak._do.fill_none(array, value)) == [ + assert to_list(fill_none(array, value)) == [ [1.1, 2.2, 3.3], [4.4, 5.5, 6.6], 0, ] - array = ak._do.pad_none(content, 5, 1) + array = pad_none(content, 5, 1) assert to_list(array) == [ [1.1, 2.2, 3.3, None, None], [4.4, 5.5, 6.6, None, None], ] - assert to_list(ak._do.fill_none(array, value)) == [ + assert to_list(fill_none(array, value)) == [ [1.1, 2.2, 3.3, 0, 0], [4.4, 5.5, 6.6, 0, 0], ] @@ -79,7 +79,7 @@ def test_fillna_regular_array(): assert to_list(regarray) == [[6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7]] - assert to_list(ak._do.fill_none(regarray, value)) == [ + assert to_list(fill_none(regarray, value)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, 666, 6.7], @@ -103,7 +103,7 @@ def test_fillna_listarray_array(): [8.8], ] - assert to_list(ak._do.fill_none(listarray, value)) == [ + assert to_list(fill_none(listarray, value)) == [ [0.0, 1.1, 2.2], [], [4.4, 5.5], @@ -121,7 +121,7 @@ def test_fillna_unionarray(): assert to_list(array) == [[], ["two", "two"], [1.1], ["one"], [2.2, 2.2], []] - padded_array = ak._do.pad_none(array, 2, 1) + padded_array = pad_none(array, 2, 1) assert to_list(padded_array) == [ [None, None], ["two", "two"], @@ -132,7 +132,7 @@ def test_fillna_unionarray(): ] value = ak.contents.NumpyArray(np.array([777])) - assert to_list(ak._do.fill_none(padded_array, value)) == [ + assert to_list(fill_none(padded_array, value)) == [ [777, 777], ["two", "two"], [1.1, 777], diff --git a/tests/test_0078_argcross_and_cross.py b/tests/test_0078_argcross_and_cross.py index a1076bfa26..3b49d630e6 100644 --- a/tests/test_0078_argcross_and_cross.py +++ b/tests/test_0078_argcross_and_cross.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.content import local_index to_list = ak.operations.to_list @@ -313,8 +313,8 @@ def test_localindex(): array = ak.operations.from_iter( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]], highlevel=False ) - assert to_list(ak._do.local_index(array, 0)) == [0, 1, 2, 3, 4] - assert to_list(ak._do.local_index(array, 1)) == [ + assert to_list(local_index(array, 0)) == [0, 1, 2, 3, 4] + assert to_list(local_index(array, 1)) == [ [0, 1, 2], [], [0, 1], @@ -326,9 +326,9 @@ def test_localindex(): [[[0.0, 1.1, 2.2], [], [3.3, 4.4]], [], [[5.5]], [[6.6, 7.7, 8.8, 9.9]]], highlevel=False, ) - assert to_list(ak._do.local_index(array, 0)) == [0, 1, 2, 3] - assert to_list(ak._do.local_index(array, 1)) == [[0, 1, 2], [], [0], [0]] - assert to_list(ak._do.local_index(array, 2)) == [ + assert to_list(local_index(array, 0)) == [0, 1, 2, 3] + assert to_list(local_index(array, 1)) == [[0, 1, 2], [], [0], [0]] + assert to_list(local_index(array, 2)) == [ [[0, 1, 2], [], [0, 1]], [], [[0]], @@ -338,9 +338,9 @@ def test_localindex(): array = ak.operations.from_numpy( np.arange(2 * 3 * 5).reshape(2, 3, 5), regulararray=True, highlevel=False ) - assert to_list(ak._do.local_index(array, 0)) == [0, 1] - assert to_list(ak._do.local_index(array, 1)) == [[0, 1, 2], [0, 1, 2]] - assert to_list(ak._do.local_index(array, 2)) == [ + assert to_list(local_index(array, 0)) == [0, 1] + assert to_list(local_index(array, 1)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(array, 2)) == [ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], ] diff --git a/tests/test_0080_flatpandas_multiindex_rows_and_columns.py b/tests/test_0080_flatpandas_multiindex_rows_and_columns.py index 2bc1828f83..507e5fdd7a 100644 --- a/tests/test_0080_flatpandas_multiindex_rows_and_columns.py +++ b/tests/test_0080_flatpandas_multiindex_rows_and_columns.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import json diff --git a/tests/test_0093_simplify_uniontypes_and_optiontypes.py b/tests/test_0093_simplify_uniontypes_and_optiontypes.py index f65a64d454..fab86eace9 100644 --- a/tests/test_0093_simplify_uniontypes_and_optiontypes.py +++ b/tests/test_0093_simplify_uniontypes_and_optiontypes.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.meta import mergeable to_list = ak.operations.to_list @@ -419,25 +419,25 @@ def test_recordarray_merge(): ) arrayt7 = ak.operations.from_iter([(0,), (1,), (2,)], highlevel=False) - assert ak._do.mergeable(arrayr1, arrayr2) - assert ak._do.mergeable(arrayr2, arrayr1) - assert not ak._do.mergeable(arrayr1, arrayr3) - assert ak._do.mergeable(arrayr1, arrayr4) - assert ak._do.mergeable(arrayr4, arrayr1) - assert not ak._do.mergeable(arrayr1, arrayr5) - assert not ak._do.mergeable(arrayr1, arrayr6) - assert ak._do.mergeable(arrayr5, arrayr6) - assert ak._do.mergeable(arrayr6, arrayr5) - assert not ak._do.mergeable(arrayr1, arrayr7) - - assert ak._do.mergeable(arrayt1, arrayt2) - assert ak._do.mergeable(arrayt2, arrayt1) - assert not ak._do.mergeable(arrayt1, arrayt3) - assert not ak._do.mergeable(arrayt1, arrayt4) - assert not ak._do.mergeable(arrayt1, arrayt5) - assert not ak._do.mergeable(arrayt1, arrayt6) - assert not ak._do.mergeable(arrayt5, arrayt6) - assert not ak._do.mergeable(arrayt1, arrayt7) + assert mergeable(arrayr1, arrayr2) + assert mergeable(arrayr2, arrayr1) + assert not mergeable(arrayr1, arrayr3) + assert mergeable(arrayr1, arrayr4) + assert mergeable(arrayr4, arrayr1) + assert not mergeable(arrayr1, arrayr5) + assert not mergeable(arrayr1, arrayr6) + assert mergeable(arrayr5, arrayr6) + assert mergeable(arrayr6, arrayr5) + assert not mergeable(arrayr1, arrayr7) + + assert mergeable(arrayt1, arrayt2) + assert mergeable(arrayt2, arrayt1) + assert not mergeable(arrayt1, arrayt3) + assert not mergeable(arrayt1, arrayt4) + assert not mergeable(arrayt1, arrayt5) + assert not mergeable(arrayt1, arrayt6) + assert not mergeable(arrayt5, arrayt6) + assert not mergeable(arrayt1, arrayt7) assert to_list(arrayr1._mergemany([arrayr2])) == [ {"x": 0.0, "y": []}, diff --git a/tests/test_0127_tomask_operation.py b/tests/test_0127_tomask_operation.py index f84d278b5d..c93f23ea84 100644 --- a/tests/test_0127_tomask_operation.py +++ b/tests/test_0127_tomask_operation.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.content import local_index to_list = ak.operations.to_list @@ -720,30 +720,30 @@ def test_ByteMaskedArray_localindex(): None, [[], [10.0, 11.1, 12.2]], ] - assert to_list(ak._do.local_index(array, axis=0)) == [0, 1, 2, 3, 4] - assert to_list(ak._do.local_index(array, axis=-3)) == [0, 1, 2, 3, 4] - assert to_list(ak._do.local_index(array, axis=1)) == [ + assert to_list(local_index(array, axis=0)) == [0, 1, 2, 3, 4] + assert to_list(local_index(array, axis=-3)) == [0, 1, 2, 3, 4] + assert to_list(local_index(array, axis=1)) == [ [0, 1, 2], [], None, None, [0, 1], ] - assert to_list(ak._do.local_index(array, axis=-2)) == [ + assert to_list(local_index(array, axis=-2)) == [ [0, 1, 2], [], None, None, [0, 1], ] - assert to_list(ak._do.local_index(array, axis=2)) == [ + assert to_list(local_index(array, axis=2)) == [ [[0, 1, 2], [], [0, 1]], [], None, None, [[], [0, 1, 2]], ] - assert to_list(ak._do.local_index(array, axis=-1)) == [ + assert to_list(local_index(array, axis=-1)) == [ [[0, 1, 2], [], [0, 1]], [], None, diff --git a/tests/test_0150_flatten.py b/tests/test_0150_flatten.py index 72e20dc17b..7bd529f80b 100644 --- a/tests/test_0150_flatten.py +++ b/tests/test_0150_flatten.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest import awkward as ak +from awkward._do.content import flatten to_list = ak.operations.to_list @@ -446,7 +446,7 @@ def test_flatten2(): [5.5], [6.6, 7.7, 8.8, 9.9], ] - assert to_list(ak._do.flatten(array, axis=1)) == [ + assert to_list(flatten(array, axis=1)) == [ 0.0, 1.1, 2.2, @@ -458,7 +458,7 @@ def test_flatten2(): 8.8, 9.9, ] - assert to_list(ak._do.flatten(array, axis=-1)) == [ + assert to_list(flatten(array, axis=-1)) == [ 0.0, 1.1, 2.2, @@ -471,12 +471,12 @@ def test_flatten2(): 9.9, ] with pytest.raises(ValueError) as err: - assert to_list(ak._do.flatten(array, axis=-2)) + assert to_list(flatten(array, axis=-2)) assert str(err.value).startswith("axis=0 not allowed for flatten") array2 = array[2:-1] - assert to_list(ak._do.flatten(array2, axis=1)) == [3.3, 4.4, 5.5] - assert to_list(ak._do.flatten(array2, axis=-1)) == [3.3, 4.4, 5.5] + assert to_list(flatten(array2, axis=1)) == [3.3, 4.4, 5.5] + assert to_list(flatten(array2, axis=-1)) == [3.3, 4.4, 5.5] def test_ByteMaskedArray_flatten(): diff --git a/tests/test_0184_concatenate_operation.py b/tests/test_0184_concatenate_operation.py index 893ff2d872..d1a286f657 100644 --- a/tests/test_0184_concatenate_operation.py +++ b/tests/test_0184_concatenate_operation.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest import awkward as ak +from awkward._do.content import pad_none to_list = ak.operations.to_list @@ -66,7 +66,7 @@ def test_list_offset_array_concatenate(): three = ak.contents.ListOffsetArray(offsets_three, one) four = ak.contents.ListOffsetArray(offsets_four, two) - padded_one = ak._do.pad_none(one, 7, 0) + padded_one = pad_none(one, 7, 0) assert to_list(padded_one) == [ [0.0, 1.1, 2.2], [], @@ -117,7 +117,7 @@ def test_list_offset_array_concatenate(): [], ] - padded = ak._do.pad_none(three, 6, 0) + padded = pad_none(three, 6, 0) assert to_list(ak.operations.concatenate([padded, four], 1)) == [ [[0.0, 1.1, 2.2], [], [3.3, 4.4], [0.33], []], diff --git a/tests/test_0397_arrays_as_constants_in_numba.py b/tests/test_0397_arrays_as_constants_in_numba.py index 1b57684a66..234be8c0e2 100644 --- a/tests/test_0397_arrays_as_constants_in_numba.py +++ b/tests/test_0397_arrays_as_constants_in_numba.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import sys diff --git a/tests/test_0404_array_validity_check.py b/tests/test_0404_array_validity_check.py index 78f2336d17..62b7f0d153 100644 --- a/tests/test_0404_array_validity_check.py +++ b/tests/test_0404_array_validity_check.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/master/LICENSE - from __future__ import annotations import numpy as np import pytest import awkward as ak +from awkward._do.content import is_unique, unique to_list = ak.operations.to_list @@ -76,9 +76,9 @@ def test_BitMaskedArray(): None, None, ] - assert ak._do.is_unique(array, axis=None) is True - assert to_list(ak._do.unique(array, axis=None)) == [0, 1, 5, 7, 8, 9, None] - assert to_list(ak._do.unique(array, axis=-1)) == [0, 1, 5, 7, 8, 9, None] + assert is_unique(array, axis=None) is True + assert to_list(unique(array, axis=None)) == [0, 1, 5, 7, 8, 9, None] + assert to_list(unique(array, axis=-1)) == [0, 1, 5, 7, 8, 9, None] def test_ByteMaskedArray_0(): @@ -88,8 +88,8 @@ def test_ByteMaskedArray_0(): mask = ak.index.Index8(np.array([0, 0, 1, 1, 0], dtype=np.int8)) array = ak.contents.ByteMaskedArray(mask, content, valid_when=False) assert to_list(array) == [[0.0, 1.1, 2.2], [], None, None, [6.6, 7.7, 8.8, 9.9]] - assert ak._do.is_unique(array, axis=None) is True - assert to_list(ak._do.unique(array, axis=None)) == [ + assert is_unique(array, axis=None) is True + assert to_list(unique(array, axis=None)) == [ 0.0, 1.1, 2.2, @@ -99,7 +99,7 @@ def test_ByteMaskedArray_0(): 9.9, None, ] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert to_list(unique(array, axis=-1)) == [ [0.0, 1.1, 2.2], [], [6.6, 7.7, 8.8, 9.9], @@ -116,8 +116,8 @@ def test_ByteMaskedArray_1(): array = ak.contents.ByteMaskedArray(mask, content, valid_when=False) assert to_list(array) == [[0.0, 1.1, 2.2], [], None, None, [6.6, 7.7, 8.8, 9.9]] - assert ak._do.is_unique(array, axis=None) is True - assert to_list(ak._do.unique(array, axis=None)) == [ + assert is_unique(array, axis=None) is True + assert to_list(unique(array, axis=None)) == [ 0.0, 1.1, 2.2, @@ -127,7 +127,7 @@ def test_ByteMaskedArray_1(): 9.9, None, ] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert to_list(unique(array, axis=-1)) == [ [0.0, 1.1, 2.2], [], [6.6, 7.7, 8.8, 9.9], @@ -144,9 +144,9 @@ def test_ByteMaskedArray_2(): array = ak.contents.ByteMaskedArray(mask, content, valid_when=False) assert to_list(array) == [[1.1, 1.1, 2.2], [], None, None, [1.1, 7.7, 8.8, 9.9]] - assert ak._do.is_unique(array, axis=None) is False - assert to_list(ak._do.unique(array, axis=None)) == [1.1, 2.2, 7.7, 8.8, 9.9, None] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert is_unique(array, axis=None) is False + assert to_list(unique(array, axis=None)) == [1.1, 2.2, 7.7, 8.8, 9.9, None] + assert to_list(unique(array, axis=-1)) == [ [1.1, 2.2], [], [1.1, 7.7, 8.8, 9.9], @@ -162,8 +162,8 @@ def test_UnmaskedArray(): array = ak.contents.UnmaskedArray(content) assert to_list(array) == [1.1, 2.2, 3.3, 4.4, 5.5] - assert ak._do.is_unique(array, axis=None) is True - assert to_list(ak._do.unique(array, axis=None)) == [1.1, 2.2, 3.3, 4.4, 5.5] + assert is_unique(array, axis=None) is True + assert to_list(unique(array, axis=None)) == [1.1, 2.2, 3.3, 4.4, 5.5] def test_subranges_equal(): @@ -220,14 +220,14 @@ def test_categorical(): categorical = ak.str.to_categorical(array) assert ak.operations.is_valid(categorical) is True - assert ak._do.is_unique(categorical.layout) is False + assert is_unique(categorical.layout) is False def test_NumpyArray(): array = ak.contents.NumpyArray(np.array([5, 6, 1, 3, 4, 5])) - assert ak._do.is_unique(array) is False - assert to_list(ak._do.unique(array)) == [1, 3, 4, 5, 6] + assert is_unique(array) is False + assert to_list(unique(array)) == [1, 3, 4, 5, 6] def test_2d(): @@ -272,15 +272,15 @@ def test_2d(): ) assert ( - ak._do.is_unique( + is_unique( array, ) is False ) - assert ak._do.is_unique(array, axis=-1) is True + assert is_unique(array, axis=-1) is True - assert to_list(ak._do.unique(array)) == [1.1, 2.2, 3.3, 4.4, 5.5] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert to_list(unique(array)) == [1.1, 2.2, 3.3, 4.4, 5.5] + assert to_list(unique(array, axis=-1)) == [ [1.1, 2.2, 3.3, 4.4, 5.5], [1.1, 2.2, 3.3, 4.4, 5.5], [1.1, 2.2, 3.3, 4.4, 5.5], @@ -297,15 +297,15 @@ def test_2d_in_axis(): ] ) ) - assert ak._do.is_unique(array) is False - assert to_list(ak._do.unique(array)) == [1.1, 2.2, 3.3, 4.4, 5.5] + assert is_unique(array) is False + assert to_list(unique(array)) == [1.1, 2.2, 3.3, 4.4, 5.5] assert to_list(ak.sort(array, axis=-1, highlevel=False)) == [ [1.1, 1.1, 2.2, 3.3, 4.4, 5.5], [1.1, 2.2, 3.3, 3.3, 4.4, 5.5], [1.1, 2.2, 2.2, 3.3, 4.4, 5.5], ] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert to_list(unique(array, axis=-1)) == [ [1.1, 2.2, 3.3, 4.4, 5.5], [1.1, 2.2, 3.3, 4.4, 5.5], [1.1, 2.2, 3.3, 4.4, 5.5], @@ -331,9 +331,9 @@ def test_3d(): ) ) # 5 - assert ak._do.is_unique(array) is True + assert is_unique(array) is True - assert to_list(ak._do.unique(array)) == [ + assert to_list(unique(array)) == [ -15.15, -14.14, -13.13, @@ -366,7 +366,7 @@ def test_3d(): 15.15, ] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert to_list(unique(array, axis=-1)) == [ [ [1.1, 2.2, 3.3, 4.4, 5.5], [6.6, 7.7, 8.8, 9.9, 10.1], @@ -398,8 +398,8 @@ def test_3d_non_unique(): array = ak.contents.NumpyArray(np_array) - assert to_list(ak._do.unique(array)) == to_list(np.unique(np_array)) - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert to_list(unique(array)) == to_list(np.unique(np_array)) + assert to_list(unique(array, axis=-1)) == [ [[1.1, 4.4, 5.5, 13.13], [7.7, 10.1, 13.13], [12.12, 13.13]], [ [-5.5, -4.4, -2.2, -1.1, 13.13], @@ -421,8 +421,8 @@ def test_ListOffsetArray(): "three", "two", ] - assert ak._do.is_unique(array) is True - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert is_unique(array) is True + assert to_list(unique(array, axis=-1)) == [ "five", "four", "one", @@ -440,8 +440,8 @@ def test_ListOffsetArray(): "two", "two", ] - assert ak._do.is_unique(array2) is False - assert to_list(ak._do.unique(array2, axis=-1)) == [ + assert is_unique(array2) is False + assert to_list(unique(array2, axis=-1)) == [ "four", "one", "two", @@ -461,8 +461,8 @@ def test_ListOffsetArray(): [6.6, 7.7, 8.8, 5.5], [], ] - assert ak._do.is_unique(listoffsetarray) is True - assert to_list(ak._do.unique(listoffsetarray, axis=-1)) == [ + assert is_unique(listoffsetarray) is True + assert to_list(unique(listoffsetarray, axis=-1)) == [ [1.1, 2.2, 3.3], [], [0.0, 4.4], @@ -470,7 +470,7 @@ def test_ListOffsetArray(): [5.5, 6.6, 7.7, 8.8], [], ] - assert to_list(ak._do.unique(listoffsetarray)) == [ + assert to_list(unique(listoffsetarray)) == [ 0.0, 1.1, 2.2, @@ -497,8 +497,8 @@ def test_ListOffsetArray(): [2.2, 3.3, 1.1], [5.5], ] - assert ak._do.is_unique(listoffsetarray) is False - assert to_list(ak._do.unique(listoffsetarray, axis=-1)) == [ + assert is_unique(listoffsetarray) is False + assert to_list(unique(listoffsetarray, axis=-1)) == [ [1.1, 2.2, 3.3], [], [0.0, 4.4], @@ -520,8 +520,8 @@ def test_ListOffsetArray(): [9.9], [5.5], ] - assert ak._do.is_unique(listoffsetarray1) is False - assert to_list(ak._do.unique(listoffsetarray1, axis=-1)) == [ + assert is_unique(listoffsetarray1) is False + assert to_list(unique(listoffsetarray1, axis=-1)) == [ [1.1, 2.2, 3.3], [1.1, 2.2, 3.3], [], @@ -544,8 +544,8 @@ def test_ListOffsetArray(): [5.5], [5.5], ] - assert ak._do.is_unique(listoffsetarray2) is False - assert to_list(ak._do.unique(listoffsetarray2, axis=-1)) == [ + assert is_unique(listoffsetarray2) is False + assert to_list(unique(listoffsetarray2, axis=-1)) == [ [1.1, 2.2, 3.3], [1.1, 2.2, 3.3], [], @@ -576,8 +576,8 @@ def test_ListOffsetArray(): [2.2, 6.6, 7.7, 9.9], [], ] - assert ak._do.is_unique(listoffsetarray2, axis=-1) is True - assert to_list(ak._do.unique(listoffsetarray2, axis=-1)) == [ + assert is_unique(listoffsetarray2, axis=-1) is True + assert to_list(unique(listoffsetarray2, axis=-1)) == [ [0.0, 1.1, 2.2], [], [1.1, 3.3], @@ -604,8 +604,8 @@ def test_ListOffsetArray(): [], [], ] - assert ak._do.is_unique(listoffsetarray) is True - assert to_list(ak._do.unique(listoffsetarray, axis=-1)) == [ + assert is_unique(listoffsetarray) is True + assert to_list(unique(listoffsetarray, axis=-1)) == [ [], [], [], @@ -657,14 +657,14 @@ def test_RegularArray(): [2.2, 1.5, 1.6], [3.6, None, 6.7], ] - assert ak._do.is_unique(regular_array) is False - assert to_list(ak._do.unique(regular_array, axis=-1)) == [ + assert is_unique(regular_array) is False + assert to_list(unique(regular_array, axis=-1)) == [ [3.9, 6.9], [1.5, 1.6, 2.2], [3.6, 6.7, None], ] - assert to_list(ak._do.unique(regular_array, axis=None)) == [ + assert to_list(unique(regular_array, axis=None)) == [ 1.5, 1.6, 2.2, @@ -685,8 +685,8 @@ def test_RegularArray(): [3.9, 6.9, 6.9], [None, None, None], ] - assert ak._do.is_unique(regular_array2) is False - assert to_list(ak._do.unique(regular_array2, axis=None)) == [3.9, 6.9, None] + assert is_unique(regular_array2) is False + assert to_list(unique(regular_array2, axis=None)) == [3.9, 6.9, None] def test_IndexedArray(): @@ -696,7 +696,7 @@ def test_IndexedArray(): index = ak.index.Index64(np.array([4, 3, 2, 1, 0], dtype=np.int64)) indexedarray = ak.contents.IndexedArray(index, content) - assert ak._do.is_unique(indexedarray) is True + assert is_unique(indexedarray) is True listoffsetarray = ak.operations.from_iter( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]], highlevel=False @@ -711,10 +711,10 @@ def test_IndexedArray(): [], [0.0, 1.1, 2.2], ] - assert ak._do.is_unique(indexedarray) is True + assert is_unique(indexedarray) is True - assert ak._do.is_unique(indexedarray) is True - assert to_list(ak._do.unique(indexedarray)) == [ + assert is_unique(indexedarray) is True + assert to_list(unique(indexedarray)) == [ 0.0, 1.1, 2.2, @@ -726,7 +726,7 @@ def test_IndexedArray(): 8.8, 9.9, ] - assert to_list(ak._do.unique(indexedarray, axis=-1)) == [ + assert to_list(unique(indexedarray, axis=-1)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -744,9 +744,9 @@ def test_IndexedArray(): None, [0.0, 1.1, 2.2], ] - assert ak._do.is_unique(indexedarray) is False - assert ak._do.is_unique(indexedarray, axis=-1) is True - assert to_list(ak._do.unique(indexedarray, axis=-1)) == [ + assert is_unique(indexedarray) is False + assert is_unique(indexedarray, axis=-1) is True + assert to_list(unique(indexedarray, axis=-1)) == [ [6.6, 7.7, 8.8, 9.9], [6.6, 7.7, 8.8, 9.9], [5.5], @@ -771,9 +771,9 @@ def test_RecordArray(): ] ) - assert ak._do.is_unique(array.layout) is False - assert ak._do.is_unique(array["x"].layout) is True - assert ak._do.is_unique(array["y"].layout) is False + assert is_unique(array.layout) is False + assert is_unique(array["x"].layout) is True + assert is_unique(array["y"].layout) is False def test_same_categories(): @@ -799,9 +799,9 @@ def test_same_categories(): "two", "two", ] - assert ak._do.is_unique(categorical1) is False - assert ak._do.is_unique(categorical1.content) is True - assert ak._do.is_unique(categorical2) is False + assert is_unique(categorical1) is False + assert is_unique(categorical1.content) is True + assert is_unique(categorical2) is False assert to_list(array1) == [ "one", @@ -856,9 +856,9 @@ def test_UnionArray(): [3, 3, 3], [], ] - assert ak._do.is_unique(array) is False - assert to_list(ak._do.unique(array, axis=None)) == [1.0, 1.1, 2.0, 2.2, 3.0, 3.3] - assert to_list(ak._do.unique(array, axis=-1)) == [ + assert is_unique(array) is False + assert to_list(unique(array, axis=None)) == [1.0, 1.1, 2.0, 2.2, 3.0, 3.3] + assert to_list(unique(array, axis=-1)) == [ [], [3.3], [1.0], diff --git a/tests/test_1059_localindex.py b/tests/test_1059_localindex.py index 2d47d90ea1..b6e01b0430 100644 --- a/tests/test_1059_localindex.py +++ b/tests/test_1059_localindex.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest import awkward as ak +from awkward._do.content import local_index to_list = ak.operations.to_list @@ -14,12 +14,11 @@ def test_listoffsetarray_localindex(): v2_array = ak.operations.from_iter( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]], highlevel=False ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [ + assert to_list(local_index(v2_array, 1)) == [ [0, 1, 2], [], [0, 1], @@ -27,10 +26,9 @@ def test_listoffsetarray_localindex(): [0, 1, 2, 3], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ [0, 1, 2], [], [0, 1], @@ -38,141 +36,124 @@ def test_listoffsetarray_localindex(): [0, 1, 2, 3], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, -2)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -3) + local_index(v2_array, -3) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 2) + local_index(v2_array, 2) v2_array = ak.operations.from_iter( [[[0.0, 1.1, 2.2], [], [3.3, 4.4]], [], [[5.5]], [[6.6, 7.7, 8.8, 9.9]]], highlevel=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [[0, 1, 2], [], [0], [0]] + assert to_list(local_index(v2_array, 1)) == [[0, 1, 2], [], [0], [0]] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, 2)) == [ + assert to_list(local_index(v2_array, 2)) == [ [[0, 1, 2], [], [0, 1]], [], [[0]], [[0, 1, 2, 3]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 2).form - == ak._do.local_index(v2_array, 2).form + local_index(v2_array.to_typetracer(), 2).form == local_index(v2_array, 2).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ [[0, 1, 2], [], [0, 1]], [], [[0]], [[0, 1, 2, 3]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [[0, 1, 2], [], [0], [0]] + assert to_list(local_index(v2_array, -2)) == [[0, 1, 2], [], [0], [0]] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) - assert to_list(ak._do.local_index(v2_array, -3)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, -3)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), -3).form - == ak._do.local_index(v2_array, -3).form + local_index(v2_array.to_typetracer(), -3).form == local_index(v2_array, -3).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -4) + local_index(v2_array, -4) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 3) + local_index(v2_array, 3) def test_regulararray_localindex(): v2_array = ak.operations.from_numpy( np.arange(2 * 3 * 5).reshape(2, 3, 5), regulararray=True, highlevel=False ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1] + assert to_list(local_index(v2_array, 0)) == [0, 1] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(v2_array, 1)) == [[0, 1, 2], [0, 1, 2]] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, 2)) == [ + assert to_list(local_index(v2_array, 2)) == [ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 2).form - == ak._do.local_index(v2_array, 2).form + local_index(v2_array.to_typetracer(), 2).form == local_index(v2_array, 2).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(v2_array, -2)) == [[0, 1, 2], [0, 1, 2]] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) - assert to_list(ak._do.local_index(v2_array, -3)) == [0, 1] + assert to_list(local_index(v2_array, -3)) == [0, 1] assert ( - ak._do.local_index(v2_array.to_typetracer(), -3).form - == ak._do.local_index(v2_array, -3).form + local_index(v2_array.to_typetracer(), -3).form == local_index(v2_array, -3).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -4) + local_index(v2_array, -4) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 3) + local_index(v2_array, 3) v2_array = ak.operations.from_numpy( np.arange(2 * 3 * 5 * 10).reshape(2, 3, 5, 10), regulararray=True, highlevel=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1] + assert to_list(local_index(v2_array, 0)) == [0, 1] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(v2_array, 1)) == [[0, 1, 2], [0, 1, 2]] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, 2)) == [ + assert to_list(local_index(v2_array, 2)) == [ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 2).form - == ak._do.local_index(v2_array, 2).form + local_index(v2_array.to_typetracer(), 2).form == local_index(v2_array, 2).form ) - assert to_list(ak._do.local_index(v2_array, 3)) == [ + assert to_list(local_index(v2_array, 3)) == [ [ [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], @@ -221,10 +202,9 @@ def test_regulararray_localindex(): ], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 3).form - == ak._do.local_index(v2_array, 3).form + local_index(v2_array.to_typetracer(), 3).form == local_index(v2_array, 3).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ [ [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], @@ -273,32 +253,28 @@ def test_regulararray_localindex(): ], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [ + assert to_list(local_index(v2_array, -2)) == [ [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) - assert to_list(ak._do.local_index(v2_array, -3)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(v2_array, -3)) == [[0, 1, 2], [0, 1, 2]] assert ( - ak._do.local_index(v2_array.to_typetracer(), -3).form - == ak._do.local_index(v2_array, -3).form + local_index(v2_array.to_typetracer(), -3).form == local_index(v2_array, -3).form ) - assert to_list(ak._do.local_index(v2_array, -4)) == [0, 1] + assert to_list(local_index(v2_array, -4)) == [0, 1] assert ( - ak._do.local_index(v2_array.to_typetracer(), -4).form - == ak._do.local_index(v2_array, -4).form + local_index(v2_array.to_typetracer(), -4).form == local_index(v2_array, -4).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -5) + local_index(v2_array, -5) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 4) + local_index(v2_array, 4) v2_array = ak.highlevel.Array( ak.contents.RegularArray( @@ -306,41 +282,35 @@ def test_regulararray_localindex(): ) ).layout - assert to_list(ak._do.local_index(v2_array, 0)) == [] + assert to_list(local_index(v2_array, 0)) == [] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [] + assert to_list(local_index(v2_array, 1)) == [] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, 2)) == [] + assert to_list(local_index(v2_array, 2)) == [] assert ( - ak._do.local_index(v2_array.to_typetracer(), 2).form - == ak._do.local_index(v2_array, 2).form + local_index(v2_array.to_typetracer(), 2).form == local_index(v2_array, 2).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [] + assert to_list(local_index(v2_array, -1)) == [] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [] + assert to_list(local_index(v2_array, -2)) == [] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) - assert to_list(ak._do.local_index(v2_array, -3)) == [] + assert to_list(local_index(v2_array, -3)) == [] assert ( - ak._do.local_index(v2_array.to_typetracer(), -3).form - == ak._do.local_index(v2_array, -3).form + local_index(v2_array.to_typetracer(), -3).form == local_index(v2_array, -3).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -4) + local_index(v2_array, -4) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 3) + local_index(v2_array, 3) def test_bytemaskedarray_localindex(): @@ -364,17 +334,17 @@ def test_bytemaskedarray_localindex(): None, [[], [10.0, 11.1, 12.2]], ] - assert to_list(ak._do.local_index(v2_array, axis=0)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, axis=0)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=0).form - == ak._do.local_index(v2_array, axis=0).form + local_index(v2_array.to_typetracer(), axis=0).form + == local_index(v2_array, axis=0).form ) - assert to_list(ak._do.local_index(v2_array, axis=-3)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, axis=-3)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=-3).form - == ak._do.local_index(v2_array, axis=-3).form + local_index(v2_array.to_typetracer(), axis=-3).form + == local_index(v2_array, axis=-3).form ) - assert to_list(ak._do.local_index(v2_array, axis=1)) == [ + assert to_list(local_index(v2_array, axis=1)) == [ [0, 1, 2], [], None, @@ -382,10 +352,10 @@ def test_bytemaskedarray_localindex(): [0, 1], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=1).form - == ak._do.local_index(v2_array, axis=1).form + local_index(v2_array.to_typetracer(), axis=1).form + == local_index(v2_array, axis=1).form ) - assert to_list(ak._do.local_index(v2_array, axis=-2)) == [ + assert to_list(local_index(v2_array, axis=-2)) == [ [0, 1, 2], [], None, @@ -393,10 +363,10 @@ def test_bytemaskedarray_localindex(): [0, 1], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=-2).form - == ak._do.local_index(v2_array, axis=-2).form + local_index(v2_array.to_typetracer(), axis=-2).form + == local_index(v2_array, axis=-2).form ) - assert to_list(ak._do.local_index(v2_array, axis=2)) == [ + assert to_list(local_index(v2_array, axis=2)) == [ [[0, 1, 2], [], [0, 1]], [], None, @@ -404,10 +374,10 @@ def test_bytemaskedarray_localindex(): [[], [0, 1, 2]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=2).form - == ak._do.local_index(v2_array, axis=2).form + local_index(v2_array.to_typetracer(), axis=2).form + == local_index(v2_array, axis=2).form ) - assert to_list(ak._do.local_index(v2_array, axis=-1)) == [ + assert to_list(local_index(v2_array, axis=-1)) == [ [[0, 1, 2], [], [0, 1]], [], None, @@ -415,37 +385,37 @@ def test_bytemaskedarray_localindex(): [[], [0, 1, 2]], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=-1).form - == ak._do.local_index(v2_array, axis=-1).form + local_index(v2_array.to_typetracer(), axis=-1).form + == local_index(v2_array, axis=-1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, axis=4) + local_index(v2_array, axis=4) with pytest.raises(IndexError): - ak._do.local_index(v2_array, axis=-4) + local_index(v2_array, axis=-4) def test_numpyarray_localindex(): v2_array = ak.contents.numpyarray.NumpyArray( np.array([0.0, 1.1, 2.2, 3.3], dtype=np.float64) ) - assert to_list(ak._do.local_index(v2_array, axis=0)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, axis=0)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=0).form - == ak._do.local_index(v2_array, axis=0).form + local_index(v2_array.to_typetracer(), axis=0).form + == local_index(v2_array, axis=0).form ) - assert to_list(ak._do.local_index(v2_array, axis=-1)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, axis=-1)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), axis=-1).form - == ak._do.local_index(v2_array, axis=-1).form + local_index(v2_array.to_typetracer(), axis=-1).form + == local_index(v2_array, axis=-1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, axis=1) + local_index(v2_array, axis=1) with pytest.raises(IndexError): - ak._do.local_index(v2_array, axis=2) + local_index(v2_array, axis=2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, axis=-2) + local_index(v2_array, axis=-2) def test_bitmaskedarray_localindex(): @@ -482,7 +452,7 @@ def test_bitmaskedarray_localindex(): lsb_order=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -497,7 +467,7 @@ def test_bitmaskedarray_localindex(): 11, 12, ] - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -513,14 +483,13 @@ def test_bitmaskedarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bitmaskedarray.BitMaskedArray( ak.index.Index( @@ -555,7 +524,7 @@ def test_bitmaskedarray_localindex(): lsb_order=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -571,10 +540,9 @@ def test_bitmaskedarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -590,14 +558,13 @@ def test_bitmaskedarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bitmaskedarray.BitMaskedArray( ak.index.Index( @@ -634,7 +601,7 @@ def test_bitmaskedarray_localindex(): length=13, lsb_order=True, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -650,10 +617,9 @@ def test_bitmaskedarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -669,14 +635,13 @@ def test_bitmaskedarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) def test_unmaskedarray_localindex(): @@ -685,21 +650,19 @@ def test_unmaskedarray_localindex(): np.array([0.0, 1.1, 2.2, 3.3], dtype=np.float64) ) ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) def test_unionarray_localindex(): @@ -711,21 +674,19 @@ def test_unionarray_localindex(): ak.contents.numpyarray.NumpyArray(np.array([1.1, 2.2, 3.3, 4.4, 5.5])), ], ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) def test_recordarray_localindex(): @@ -740,31 +701,27 @@ def test_recordarray_localindex(): ), 3, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1] + assert to_list(local_index(v2_array, 0)) == [0, 1] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(v2_array, 1)) == [[0, 1, 2], [0, 1, 2]] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [[0, 1, 2], [0, 1, 2]] + assert to_list(local_index(v2_array, -1)) == [[0, 1, 2], [0, 1, 2]] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [0, 1] + assert to_list(local_index(v2_array, -2)) == [0, 1] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -3) + local_index(v2_array, -3) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 2) + local_index(v2_array, 2) v2_array = ak.contents.regulararray.RegularArray( ak.contents.recordarray.RecordArray( @@ -774,7 +731,7 @@ def test_recordarray_localindex(): zeros_length=10, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -787,10 +744,9 @@ def test_recordarray_localindex(): 9, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [ + assert to_list(local_index(v2_array, 1)) == [ [], [], [], @@ -803,10 +759,9 @@ def test_recordarray_localindex(): [], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ [], [], [], @@ -819,10 +774,9 @@ def test_recordarray_localindex(): [], ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [ + assert to_list(local_index(v2_array, -2)) == [ 0, 1, 2, @@ -835,12 +789,11 @@ def test_recordarray_localindex(): 9, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -3) + local_index(v2_array, -3) v2_array = ak.contents.listarray.ListArray( ak.index.Index(np.array([4, 100, 1])), @@ -855,31 +808,27 @@ def test_recordarray_localindex(): ), ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [[0, 1, 2], [], [0, 1]] + assert to_list(local_index(v2_array, 1)) == [[0, 1, 2], [], [0, 1]] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [[0, 1, 2], [], [0, 1]] + assert to_list(local_index(v2_array, -1)) == [[0, 1, 2], [], [0, 1]] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [0, 1, 2] + assert to_list(local_index(v2_array, -2)) == [0, 1, 2] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -3) + local_index(v2_array, -3) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 2) + local_index(v2_array, 2) v2_array = ak.contents.listoffsetarray.ListOffsetArray( ak.index.Index(np.array([1, 4, 4, 6])), @@ -892,31 +841,27 @@ def test_recordarray_localindex(): ["nest"], ), ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, 1)) == [[0, 1, 2], [], [0, 1]] + assert to_list(local_index(v2_array, 1)) == [[0, 1, 2], [], [0, 1]] assert ( - ak._do.local_index(v2_array.to_typetracer(), 1).form - == ak._do.local_index(v2_array, 1).form + local_index(v2_array.to_typetracer(), 1).form == local_index(v2_array, 1).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [[0, 1, 2], [], [0, 1]] + assert to_list(local_index(v2_array, -1)) == [[0, 1, 2], [], [0, 1]] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) - assert to_list(ak._do.local_index(v2_array, -2)) == [0, 1, 2] + assert to_list(local_index(v2_array, -2)) == [0, 1, 2] assert ( - ak._do.local_index(v2_array.to_typetracer(), -2).form - == ak._do.local_index(v2_array, -2).form + local_index(v2_array.to_typetracer(), -2).form == local_index(v2_array, -2).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -3) + local_index(v2_array, -3) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 2) + local_index(v2_array, 2) v2_array = ak.contents.indexedarray.IndexedArray( ak.index.Index(np.array([2, 2, 0, 1, 4, 5, 4])), @@ -929,21 +874,19 @@ def test_recordarray_localindex(): ["nest"], ), ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.indexedoptionarray.IndexedOptionArray( ak.index.Index(np.array([2, 2, -1, 1, -1, 5, 4])), @@ -956,21 +899,19 @@ def test_recordarray_localindex(): ["nest"], ), ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bytemaskedarray.ByteMaskedArray( ak.index.Index(np.array([1, 0, 1, 0, 1], dtype=np.int8)), @@ -985,21 +926,19 @@ def test_recordarray_localindex(): valid_when=True, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bytemaskedarray.ByteMaskedArray( ak.index.Index(np.array([0, 1, 0, 1, 0], dtype=np.int8)), @@ -1014,21 +953,19 @@ def test_recordarray_localindex(): valid_when=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3, 4] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3, 4] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bitmaskedarray.BitMaskedArray( ak.index.Index( @@ -1082,7 +1019,7 @@ def test_recordarray_localindex(): lsb_order=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -1098,10 +1035,9 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -1117,13 +1053,12 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bitmaskedarray.BitMaskedArray( ak.index.Index( @@ -1178,7 +1113,7 @@ def test_recordarray_localindex(): lsb_order=False, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -1194,10 +1129,9 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -1213,14 +1147,13 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bitmaskedarray.BitMaskedArray( ak.index.Index( @@ -1278,7 +1211,7 @@ def test_recordarray_localindex(): lsb_order=True, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -1294,10 +1227,9 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -1313,14 +1245,13 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.bitmaskedarray.BitMaskedArray( ak.index.Index( @@ -1378,7 +1309,7 @@ def test_recordarray_localindex(): lsb_order=True, ) - assert to_list(ak._do.local_index(v2_array, 0)) == [ + assert to_list(local_index(v2_array, 0)) == [ 0, 1, 2, @@ -1394,10 +1325,9 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [ + assert to_list(local_index(v2_array, -1)) == [ 0, 1, 2, @@ -1413,14 +1343,13 @@ def test_recordarray_localindex(): 12, ] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.unmaskedarray.UnmaskedArray( ak.contents.recordarray.RecordArray( @@ -1433,21 +1362,19 @@ def test_recordarray_localindex(): ) ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) v2_array = ak.contents.unionarray.UnionArray( ak.index.Index(np.array([1, 1, 0, 0, 1, 0, 1], dtype=np.int8)), @@ -1467,18 +1394,16 @@ def test_recordarray_localindex(): ], ) - assert to_list(ak._do.local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, 0)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), 0).form - == ak._do.local_index(v2_array, 0).form + local_index(v2_array.to_typetracer(), 0).form == local_index(v2_array, 0).form ) - assert to_list(ak._do.local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] + assert to_list(local_index(v2_array, -1)) == [0, 1, 2, 3, 4, 5, 6] assert ( - ak._do.local_index(v2_array.to_typetracer(), -1).form - == ak._do.local_index(v2_array, -1).form + local_index(v2_array.to_typetracer(), -1).form == local_index(v2_array, -1).form ) with pytest.raises(IndexError): - ak._do.local_index(v2_array, -2) + local_index(v2_array, -2) with pytest.raises(IndexError): - ak._do.local_index(v2_array, 1) + local_index(v2_array, 1) diff --git a/tests/test_1074_combinations.py b/tests/test_1074_combinations.py index e025ae400a..9e3fc36839 100644 --- a/tests/test_1074_combinations.py +++ b/tests/test_1074_combinations.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.content import combinations to_list = ak.operations.to_list @@ -14,7 +14,7 @@ def test_ListOffsetArray(): v2_array = ak.highlevel.Array( [[0.0, 1.1, 2.2, 3.3], [], [4.4, 5.5, 6.6], [7.7], [8.8, 9.9, 10.0, 11.1, 12.2]] ).layout - assert to_list(ak._do.combinations(v2_array, 2, replacement=False)) == [ + assert to_list(combinations(v2_array, 2, replacement=False)) == [ [(0.0, 1.1), (0.0, 2.2), (0.0, 3.3), (1.1, 2.2), (1.1, 3.3), (2.2, 3.3)], [], [(4.4, 5.5), (4.4, 6.6), (5.5, 6.6)], @@ -33,12 +33,10 @@ def test_ListOffsetArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, replacement=False).form - == ak._do.combinations(v2_array, 2, replacement=False).form + combinations(v2_array.to_typetracer(), 2, replacement=False).form + == combinations(v2_array, 2, replacement=False).form ) - assert to_list( - ak._do.combinations(v2_array, 2, replacement=False, fields=["x", "y"]) - ) == [ + assert to_list(combinations(v2_array, 2, replacement=False, fields=["x", "y"])) == [ [ {"x": 0.0, "y": 1.1}, {"x": 0.0, "y": 2.2}, @@ -64,28 +62,28 @@ def test_ListOffsetArray(): ], ] assert ( - ak._do.combinations( + combinations( v2_array.to_typetracer(), 2, replacement=False, fields=["x", "y"] ).form - == ak._do.combinations(v2_array, 2, replacement=False, fields=["x", "y"]).form + == combinations(v2_array, 2, replacement=False, fields=["x", "y"]).form ) assert ( - ak._do.combinations( + combinations( v2_array, 2, replacement=False, parameters={"some": "param"} ).content.parameters["some"] == "param" ) assert ( - ak._do.combinations( + combinations( v2_array.to_typetracer(), 2, replacement=False, parameters={"some": "param"} ).form - == ak._do.combinations( + == combinations( v2_array, 2, replacement=False, parameters={"some": "param"} ).form ) - assert to_list(ak._do.combinations(v2_array, 2, replacement=True)) == [ + assert to_list(combinations(v2_array, 2, replacement=True)) == [ [ (0.0, 0.0), (0.0, 1.1), @@ -120,11 +118,11 @@ def test_ListOffsetArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, replacement=True).form - == ak._do.combinations(v2_array, 2, replacement=True).form + combinations(v2_array.to_typetracer(), 2, replacement=True).form + == combinations(v2_array, 2, replacement=True).form ) - assert to_list(ak._do.combinations(v2_array, 3, replacement=False)) == [ + assert to_list(combinations(v2_array, 3, replacement=False)) == [ [(0.0, 1.1, 2.2), (0.0, 1.1, 3.3), (0.0, 2.2, 3.3), (1.1, 2.2, 3.3)], [], [(4.4, 5.5, 6.6)], @@ -143,11 +141,11 @@ def test_ListOffsetArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, replacement=False).form - == ak._do.combinations(v2_array, 3, replacement=False).form + combinations(v2_array.to_typetracer(), 3, replacement=False).form + == combinations(v2_array, 3, replacement=False).form ) - assert to_list(ak._do.combinations(v2_array, 3, replacement=True)) == [ + assert to_list(combinations(v2_array, 3, replacement=True)) == [ [ (0.0, 0.0, 0.0), (0.0, 0.0, 1.1), @@ -223,8 +221,8 @@ def test_ListOffsetArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, replacement=True).form - == ak._do.combinations(v2_array, 3, replacement=True).form + combinations(v2_array.to_typetracer(), 3, replacement=True).form + == combinations(v2_array, 3, replacement=True).form ) @@ -233,18 +231,16 @@ def test_RegularArray(): np.array([[0.0, 1.1, 2.2, 3.3], [4.4, 5.5, 6.6, 7.7]]) ).layout - assert to_list(ak._do.combinations(v2_array, 2, replacement=False)) == [ + assert to_list(combinations(v2_array, 2, replacement=False)) == [ [(0.0, 1.1), (0.0, 2.2), (0.0, 3.3), (1.1, 2.2), (1.1, 3.3), (2.2, 3.3)], [(4.4, 5.5), (4.4, 6.6), (4.4, 7.7), (5.5, 6.6), (5.5, 7.7), (6.6, 7.7)], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, replacement=False).form - == ak._do.combinations(v2_array, 2, replacement=False).form + combinations(v2_array.to_typetracer(), 2, replacement=False).form + == combinations(v2_array, 2, replacement=False).form ) - assert to_list( - ak._do.combinations(v2_array, 2, replacement=False, fields=["x", "y"]) - ) == [ + assert to_list(combinations(v2_array, 2, replacement=False, fields=["x", "y"])) == [ [ {"x": 0.0, "y": 1.1}, {"x": 0.0, "y": 2.2}, @@ -263,28 +259,28 @@ def test_RegularArray(): ], ] assert ( - ak._do.combinations( + combinations( v2_array.to_typetracer(), 2, replacement=False, fields=["x", "y"] ).form - == ak._do.combinations(v2_array, 2, replacement=False, fields=["x", "y"]).form + == combinations(v2_array, 2, replacement=False, fields=["x", "y"]).form ) assert ( - ak._do.combinations( + combinations( v2_array, 2, replacement=False, parameters={"some": "param"} ).content.parameters["some"] == "param" ) assert ( - ak._do.combinations( + combinations( v2_array.to_typetracer(), 2, replacement=False, parameters={"some": "param"} ).form - == ak._do.combinations( + == combinations( v2_array, 2, replacement=False, parameters={"some": "param"} ).form ) - assert to_list(ak._do.combinations(v2_array, 2, replacement=True)) == [ + assert to_list(combinations(v2_array, 2, replacement=True)) == [ [ (0.0, 0.0), (0.0, 1.1), @@ -311,20 +307,20 @@ def test_RegularArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, replacement=True).form - == ak._do.combinations(v2_array, 2, replacement=True).form + combinations(v2_array.to_typetracer(), 2, replacement=True).form + == combinations(v2_array, 2, replacement=True).form ) - assert to_list(ak._do.combinations(v2_array, 3, replacement=False)) == [ + assert to_list(combinations(v2_array, 3, replacement=False)) == [ [(0.0, 1.1, 2.2), (0.0, 1.1, 3.3), (0.0, 2.2, 3.3), (1.1, 2.2, 3.3)], [(4.4, 5.5, 6.6), (4.4, 5.5, 7.7), (4.4, 6.6, 7.7), (5.5, 6.6, 7.7)], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, replacement=False).form - == ak._do.combinations(v2_array, 3, replacement=False).form + combinations(v2_array.to_typetracer(), 3, replacement=False).form + == combinations(v2_array, 3, replacement=False).form ) - assert to_list(ak._do.combinations(v2_array, 3, replacement=True)) == [ + assert to_list(combinations(v2_array, 3, replacement=True)) == [ [ (0.0, 0.0, 0.0), (0.0, 0.0, 1.1), @@ -371,15 +367,15 @@ def test_RegularArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, replacement=True).form - == ak._do.combinations(v2_array, 3, replacement=True).form + combinations(v2_array.to_typetracer(), 3, replacement=True).form + == combinations(v2_array, 3, replacement=True).form ) def test_axis0(): v2_array = ak.highlevel.Array([0.0, 1.1, 2.2, 3.3]).layout - assert to_list(ak._do.combinations(v2_array, 2, replacement=False, axis=0)) == [ + assert to_list(combinations(v2_array, 2, replacement=False, axis=0)) == [ (0.0, 1.1), (0.0, 2.2), (0.0, 3.3), @@ -388,12 +384,12 @@ def test_axis0(): (2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, replacement=False, axis=0).form - == ak._do.combinations(v2_array, 2, replacement=False, axis=0).form + combinations(v2_array.to_typetracer(), 2, replacement=False, axis=0).form + == combinations(v2_array, 2, replacement=False, axis=0).form ) assert to_list( - ak._do.combinations(v2_array, 2, replacement=False, axis=0, fields=["x", "y"]) + combinations(v2_array, 2, replacement=False, axis=0, fields=["x", "y"]) ) == [ {"x": 0.0, "y": 1.1}, {"x": 0.0, "y": 2.2}, @@ -403,42 +399,40 @@ def test_axis0(): {"x": 2.2, "y": 3.3}, ] assert ( - ak._do.combinations( + combinations( v2_array.to_typetracer(), 2, replacement=False, axis=0, fields=["x", "y"] ).form - == ak._do.combinations( - v2_array, 2, replacement=False, axis=0, fields=["x", "y"] - ).form + == combinations(v2_array, 2, replacement=False, axis=0, fields=["x", "y"]).form ) assert ( - ak._do.combinations( + combinations( v2_array, 2, replacement=False, axis=0, parameters={"some": "param"} ).parameters["some"] == "param" ) assert ( - ak._do.combinations( + combinations( v2_array.to_typetracer(), 2, replacement=False, axis=0, parameters={"some": "param"}, ).form - == ak._do.combinations( + == combinations( v2_array, 2, replacement=False, axis=0, parameters={"some": "param"} ).form ) - assert to_list(ak._do.combinations(v2_array, 3, replacement=False, axis=0)) == [ + assert to_list(combinations(v2_array, 3, replacement=False, axis=0)) == [ (0.0, 1.1, 2.2), (0.0, 1.1, 3.3), (0.0, 2.2, 3.3), (1.1, 2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, replacement=False, axis=0).form - == ak._do.combinations(v2_array, 3, replacement=False, axis=0).form + combinations(v2_array.to_typetracer(), 3, replacement=False, axis=0).form + == combinations(v2_array, 3, replacement=False, axis=0).form ) @@ -455,7 +449,7 @@ def test_IndexedArray(): ] ).layout - assert to_list(ak._do.combinations(v2_array, 2, replacement=False)) == [ + assert to_list(combinations(v2_array, 2, replacement=False)) == [ [(0.0, 1.1), (0.0, 2.2), (0.0, 3.3), (1.1, 2.2), (1.1, 3.3), (2.2, 3.3)], [], [(4.4, 5.5), (4.4, 6.6), (5.5, 6.6)], @@ -476,8 +470,8 @@ def test_IndexedArray(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, replacement=False).form - == ak._do.combinations(v2_array, 2, replacement=False).form + combinations(v2_array.to_typetracer(), 2, replacement=False).form + == combinations(v2_array, 2, replacement=False).form ) @@ -490,7 +484,7 @@ def test_axis2(): ] ).layout - assert to_list(ak._do.combinations(v2_array, 2, axis=1, replacement=False)) == [ + assert to_list(combinations(v2_array, 2, axis=1, replacement=False)) == [ [ ([0.0, 1.1, 2.2, 3.3], []), ([0.0, 1.1, 2.2, 3.3], [4.4, 5.5, 6.6]), @@ -500,11 +494,11 @@ def test_axis2(): [([7.7], [8.8, 9.9, 10.0, 11.1, 12.2])], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=1, replacement=False).form - == ak._do.combinations(v2_array, 2, axis=1, replacement=False).form + combinations(v2_array.to_typetracer(), 2, axis=1, replacement=False).form + == combinations(v2_array, 2, axis=1, replacement=False).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=2, replacement=False)) == [ + assert to_list(combinations(v2_array, 2, axis=2, replacement=False)) == [ [ [(0.0, 1.1), (0.0, 2.2), (0.0, 3.3), (1.1, 2.2), (1.1, 3.3), (2.2, 3.3)], [], @@ -528,8 +522,8 @@ def test_axis2(): ], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=2, replacement=False).form - == ak._do.combinations(v2_array, 2, axis=2, replacement=False).form + combinations(v2_array.to_typetracer(), 2, axis=2, replacement=False).form + == combinations(v2_array, 2, axis=2, replacement=False).form ) @@ -541,7 +535,7 @@ def test_ByteMaskedArray(): mask = ak.index.Index8(np.array([0, 0, 1, 1, 0], dtype=np.int8)) v2_array = ak.contents.ByteMaskedArray(mask, content, valid_when=False) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ ([[0, 1, 2], [], [3, 4]], []), ([[0, 1, 2], [], [3, 4]], None), ([[0, 1, 2], [], [3, 4]], None), @@ -554,11 +548,11 @@ def test_ByteMaskedArray(): (None, [[], [10, 11, 12]]), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-3)) == [ + assert to_list(combinations(v2_array, 2, axis=-3)) == [ ([[0, 1, 2], [], [3, 4]], []), ([[0, 1, 2], [], [3, 4]], None), ([[0, 1, 2], [], [3, 4]], None), @@ -571,11 +565,11 @@ def test_ByteMaskedArray(): (None, [[], [10, 11, 12]]), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-3).form - == ak._do.combinations(v2_array, 2, axis=-3).form + combinations(v2_array.to_typetracer(), 2, axis=-3).form + == combinations(v2_array, 2, axis=-3).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=1)) == [ + assert to_list(combinations(v2_array, 2, axis=1)) == [ [([0, 1, 2], []), ([0, 1, 2], [3, 4]), ([], [3, 4])], [], None, @@ -583,11 +577,11 @@ def test_ByteMaskedArray(): [([], [10, 11, 12])], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=1).form - == ak._do.combinations(v2_array, 2, axis=1).form + combinations(v2_array.to_typetracer(), 2, axis=1).form + == combinations(v2_array, 2, axis=1).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-2)) == [ + assert to_list(combinations(v2_array, 2, axis=-2)) == [ [([0, 1, 2], []), ([0, 1, 2], [3, 4]), ([], [3, 4])], [], None, @@ -595,11 +589,11 @@ def test_ByteMaskedArray(): [([], [10, 11, 12])], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-2).form - == ak._do.combinations(v2_array, 2, axis=-2).form + combinations(v2_array.to_typetracer(), 2, axis=-2).form + == combinations(v2_array, 2, axis=-2).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=2)) == [ + assert to_list(combinations(v2_array, 2, axis=2)) == [ [[(0, 1), (0, 2), (1, 2)], [], [(3, 4)]], [], None, @@ -607,11 +601,11 @@ def test_ByteMaskedArray(): [[], [(10, 11), (10, 12), (11, 12)]], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=2).form - == ak._do.combinations(v2_array, 2, axis=2).form + combinations(v2_array.to_typetracer(), 2, axis=2).form + == combinations(v2_array, 2, axis=2).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-1)) == [ + assert to_list(combinations(v2_array, 2, axis=-1)) == [ [[(0, 1), (0, 2), (1, 2)], [], [(3, 4)]], [], None, @@ -619,8 +613,8 @@ def test_ByteMaskedArray(): [[], [(10, 11), (10, 12), (11, 12)]], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-1).form - == ak._do.combinations(v2_array, 2, axis=-1).form + combinations(v2_array.to_typetracer(), 2, axis=-1).form + == combinations(v2_array, 2, axis=-1).form ) @@ -632,7 +626,7 @@ def test_IndexedOptionArray(): index = ak.index.Index64(np.array([0, 1, -1, -1, 4], dtype=np.int64)) v2_array = ak.contents.IndexedOptionArray(index, content) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ ([[0, 1, 2], [], [3, 4]], []), ([[0, 1, 2], [], [3, 4]], None), ([[0, 1, 2], [], [3, 4]], None), @@ -645,11 +639,11 @@ def test_IndexedOptionArray(): (None, [[], [10, 11, 12]]), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-3)) == [ + assert to_list(combinations(v2_array, 2, axis=-3)) == [ ([[0, 1, 2], [], [3, 4]], []), ([[0, 1, 2], [], [3, 4]], None), ([[0, 1, 2], [], [3, 4]], None), @@ -662,11 +656,11 @@ def test_IndexedOptionArray(): (None, [[], [10, 11, 12]]), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-3).form - == ak._do.combinations(v2_array, 2, axis=-3).form + combinations(v2_array.to_typetracer(), 2, axis=-3).form + == combinations(v2_array, 2, axis=-3).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=1)) == [ + assert to_list(combinations(v2_array, 2, axis=1)) == [ [([0, 1, 2], []), ([0, 1, 2], [3, 4]), ([], [3, 4])], [], None, @@ -674,11 +668,11 @@ def test_IndexedOptionArray(): [([], [10, 11, 12])], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=1).form - == ak._do.combinations(v2_array, 2, axis=1).form + combinations(v2_array.to_typetracer(), 2, axis=1).form + == combinations(v2_array, 2, axis=1).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-2)) == [ + assert to_list(combinations(v2_array, 2, axis=-2)) == [ [([0, 1, 2], []), ([0, 1, 2], [3, 4]), ([], [3, 4])], [], None, @@ -686,11 +680,11 @@ def test_IndexedOptionArray(): [([], [10, 11, 12])], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-2).form - == ak._do.combinations(v2_array, 2, axis=-2).form + combinations(v2_array.to_typetracer(), 2, axis=-2).form + == combinations(v2_array, 2, axis=-2).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=2)) == [ + assert to_list(combinations(v2_array, 2, axis=2)) == [ [[(0, 1), (0, 2), (1, 2)], [], [(3, 4)]], [], None, @@ -698,11 +692,11 @@ def test_IndexedOptionArray(): [[], [(10, 11), (10, 12), (11, 12)]], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=2).form - == ak._do.combinations(v2_array, 2, axis=2).form + combinations(v2_array.to_typetracer(), 2, axis=2).form + == combinations(v2_array, 2, axis=2).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-1)) == [ + assert to_list(combinations(v2_array, 2, axis=-1)) == [ [[(0, 1), (0, 2), (1, 2)], [], [(3, 4)]], [], None, @@ -710,8 +704,8 @@ def test_IndexedOptionArray(): [[], [(10, 11), (10, 12), (11, 12)]], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-1).form - == ak._do.combinations(v2_array, 2, axis=-1).form + combinations(v2_array.to_typetracer(), 2, axis=-1).form + == combinations(v2_array, 2, axis=-1).form ) @@ -720,7 +714,7 @@ def test_NumpyArray(): np.array([0.0, 1.1, 2.2, 3.3], dtype=np.float64) ) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ (0.0, 1.1), (0.0, 2.2), (0.0, 3.3), @@ -729,11 +723,11 @@ def test_NumpyArray(): (2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-1)) == [ + assert to_list(combinations(v2_array, 2, axis=-1)) == [ (0.0, 1.1), (0.0, 2.2), (0.0, 3.3), @@ -742,25 +736,25 @@ def test_NumpyArray(): (2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-1).form - == ak._do.combinations(v2_array, 2, axis=-1).form + combinations(v2_array.to_typetracer(), 2, axis=-1).form + == combinations(v2_array, 2, axis=-1).form ) - assert to_list(ak._do.combinations(v2_array, 3, axis=-1)) == [ + assert to_list(combinations(v2_array, 3, axis=-1)) == [ (0.0, 1.1, 2.2), (0.0, 1.1, 3.3), (0.0, 2.2, 3.3), (1.1, 2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, axis=-1).form - == ak._do.combinations(v2_array, 3, axis=-1).form + combinations(v2_array.to_typetracer(), 3, axis=-1).form + == combinations(v2_array, 3, axis=-1).form ) - assert to_list(ak._do.combinations(v2_array, 4, axis=-1)) == [(0.0, 1.1, 2.2, 3.3)] + assert to_list(combinations(v2_array, 4, axis=-1)) == [(0.0, 1.1, 2.2, 3.3)] assert ( - ak._do.combinations(v2_array.to_typetracer(), 4, axis=-1).form - == ak._do.combinations(v2_array, 4, axis=-1).form + combinations(v2_array.to_typetracer(), 4, axis=-1).form + == combinations(v2_array, 4, axis=-1).form ) @@ -798,7 +792,7 @@ def test_BitMaskedArray(): lsb_order=False, ) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ (0.0, 1.0), (0.0, 2.0), (0.0, 3.0), @@ -879,11 +873,11 @@ def test_BitMaskedArray(): (None, 5.5), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 3, axis=0)) == [ + assert to_list(combinations(v2_array, 3, axis=0)) == [ (0.0, 1.0, 2.0), (0.0, 1.0, 3.0), (0.0, 1.0, None), @@ -1172,18 +1166,18 @@ def test_BitMaskedArray(): (3.3, None, 5.5), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, axis=0).form - == ak._do.combinations(v2_array, 3, axis=0).form + combinations(v2_array.to_typetracer(), 3, axis=0).form + == combinations(v2_array, 3, axis=0).form ) def test_EmptyArray(): v2_array = ak.contents.emptyarray.EmptyArray() - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [] + assert to_list(combinations(v2_array, 2, axis=0)) == [] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) @@ -1201,17 +1195,17 @@ def test_RecordArray(): ), ) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ ([{"nest": 1.1}, {"nest": 2.2}, {"nest": 3.3}], []), ([{"nest": 1.1}, {"nest": 2.2}, {"nest": 3.3}], [{"nest": 4.4}, {"nest": 5.5}]), ([], [{"nest": 4.4}, {"nest": 5.5}]), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=1)) == [ + assert to_list(combinations(v2_array, 2, axis=1)) == [ [ ({"nest": 1.1}, {"nest": 2.2}), ({"nest": 1.1}, {"nest": 3.3}), @@ -1221,24 +1215,24 @@ def test_RecordArray(): [({"nest": 4.4}, {"nest": 5.5})], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=1).form - == ak._do.combinations(v2_array, 2, axis=1).form + combinations(v2_array.to_typetracer(), 2, axis=1).form + == combinations(v2_array, 2, axis=1).form ) - assert to_list(ak._do.combinations(v2_array, 3, axis=1)) == [ + assert to_list(combinations(v2_array, 3, axis=1)) == [ [({"nest": 1.1}, {"nest": 2.2}, {"nest": 3.3})], [], [], ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, axis=1).form - == ak._do.combinations(v2_array, 3, axis=1).form + combinations(v2_array.to_typetracer(), 3, axis=1).form + == combinations(v2_array, 3, axis=1).form ) - assert to_list(ak._do.combinations(v2_array, 4, axis=1)) == [[], [], []] + assert to_list(combinations(v2_array, 4, axis=1)) == [[], [], []] assert ( - ak._do.combinations(v2_array.to_typetracer(), 4, axis=1).form - == ak._do.combinations(v2_array, 4, axis=1).form + combinations(v2_array.to_typetracer(), 4, axis=1).form + == combinations(v2_array, 4, axis=1).form ) @@ -1261,7 +1255,7 @@ def test_UnionArray(): ], ) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ ({"nest": 5.5}, {"nest": 4.4}), ({"nest": 5.5}, {"nest": "1"}), ({"nest": 5.5}, {"nest": "2"}), @@ -1285,11 +1279,11 @@ def test_UnionArray(): ({"nest": "3"}, {"nest": 5.5}), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 3, axis=0)) == [ + assert to_list(combinations(v2_array, 3, axis=0)) == [ ({"nest": 5.5}, {"nest": 4.4}, {"nest": "1"}), ({"nest": 5.5}, {"nest": 4.4}, {"nest": "2"}), ({"nest": 5.5}, {"nest": 4.4}, {"nest": 3.3}), @@ -1327,11 +1321,11 @@ def test_UnionArray(): ({"nest": 3.3}, {"nest": "3"}, {"nest": 5.5}), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, axis=0).form - == ak._do.combinations(v2_array, 3, axis=0).form + combinations(v2_array.to_typetracer(), 3, axis=0).form + == combinations(v2_array, 3, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 4, axis=0)) == [ + assert to_list(combinations(v2_array, 4, axis=0)) == [ ({"nest": 5.5}, {"nest": 4.4}, {"nest": "1"}, {"nest": "2"}), ({"nest": 5.5}, {"nest": 4.4}, {"nest": "1"}, {"nest": 3.3}), ({"nest": 5.5}, {"nest": 4.4}, {"nest": "1"}, {"nest": "3"}), @@ -1369,11 +1363,11 @@ def test_UnionArray(): ({"nest": "2"}, {"nest": 3.3}, {"nest": "3"}, {"nest": 5.5}), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 4, axis=0).form - == ak._do.combinations(v2_array, 4, axis=0).form + combinations(v2_array.to_typetracer(), 4, axis=0).form + == combinations(v2_array, 4, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-1)) == [ + assert to_list(combinations(v2_array, 2, axis=-1)) == [ ({"nest": 5.5}, {"nest": 4.4}), ({"nest": 5.5}, {"nest": "1"}), ({"nest": 5.5}, {"nest": "2"}), @@ -1397,8 +1391,8 @@ def test_UnionArray(): ({"nest": "3"}, {"nest": 5.5}), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-1).form - == ak._do.combinations(v2_array, 2, axis=-1).form + combinations(v2_array.to_typetracer(), 2, axis=-1).form + == combinations(v2_array, 2, axis=-1).form ) @@ -1409,7 +1403,7 @@ def test_UnmaskedArray(): ) ) - assert to_list(ak._do.combinations(v2_array, 2, axis=0)) == [ + assert to_list(combinations(v2_array, 2, axis=0)) == [ (0.0, 1.1), (0.0, 2.2), (0.0, 3.3), @@ -1418,28 +1412,28 @@ def test_UnmaskedArray(): (2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=0).form - == ak._do.combinations(v2_array, 2, axis=0).form + combinations(v2_array.to_typetracer(), 2, axis=0).form + == combinations(v2_array, 2, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 3, axis=0)) == [ + assert to_list(combinations(v2_array, 3, axis=0)) == [ (0.0, 1.1, 2.2), (0.0, 1.1, 3.3), (0.0, 2.2, 3.3), (1.1, 2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 3, axis=0).form - == ak._do.combinations(v2_array, 3, axis=0).form + combinations(v2_array.to_typetracer(), 3, axis=0).form + == combinations(v2_array, 3, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 4, axis=0)) == [(0.0, 1.1, 2.2, 3.3)] + assert to_list(combinations(v2_array, 4, axis=0)) == [(0.0, 1.1, 2.2, 3.3)] assert ( - ak._do.combinations(v2_array.to_typetracer(), 4, axis=0).form - == ak._do.combinations(v2_array, 4, axis=0).form + combinations(v2_array.to_typetracer(), 4, axis=0).form + == combinations(v2_array, 4, axis=0).form ) - assert to_list(ak._do.combinations(v2_array, 2, axis=-1)) == [ + assert to_list(combinations(v2_array, 2, axis=-1)) == [ (0.0, 1.1), (0.0, 2.2), (0.0, 3.3), @@ -1448,6 +1442,6 @@ def test_UnmaskedArray(): (2.2, 3.3), ] assert ( - ak._do.combinations(v2_array.to_typetracer(), 2, axis=-1).form - == ak._do.combinations(v2_array, 2, axis=-1).form + combinations(v2_array.to_typetracer(), 2, axis=-1).form + == combinations(v2_array, 2, axis=-1).form ) diff --git a/tests/test_1135_rpad_operation.py b/tests/test_1135_rpad_operation.py index c7100462b3..3441d79387 100644 --- a/tests/test_1135_rpad_operation.py +++ b/tests/test_1135_rpad_operation.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.content import pad_none to_list = ak.operations.to_list @@ -13,12 +13,9 @@ def test_rpad_and_clip_empty_array(): empty = ak.contents.emptyarray.EmptyArray() assert to_list(empty) == [] - assert to_list(ak._do.pad_none(empty, 5, 0)) == [None, None, None, None, None] - assert ( - ak._do.pad_none(empty.to_typetracer(), 5, 0).form - == ak._do.pad_none(empty, 5, 0).form - ) - assert to_list(ak._do.pad_none(empty, 5, 0, clip=True)) == [ + assert to_list(pad_none(empty, 5, 0)) == [None, None, None, None, None] + assert pad_none(empty.to_typetracer(), 5, 0).form == pad_none(empty, 5, 0).form + assert to_list(pad_none(empty, 5, 0, clip=True)) == [ None, None, None, @@ -26,8 +23,8 @@ def test_rpad_and_clip_empty_array(): None, ] assert ( - ak._do.pad_none(empty.to_typetracer(), 5, 0, clip=True).form - == ak._do.pad_none(empty, 5, 0, clip=True).form + pad_none(empty.to_typetracer(), 5, 0, clip=True).form + == pad_none(empty, 5, 0, clip=True).form ) @@ -40,7 +37,7 @@ def test_rpad_and_clip_numpy_array(): [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert to_list(ak._do.pad_none(array, 5, 0, clip=True)) == [ + assert to_list(pad_none(array, 5, 0, clip=True)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], None, @@ -48,20 +45,20 @@ def test_rpad_and_clip_numpy_array(): None, ] assert ( - ak._do.pad_none(array.to_typetracer(), 5, 0, clip=True).form - == ak._do.pad_none(array, 5, 0, clip=True).form + pad_none(array.to_typetracer(), 5, 0, clip=True).form + == pad_none(array, 5, 0, clip=True).form ) - assert to_list(ak._do.pad_none(array, 5, 1, clip=True)) == [ + assert to_list(pad_none(array, 5, 1, clip=True)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], None, None], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29], None, None], ] assert ( - ak._do.pad_none(array.to_typetracer(), 5, 1, clip=True).form - == ak._do.pad_none(array, 5, 1, clip=True).form + pad_none(array.to_typetracer(), 5, 1, clip=True).form + == pad_none(array, 5, 1, clip=True).form ) - assert to_list(ak._do.pad_none(array, 7, 2, clip=True)) == [ + assert to_list(pad_none(array, 7, 2, clip=True)) == [ [ [0, 1, 2, 3, 4, None, None], [5, 6, 7, 8, 9, None, None], @@ -74,23 +71,23 @@ def test_rpad_and_clip_numpy_array(): ], ] assert ( - ak._do.pad_none(array.to_typetracer(), 7, 2, clip=True).form - == ak._do.pad_none(array, 7, 2, clip=True).form + pad_none(array.to_typetracer(), 7, 2, clip=True).form + == pad_none(array, 7, 2, clip=True).form ) - assert to_list(ak._do.pad_none(array, 2, 2, clip=True)) == [ + assert to_list(pad_none(array, 2, 2, clip=True)) == [ [[0, 1], [5, 6], [10, 11]], [[15, 16], [20, 21], [25, 26]], ] assert ( - ak._do.pad_none(array.to_typetracer(), 2, 2, clip=True).form - == ak._do.pad_none(array, 2, 2, clip=True).form + pad_none(array.to_typetracer(), 2, 2, clip=True).form + == pad_none(array, 2, 2, clip=True).form ) def test_rpad_numpy_array(): array = ak.contents.numpyarray.NumpyArray(np.array([1.1, 2.2, 3.3, 4.4, 5.5])) - assert to_list(ak._do.pad_none(array, 10, 0)) == [ + assert to_list(pad_none(array, 10, 0)) == [ 1.1, 2.2, 3.3, @@ -102,33 +99,24 @@ def test_rpad_numpy_array(): None, None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 10, 0).form - == ak._do.pad_none(array, 10, 0).form - ) + assert pad_none(array.to_typetracer(), 10, 0).form == pad_none(array, 10, 0).form array = ak.contents.numpyarray.NumpyArray( np.array([[1.1, 2.2, 3.3], [4.4, 5.5, 6.6]]) ) - assert to_list(ak._do.pad_none(array, 5, 0)) == [ + assert to_list(pad_none(array, 5, 0)) == [ [1.1, 2.2, 3.3], [4.4, 5.5, 6.6], None, None, None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 0).form - == ak._do.pad_none(array, 5, 0).form - ) - assert to_list(ak._do.pad_none(array, 5, 1)) == [ + assert pad_none(array.to_typetracer(), 5, 0).form == pad_none(array, 5, 0).form + assert to_list(pad_none(array, 5, 1)) == [ [1.1, 2.2, 3.3, None, None], [4.4, 5.5, 6.6, None, None], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 1).form - == ak._do.pad_none(array, 5, 1).form - ) + assert pad_none(array.to_typetracer(), 5, 1).form == pad_none(array, 5, 1).form array = ak.contents.numpyarray.NumpyArray( np.arange(2 * 3 * 5, dtype=np.int64).reshape(2, 3, 5) @@ -138,93 +126,66 @@ def test_rpad_numpy_array(): [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert to_list(ak._do.pad_none(array, 1, 0)) == [ + assert to_list(pad_none(array, 1, 0)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 1, 0).form - == ak._do.pad_none(array, 1, 0).form - ) - assert to_list(ak._do.pad_none(array, 2, 0)) == [ + assert pad_none(array.to_typetracer(), 1, 0).form == pad_none(array, 1, 0).form + assert to_list(pad_none(array, 2, 0)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 2, 0).form - == ak._do.pad_none(array, 2, 0).form - ) - assert to_list(ak._do.pad_none(array, 3, 0)) == [ + assert pad_none(array.to_typetracer(), 2, 0).form == pad_none(array, 2, 0).form + assert to_list(pad_none(array, 3, 0)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 3, 0).form - == ak._do.pad_none(array, 3, 0).form - ) - assert to_list(ak._do.pad_none(array, 4, 0)) == [ + assert pad_none(array.to_typetracer(), 3, 0).form == pad_none(array, 3, 0).form + assert to_list(pad_none(array, 4, 0)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], None, None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 4, 0).form - == ak._do.pad_none(array, 4, 0).form - ) - assert to_list(ak._do.pad_none(array, 5, 0)) == [ + assert pad_none(array.to_typetracer(), 4, 0).form == pad_none(array, 4, 0).form + assert to_list(pad_none(array, 5, 0)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], None, None, None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 0).form - == ak._do.pad_none(array, 5, 0).form - ) + assert pad_none(array.to_typetracer(), 5, 0).form == pad_none(array, 5, 0).form - assert to_list(ak._do.pad_none(array, 2, 1)) == [ + assert to_list(pad_none(array, 2, 1)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert to_list(ak._do.pad_none(array, 3, 1)) == [ + assert to_list(pad_none(array, 3, 1)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 3, 1).form - == ak._do.pad_none(array, 3, 1).form - ) - assert to_list(ak._do.pad_none(array, 4, 1)) == [ + assert pad_none(array.to_typetracer(), 3, 1).form == pad_none(array, 3, 1).form + assert to_list(pad_none(array, 4, 1)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], None], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29], None], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 4, 1).form - == ak._do.pad_none(array, 4, 1).form - ) - assert to_list(ak._do.pad_none(array, 5, 1)) == [ + assert pad_none(array.to_typetracer(), 4, 1).form == pad_none(array, 4, 1).form + assert to_list(pad_none(array, 5, 1)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], None, None], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29], None, None], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 1).form - == ak._do.pad_none(array, 5, 1).form - ) + assert pad_none(array.to_typetracer(), 5, 1).form == pad_none(array, 5, 1).form - assert to_list(ak._do.pad_none(array, 3, 2)) == [ + assert to_list(pad_none(array, 3, 2)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 3, 2).form - == ak._do.pad_none(array, 3, 2).form - ) + assert pad_none(array.to_typetracer(), 3, 2).form == pad_none(array, 3, 2).form - assert to_list(ak._do.pad_none(array, 7, 2)) == [ + assert to_list(pad_none(array, 7, 2)) == [ [ [0, 1, 2, 3, 4, None, None], [5, 6, 7, 8, 9, None, None], @@ -236,19 +197,13 @@ def test_rpad_numpy_array(): [25, 26, 27, 28, 29, None, None], ], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 7, 2).form - == ak._do.pad_none(array, 7, 2).form - ) + assert pad_none(array.to_typetracer(), 7, 2).form == pad_none(array, 7, 2).form - assert to_list(ak._do.pad_none(array, 2, 2)) == [ + assert to_list(pad_none(array, 2, 2)) == [ [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 2, 2).form - == ak._do.pad_none(array, 2, 2).form - ) + assert pad_none(array.to_typetracer(), 2, 2).form == pad_none(array, 2, 2).form def test_rpad_and_clip_regular_array(): @@ -283,7 +238,7 @@ def test_rpad_and_clip_regular_array(): indexedarray = ak.contents.indexedoptionarray.IndexedOptionArray(index, content) array = ak.contents.regulararray.RegularArray(indexedarray, 3, zeros_length=0) - assert to_list(ak._do.pad_none(array, 5, 0, clip=True)) == [ + assert to_list(pad_none(array, 5, 0, clip=True)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], @@ -291,81 +246,81 @@ def test_rpad_and_clip_regular_array(): None, ] assert ( - ak._do.pad_none(array.to_typetracer(), 5, 0, clip=True).form - == ak._do.pad_none(array, 5, 0, clip=True).form + pad_none(array.to_typetracer(), 5, 0, clip=True).form + == pad_none(array, 5, 0, clip=True).form ) - assert to_list(ak._do.pad_none(array, 4, 0, clip=True)) == [ + assert to_list(pad_none(array, 4, 0, clip=True)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], None, ] assert ( - ak._do.pad_none(array.to_typetracer(), 4, 0, clip=True).form - == ak._do.pad_none(array, 4, 0, clip=True).form + pad_none(array.to_typetracer(), 4, 0, clip=True).form + == pad_none(array, 4, 0, clip=True).form ) - assert to_list(ak._do.pad_none(array, 3, 0, clip=True)) == [ + assert to_list(pad_none(array, 3, 0, clip=True)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], ] assert ( - ak._do.pad_none(array.to_typetracer(), 3, 0, clip=True).form - == ak._do.pad_none(array, 3, 0, clip=True).form + pad_none(array.to_typetracer(), 3, 0, clip=True).form + == pad_none(array, 3, 0, clip=True).form ) - assert to_list(ak._do.pad_none(array, 2, 0, clip=True)) == [ + assert to_list(pad_none(array, 2, 0, clip=True)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], ] assert ( - ak._do.pad_none(array.to_typetracer(), 2, 0, clip=True).form - == ak._do.pad_none(array, 2, 0, clip=True).form + pad_none(array.to_typetracer(), 2, 0, clip=True).form + == pad_none(array, 2, 0, clip=True).form ) - assert to_list(ak._do.pad_none(array, 1, 0, clip=True)) == [[6.9, 3.9, 6.9]] + assert to_list(pad_none(array, 1, 0, clip=True)) == [[6.9, 3.9, 6.9]] assert ( - ak._do.pad_none(array.to_typetracer(), 1, 0, clip=True).form - == ak._do.pad_none(array, 1, 0, clip=True).form + pad_none(array.to_typetracer(), 1, 0, clip=True).form + == pad_none(array, 1, 0, clip=True).form ) - assert to_list(ak._do.pad_none(array, 5, 1, clip=True)) == [ + assert to_list(pad_none(array, 5, 1, clip=True)) == [ [6.9, 3.9, 6.9, None, None], [2.2, 1.5, 1.6, None, None], [3.6, None, 6.7, None, None], ] assert ( - ak._do.pad_none(array.to_typetracer(), 5, 1, clip=True).form - == ak._do.pad_none(array, 5, 1, clip=True).form + pad_none(array.to_typetracer(), 5, 1, clip=True).form + == pad_none(array, 5, 1, clip=True).form ) - assert to_list(ak._do.pad_none(array, 4, 1, clip=True)) == [ + assert to_list(pad_none(array, 4, 1, clip=True)) == [ [6.9, 3.9, 6.9, None], [2.2, 1.5, 1.6, None], [3.6, None, 6.7, None], ] assert ( - ak._do.pad_none(array.to_typetracer(), 4, 1, clip=True).form - == ak._do.pad_none(array, 4, 1, clip=True).form + pad_none(array.to_typetracer(), 4, 1, clip=True).form + == pad_none(array, 4, 1, clip=True).form ) - assert to_list(ak._do.pad_none(array, 3, 1, clip=True)) == [ + assert to_list(pad_none(array, 3, 1, clip=True)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], ] assert ( - ak._do.pad_none(array.to_typetracer(), 3, 1, clip=True).form - == ak._do.pad_none(array, 3, 1, clip=True).form + pad_none(array.to_typetracer(), 3, 1, clip=True).form + == pad_none(array, 3, 1, clip=True).form ) - assert to_list(ak._do.pad_none(array, 2, 1, clip=True)) == [ + assert to_list(pad_none(array, 2, 1, clip=True)) == [ [6.9, 3.9], [2.2, 1.5], [3.6, None], ] assert ( - ak._do.pad_none(array.to_typetracer(), 2, 1, clip=True).form - == ak._do.pad_none(array, 2, 1, clip=True).form + pad_none(array.to_typetracer(), 2, 1, clip=True).form + == pad_none(array, 2, 1, clip=True).form ) - assert to_list(ak._do.pad_none(array, 1, 1, clip=True)) == [[6.9], [2.2], [3.6]] + assert to_list(pad_none(array, 1, 1, clip=True)) == [[6.9], [2.2], [3.6]] assert ( - ak._do.pad_none(array.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(array, 1, 1, clip=True).form + pad_none(array.to_typetracer(), 1, 1, clip=True).form + == pad_none(array, 1, 1, clip=True).form ) array = ak.contents.numpyarray.NumpyArray(np.arange(2 * 3 * 5).reshape(2, 3, 5)) @@ -374,7 +329,7 @@ def test_rpad_and_clip_regular_array(): [[15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ] - assert to_list(ak._do.pad_none(array, 7, 2, clip=True)) == [ + assert to_list(pad_none(array, 7, 2, clip=True)) == [ [ [0, 1, 2, 3, 4, None, None], [5, 6, 7, 8, 9, None, None], @@ -387,8 +342,8 @@ def test_rpad_and_clip_regular_array(): ], ] assert ( - ak._do.pad_none(array.to_typetracer(), 7, 2, clip=True).form - == ak._do.pad_none(array, 7, 2, clip=True).form + pad_none(array.to_typetracer(), 7, 2, clip=True).form + == pad_none(array, 7, 2, clip=True).form ) content = ak.contents.numpyarray.NumpyArray( @@ -400,41 +355,39 @@ def test_rpad_and_clip_regular_array(): listoffsetarray, 2, zeros_length=0 ) - assert to_list(ak._do.pad_none(regulararray, 1, 0, clip=True)) == [ - [[0.0, 1.1, 2.2], []] - ] + assert to_list(pad_none(regulararray, 1, 0, clip=True)) == [[[0.0, 1.1, 2.2], []]] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 1, 0, clip=True).form - == ak._do.pad_none(regulararray, 1, 0, clip=True).form + pad_none(regulararray.to_typetracer(), 1, 0, clip=True).form + == pad_none(regulararray, 1, 0, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 2, 0, clip=True)) == [ + assert to_list(pad_none(regulararray, 2, 0, clip=True)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 2, 0, clip=True).form - == ak._do.pad_none(regulararray, 2, 0, clip=True).form + pad_none(regulararray.to_typetracer(), 2, 0, clip=True).form + == pad_none(regulararray, 2, 0, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 3, 0, clip=True)) == [ + assert to_list(pad_none(regulararray, 3, 0, clip=True)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 3, 0, clip=True).form - == ak._do.pad_none(regulararray, 3, 0, clip=True).form + pad_none(regulararray.to_typetracer(), 3, 0, clip=True).form + == pad_none(regulararray, 3, 0, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 4, 0, clip=True)) == [ + assert to_list(pad_none(regulararray, 4, 0, clip=True)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], None, ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 4, 0, clip=True).form - == ak._do.pad_none(regulararray, 4, 0, clip=True).form + pad_none(regulararray.to_typetracer(), 4, 0, clip=True).form + == pad_none(regulararray, 4, 0, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 5, 0, clip=True)) == [ + assert to_list(pad_none(regulararray, 5, 0, clip=True)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], @@ -442,91 +395,91 @@ def test_rpad_and_clip_regular_array(): None, ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 5, 0, clip=True).form - == ak._do.pad_none(regulararray, 5, 0, clip=True).form + pad_none(regulararray.to_typetracer(), 5, 0, clip=True).form + == pad_none(regulararray, 5, 0, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 1, 1, clip=True)) == [ + assert to_list(pad_none(regulararray, 1, 1, clip=True)) == [ [[0.0, 1.1, 2.2]], [[3.3, 4.4]], [[6.6, 7.7, 8.8, 9.9]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(regulararray, 1, 1, clip=True).form + pad_none(regulararray.to_typetracer(), 1, 1, clip=True).form + == pad_none(regulararray, 1, 1, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 2, 1, clip=True)) == [ + assert to_list(pad_none(regulararray, 2, 1, clip=True)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 2, 1, clip=True).form - == ak._do.pad_none(regulararray, 2, 1, clip=True).form + pad_none(regulararray.to_typetracer(), 2, 1, clip=True).form + == pad_none(regulararray, 2, 1, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 3, 1, clip=True)) == [ + assert to_list(pad_none(regulararray, 3, 1, clip=True)) == [ [[0.0, 1.1, 2.2], [], None], [[3.3, 4.4], [5.5], None], [[6.6, 7.7, 8.8, 9.9], [], None], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 3, 1, clip=True).form - == ak._do.pad_none(regulararray, 3, 1, clip=True).form + pad_none(regulararray.to_typetracer(), 3, 1, clip=True).form + == pad_none(regulararray, 3, 1, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 7, 1, clip=True)) == [ + assert to_list(pad_none(regulararray, 7, 1, clip=True)) == [ [[0.0, 1.1, 2.2], [], None, None, None, None, None], [[3.3, 4.4], [5.5], None, None, None, None, None], [[6.6, 7.7, 8.8, 9.9], [], None, None, None, None, None], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 7, 1, clip=True).form - == ak._do.pad_none(regulararray, 7, 1, clip=True).form + pad_none(regulararray.to_typetracer(), 7, 1, clip=True).form + == pad_none(regulararray, 7, 1, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 1, 2, clip=True)) == [ + assert to_list(pad_none(regulararray, 1, 2, clip=True)) == [ [[0.0], [None]], [[3.3], [5.5]], [[6.6], [None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 1, 2, clip=True).form - == ak._do.pad_none(regulararray, 1, 2, clip=True).form + pad_none(regulararray.to_typetracer(), 1, 2, clip=True).form + == pad_none(regulararray, 1, 2, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 2, 2, clip=True)) == [ + assert to_list(pad_none(regulararray, 2, 2, clip=True)) == [ [[0.0, 1.1], [None, None]], [[3.3, 4.4], [5.5, None]], [[6.6, 7.7], [None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 2, 2, clip=True).form - == ak._do.pad_none(regulararray, 2, 2, clip=True).form + pad_none(regulararray.to_typetracer(), 2, 2, clip=True).form + == pad_none(regulararray, 2, 2, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 3, 2, clip=True)) == [ + assert to_list(pad_none(regulararray, 3, 2, clip=True)) == [ [[0.0, 1.1, 2.2], [None, None, None]], [[3.3, 4.4, None], [5.5, None, None]], [[6.6, 7.7, 8.8], [None, None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 3, 2, clip=True).form - == ak._do.pad_none(regulararray, 3, 2, clip=True).form + pad_none(regulararray.to_typetracer(), 3, 2, clip=True).form + == pad_none(regulararray, 3, 2, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 4, 2, clip=True)) == [ + assert to_list(pad_none(regulararray, 4, 2, clip=True)) == [ [[0.0, 1.1, 2.2, None], [None, None, None, None]], [[3.3, 4.4, None, None], [5.5, None, None, None]], [[6.6, 7.7, 8.8, 9.9], [None, None, None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 4, 2, clip=True).form - == ak._do.pad_none(regulararray, 4, 2, clip=True).form + pad_none(regulararray.to_typetracer(), 4, 2, clip=True).form + == pad_none(regulararray, 4, 2, clip=True).form ) - assert to_list(ak._do.pad_none(regulararray, 5, 2, clip=True)) == [ + assert to_list(pad_none(regulararray, 5, 2, clip=True)) == [ [[0.0, 1.1, 2.2, None, None], [None, None, None, None, None]], [[3.3, 4.4, None, None, None], [5.5, None, None, None, None]], [[6.6, 7.7, 8.8, 9.9, None], [None, None, None, None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 5, 2, clip=True).form - == ak._do.pad_none(regulararray, 5, 2, clip=True).form + pad_none(regulararray.to_typetracer(), 5, 2, clip=True).form + == pad_none(regulararray, 5, 2, clip=True).form ) @@ -562,81 +515,57 @@ def test_rpad_regular_array(): indexedarray = ak.contents.indexedoptionarray.IndexedOptionArray(index, content) array = ak.contents.regulararray.RegularArray(indexedarray, 3, zeros_length=0) - assert to_list(ak._do.pad_none(array, 5, 0)) == [ + assert to_list(pad_none(array, 5, 0)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], None, None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 0).form - == ak._do.pad_none(array, 5, 0).form - ) - assert to_list(ak._do.pad_none(array, 4, 0)) == [ + assert pad_none(array.to_typetracer(), 5, 0).form == pad_none(array, 5, 0).form + assert to_list(pad_none(array, 4, 0)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 4, 0).form - == ak._do.pad_none(array, 4, 0).form - ) - assert to_list(ak._do.pad_none(array, 3, 0)) == [ + assert pad_none(array.to_typetracer(), 4, 0).form == pad_none(array, 4, 0).form + assert to_list(pad_none(array, 3, 0)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 3, 0).form - == ak._do.pad_none(array, 3, 0).form - ) - assert to_list(ak._do.pad_none(array, 1, 0)) == [ + assert pad_none(array.to_typetracer(), 3, 0).form == pad_none(array, 3, 0).form + assert to_list(pad_none(array, 1, 0)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 1, 0).form - == ak._do.pad_none(array, 1, 0).form - ) - assert to_list(ak._do.pad_none(array, 5, 1)) == [ + assert pad_none(array.to_typetracer(), 1, 0).form == pad_none(array, 1, 0).form + assert to_list(pad_none(array, 5, 1)) == [ [6.9, 3.9, 6.9, None, None], [2.2, 1.5, 1.6, None, None], [3.6, None, 6.7, None, None], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 1).form - == ak._do.pad_none(array, 5, 1).form - ) - assert to_list(ak._do.pad_none(array, 4, 1)) == [ + assert pad_none(array.to_typetracer(), 5, 1).form == pad_none(array, 5, 1).form + assert to_list(pad_none(array, 4, 1)) == [ [6.9, 3.9, 6.9, None], [2.2, 1.5, 1.6, None], [3.6, None, 6.7, None], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 4, 1).form - == ak._do.pad_none(array, 4, 1).form - ) - assert to_list(ak._do.pad_none(array, 3, 1)) == [ + assert pad_none(array.to_typetracer(), 4, 1).form == pad_none(array, 4, 1).form + assert to_list(pad_none(array, 3, 1)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 3, 1).form - == ak._do.pad_none(array, 3, 1).form - ) - assert to_list(ak._do.pad_none(array, 1, 1)) == [ + assert pad_none(array.to_typetracer(), 3, 1).form == pad_none(array, 3, 1).form + assert to_list(pad_none(array, 1, 1)) == [ [6.9, 3.9, 6.9], [2.2, 1.5, 1.6], [3.6, None, 6.7], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 1, 1).form - == ak._do.pad_none(array, 1, 1).form - ) + assert pad_none(array.to_typetracer(), 1, 1).form == pad_none(array, 1, 1).form content = ak.contents.numpyarray.NumpyArray( np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) @@ -647,35 +576,35 @@ def test_rpad_regular_array(): listoffsetarray, 2, zeros_length=0 ) - assert to_list(ak._do.pad_none(regulararray, 1, 0)) == [ + assert to_list(pad_none(regulararray, 1, 0)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 1, 0).form - == ak._do.pad_none(regulararray, 1, 0).form + pad_none(regulararray.to_typetracer(), 1, 0).form + == pad_none(regulararray, 1, 0).form ) - assert to_list(ak._do.pad_none(regulararray, 3, 0)) == [ + assert to_list(pad_none(regulararray, 3, 0)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 3, 0).form - == ak._do.pad_none(regulararray, 3, 0).form + pad_none(regulararray.to_typetracer(), 3, 0).form + == pad_none(regulararray, 3, 0).form ) - assert to_list(ak._do.pad_none(regulararray, 4, 0)) == [ + assert to_list(pad_none(regulararray, 4, 0)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], None, ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 4, 0).form - == ak._do.pad_none(regulararray, 4, 0).form + pad_none(regulararray.to_typetracer(), 4, 0).form + == pad_none(regulararray, 4, 0).form ) - assert to_list(ak._do.pad_none(regulararray, 7, 0)) == [ + assert to_list(pad_none(regulararray, 7, 0)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], @@ -685,91 +614,91 @@ def test_rpad_regular_array(): None, ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 7, 0).form - == ak._do.pad_none(regulararray, 7, 0).form + pad_none(regulararray.to_typetracer(), 7, 0).form + == pad_none(regulararray, 7, 0).form ) - assert to_list(ak._do.pad_none(regulararray, 1, 1)) == [ + assert to_list(pad_none(regulararray, 1, 1)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 1, 1).form - == ak._do.pad_none(regulararray, 1, 1).form + pad_none(regulararray.to_typetracer(), 1, 1).form + == pad_none(regulararray, 1, 1).form ) - assert to_list(ak._do.pad_none(regulararray, 2, 1)) == [ + assert to_list(pad_none(regulararray, 2, 1)) == [ [[0.0, 1.1, 2.2], []], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], []], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 2, 1).form - == ak._do.pad_none(regulararray, 2, 1).form + pad_none(regulararray.to_typetracer(), 2, 1).form + == pad_none(regulararray, 2, 1).form ) - assert to_list(ak._do.pad_none(regulararray, 3, 1)) == [ + assert to_list(pad_none(regulararray, 3, 1)) == [ [[0.0, 1.1, 2.2], [], None], [[3.3, 4.4], [5.5], None], [[6.6, 7.7, 8.8, 9.9], [], None], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 3, 1).form - == ak._do.pad_none(regulararray, 3, 1).form + pad_none(regulararray.to_typetracer(), 3, 1).form + == pad_none(regulararray, 3, 1).form ) - assert to_list(ak._do.pad_none(regulararray, 5, 1)) == [ + assert to_list(pad_none(regulararray, 5, 1)) == [ [[0.0, 1.1, 2.2], [], None, None, None], [[3.3, 4.4], [5.5], None, None, None], [[6.6, 7.7, 8.8, 9.9], [], None, None, None], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 5, 1).form - == ak._do.pad_none(regulararray, 5, 1).form + pad_none(regulararray.to_typetracer(), 5, 1).form + == pad_none(regulararray, 5, 1).form ) - assert to_list(ak._do.pad_none(regulararray, 7, 1)) == [ + assert to_list(pad_none(regulararray, 7, 1)) == [ [[0.0, 1.1, 2.2], [], None, None, None, None, None], [[3.3, 4.4], [5.5], None, None, None, None, None], [[6.6, 7.7, 8.8, 9.9], [], None, None, None, None, None], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 7, 1).form - == ak._do.pad_none(regulararray, 7, 1).form + pad_none(regulararray.to_typetracer(), 7, 1).form + == pad_none(regulararray, 7, 1).form ) - assert to_list(ak._do.pad_none(regulararray, 1, 2)) == [ + assert to_list(pad_none(regulararray, 1, 2)) == [ [[0.0, 1.1, 2.2], [None]], [[3.3, 4.4], [5.5]], [[6.6, 7.7, 8.8, 9.9], [None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 1, 2).form - == ak._do.pad_none(regulararray, 1, 2).form + pad_none(regulararray.to_typetracer(), 1, 2).form + == pad_none(regulararray, 1, 2).form ) - assert to_list(ak._do.pad_none(regulararray, 2, 2)) == [ + assert to_list(pad_none(regulararray, 2, 2)) == [ [[0.0, 1.1, 2.2], [None, None]], [[3.3, 4.4], [5.5, None]], [[6.6, 7.7, 8.8, 9.9], [None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 2, 2).form - == ak._do.pad_none(regulararray, 2, 2).form + pad_none(regulararray.to_typetracer(), 2, 2).form + == pad_none(regulararray, 2, 2).form ) - assert to_list(ak._do.pad_none(regulararray, 3, 2)) == [ + assert to_list(pad_none(regulararray, 3, 2)) == [ [[0.0, 1.1, 2.2], [None, None, None]], [[3.3, 4.4, None], [5.5, None, None]], [[6.6, 7.7, 8.8, 9.9], [None, None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 3, 2).form - == ak._do.pad_none(regulararray, 3, 2).form + pad_none(regulararray.to_typetracer(), 3, 2).form + == pad_none(regulararray, 3, 2).form ) - assert to_list(ak._do.pad_none(regulararray, 4, 2)) == [ + assert to_list(pad_none(regulararray, 4, 2)) == [ [[0.0, 1.1, 2.2, None], [None, None, None, None]], [[3.3, 4.4, None, None], [5.5, None, None, None]], [[6.6, 7.7, 8.8, 9.9], [None, None, None, None]], ] assert ( - ak._do.pad_none(regulararray.to_typetracer(), 4, 2).form - == ak._do.pad_none(regulararray, 4, 2).form + pad_none(regulararray.to_typetracer(), 4, 2).form + == pad_none(regulararray, 4, 2).form ) @@ -788,20 +717,20 @@ def test_rpad_and_clip_listoffset_array(): [], ] - assert to_list(ak._do.pad_none(listoffsetarray, 3, 0, clip=True)) == [ + assert to_list(pad_none(listoffsetarray, 3, 0, clip=True)) == [ [0.0, 1.1, 2.2], [], [3.3, 4.4], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 3, 0, clip=True).form - == ak._do.pad_none(listoffsetarray, 3, 0, clip=True).form + pad_none(listoffsetarray.to_typetracer(), 3, 0, clip=True).form + == pad_none(listoffsetarray, 3, 0, clip=True).form ) assert "option[" + str(listoffsetarray.form.type) + "]" == str( - ak._do.pad_none(listoffsetarray, 3, 0, clip=True).form.type + pad_none(listoffsetarray, 3, 0, clip=True).form.type ) - assert to_list(ak._do.pad_none(listoffsetarray, 7, 0, clip=True)) == [ + assert to_list(pad_none(listoffsetarray, 7, 0, clip=True)) == [ [0.0, 1.1, 2.2], [], [3.3, 4.4], @@ -811,14 +740,14 @@ def test_rpad_and_clip_listoffset_array(): None, ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 7, 0, clip=True).form - == ak._do.pad_none(listoffsetarray, 7, 0, clip=True).form + pad_none(listoffsetarray.to_typetracer(), 7, 0, clip=True).form + == pad_none(listoffsetarray, 7, 0, clip=True).form ) assert "option[" + str(listoffsetarray.form.type) + "]" == str( - ak._do.pad_none(listoffsetarray, 7, 0, clip=True).form.type + pad_none(listoffsetarray, 7, 0, clip=True).form.type ) - assert to_list(ak._do.pad_none(listoffsetarray, 5, 1, clip=True)) == [ + assert to_list(pad_none(listoffsetarray, 5, 1, clip=True)) == [ [0.0, 1.1, 2.2, None, None], [None, None, None, None, None], [3.3, 4.4, None, None, None], @@ -827,17 +756,14 @@ def test_rpad_and_clip_listoffset_array(): [None, None, None, None, None], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 5, 1, clip=True).form - == ak._do.pad_none(listoffsetarray, 5, 1, clip=True).form + pad_none(listoffsetarray.to_typetracer(), 5, 1, clip=True).form + == pad_none(listoffsetarray, 5, 1, clip=True).form ) - assert str(ak._do.pad_none(listoffsetarray, 5, 1).form.type) == "var * ?float64" - assert ( - str(ak._do.pad_none(listoffsetarray, 5, 1, clip=True).form.type) - == "5 * ?float64" - ) + assert str(pad_none(listoffsetarray, 5, 1).form.type) == "var * ?float64" + assert str(pad_none(listoffsetarray, 5, 1, clip=True).form.type) == "5 * ?float64" - assert to_list(ak._do.pad_none(listoffsetarray, 1, 1, clip=True)) == [ + assert to_list(pad_none(listoffsetarray, 1, 1, clip=True)) == [ [0.0], [None], [3.3], @@ -846,8 +772,8 @@ def test_rpad_and_clip_listoffset_array(): [None], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(listoffsetarray, 1, 1, clip=True).form + pad_none(listoffsetarray.to_typetracer(), 1, 1, clip=True).form + == pad_none(listoffsetarray, 1, 1, clip=True).form ) content = ak.contents.numpyarray.NumpyArray(np.array([1.5, 3.3])) @@ -896,12 +822,12 @@ def test_rpad_and_clip_listoffset_array(): [], [], ] - assert to_list(ak._do.pad_none(listoffsetarray, 1, 0, clip=True)) == [[3.3]] + assert to_list(pad_none(listoffsetarray, 1, 0, clip=True)) == [[3.3]] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 1, 0, clip=True).form - == ak._do.pad_none(listoffsetarray, 1, 0, clip=True).form + pad_none(listoffsetarray.to_typetracer(), 1, 0, clip=True).form + == pad_none(listoffsetarray, 1, 0, clip=True).form ) - assert to_list(ak._do.pad_none(listoffsetarray, 1, 1, clip=True)) == [ + assert to_list(pad_none(listoffsetarray, 1, 1, clip=True)) == [ [3.3], [None], [None], @@ -910,8 +836,8 @@ def test_rpad_and_clip_listoffset_array(): [None], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(listoffsetarray, 1, 1, clip=True).form + pad_none(listoffsetarray.to_typetracer(), 1, 1, clip=True).form + == pad_none(listoffsetarray, 1, 1, clip=True).form ) @@ -931,7 +857,7 @@ def test_rpad_listoffset_array(): [], ] - assert to_list(ak._do.pad_none(listoffsetarray, 3, 0)) == [ + assert to_list(pad_none(listoffsetarray, 3, 0)) == [ [0.0, 1.1, 2.2], [], [3.3, 4.4], @@ -940,15 +866,15 @@ def test_rpad_listoffset_array(): [], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 3, 0).form - == ak._do.pad_none(listoffsetarray, 3, 0).form + pad_none(listoffsetarray.to_typetracer(), 3, 0).form + == pad_none(listoffsetarray, 3, 0).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 6 - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 3, 0)) + ) == ak.operations.type(pad_none(listoffsetarray, 3, 0)) - assert to_list(ak._do.pad_none(listoffsetarray, 7, 0)) == [ + assert to_list(pad_none(listoffsetarray, 7, 0)) == [ [0.0, 1.1, 2.2], [], [3.3, 4.4], @@ -958,15 +884,15 @@ def test_rpad_listoffset_array(): None, ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 7, 0).form - == ak._do.pad_none(listoffsetarray, 7, 0).form + pad_none(listoffsetarray.to_typetracer(), 7, 0).form + == pad_none(listoffsetarray, 7, 0).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 7 - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 7, 0)) + ) == ak.operations.type(pad_none(listoffsetarray, 7, 0)) - assert to_list(ak._do.pad_none(listoffsetarray, 5, 1)) == [ + assert to_list(pad_none(listoffsetarray, 5, 1)) == [ [0.0, 1.1, 2.2, None, None], [None, None, None, None, None], [3.3, 4.4, None, None, None], @@ -975,16 +901,14 @@ def test_rpad_listoffset_array(): [None, None, None, None, None], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 5, 1).form - == ak._do.pad_none(listoffsetarray, 5, 1).form + pad_none(listoffsetarray.to_typetracer(), 5, 1).form + == pad_none(listoffsetarray, 5, 1).form ) - assert ak.operations.type( - ak._do.pad_none(listoffsetarray, 5, 1) - ) == ak.types.ArrayType( + assert ak.operations.type(pad_none(listoffsetarray, 5, 1)) == ak.types.ArrayType( ak.types.ListType(ak.types.OptionType(ak.types.NumpyType("float64"))), 6 ) - assert to_list(ak._do.pad_none(listoffsetarray, 1, 1)) == [ + assert to_list(pad_none(listoffsetarray, 1, 1)) == [ [0.0, 1.1, 2.2], [None], [3.3, 4.4], @@ -993,8 +917,8 @@ def test_rpad_listoffset_array(): [None], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 1, 1).form - == ak._do.pad_none(listoffsetarray, 1, 1).form + pad_none(listoffsetarray.to_typetracer(), 1, 1).form + == pad_none(listoffsetarray, 1, 1).form ) content = ak.contents.numpyarray.NumpyArray(np.array([1.5, 3.3])) @@ -1044,7 +968,7 @@ def test_rpad_listoffset_array(): [], ] - assert to_list(ak._do.pad_none(listoffsetarray, 1, 0)) == [ + assert to_list(pad_none(listoffsetarray, 1, 0)) == [ [3.3], [], [], @@ -1053,17 +977,17 @@ def test_rpad_listoffset_array(): [], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 1, 0).form - == ak._do.pad_none(listoffsetarray, 1, 0).form + pad_none(listoffsetarray.to_typetracer(), 1, 0).form + == pad_none(listoffsetarray, 1, 0).form ) assert ak.types.ArrayType( ak.types.OptionType( ak.types.ListType(ak.types.OptionType(ak.types.NumpyType("float64"))) ), 6, - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 1, 0)) + ) == ak.operations.type(pad_none(listoffsetarray, 1, 0)) - assert to_list(ak._do.pad_none(listoffsetarray, 6, 0)) == [ + assert to_list(pad_none(listoffsetarray, 6, 0)) == [ [3.3], [], [], @@ -1072,17 +996,17 @@ def test_rpad_listoffset_array(): [], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 6, 0).form - == ak._do.pad_none(listoffsetarray, 6, 0).form + pad_none(listoffsetarray.to_typetracer(), 6, 0).form + == pad_none(listoffsetarray, 6, 0).form ) assert ak.types.ArrayType( ak.types.OptionType( ak.types.ListType(ak.types.OptionType(ak.types.NumpyType("float64"))) ), 6, - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 6, 0)) + ) == ak.operations.type(pad_none(listoffsetarray, 6, 0)) - assert to_list(ak._do.pad_none(listoffsetarray, 7, 0)) == [ + assert to_list(pad_none(listoffsetarray, 7, 0)) == [ [3.3], [], [], @@ -1092,14 +1016,14 @@ def test_rpad_listoffset_array(): None, ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 7, 0).form - == ak._do.pad_none(listoffsetarray, 7, 0).form + pad_none(listoffsetarray.to_typetracer(), 7, 0).form + == pad_none(listoffsetarray, 7, 0).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.operations.type(listoffsetarray).content), 7 - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 7, 0)) + ) == ak.operations.type(pad_none(listoffsetarray, 7, 0)) - assert to_list(ak._do.pad_none(listoffsetarray, 9, 0)) == [ + assert to_list(pad_none(listoffsetarray, 9, 0)) == [ [3.3], [], [], @@ -1111,14 +1035,14 @@ def test_rpad_listoffset_array(): None, ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 9, 0).form - == ak._do.pad_none(listoffsetarray, 9, 0).form + pad_none(listoffsetarray.to_typetracer(), 9, 0).form + == pad_none(listoffsetarray, 9, 0).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.operations.type(listoffsetarray).content), 9 - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 9, 0)) + ) == ak.operations.type(pad_none(listoffsetarray, 9, 0)) - assert to_list(ak._do.pad_none(listoffsetarray, 1, 1)) == [ + assert to_list(pad_none(listoffsetarray, 1, 1)) == [ [3.3], [None], [None], @@ -1127,14 +1051,14 @@ def test_rpad_listoffset_array(): [None], ] assert ( - ak._do.pad_none(listoffsetarray.to_typetracer(), 1, 1).form - == ak._do.pad_none(listoffsetarray, 1, 1).form + pad_none(listoffsetarray.to_typetracer(), 1, 1).form + == pad_none(listoffsetarray, 1, 1).form ) assert ak.types.ArrayType( ak.types.ListType(ak.types.OptionType(ak.types.NumpyType("float64"))), 6 - ) == ak.operations.type(ak._do.pad_none(listoffsetarray, 1, 1)) + ) == ak.operations.type(pad_none(listoffsetarray, 1, 1)) - assert to_list(ak._do.pad_none(listoffsetarray, 4, 1)) == [ + assert to_list(pad_none(listoffsetarray, 4, 1)) == [ [3.3, None, None, None], [None, None, None, None], [None, None, None, None], @@ -1143,7 +1067,7 @@ def test_rpad_listoffset_array(): [None, None, None, None], ] assert ak.operations.type(listoffsetarray) == ak.operations.type( - ak._do.pad_none(listoffsetarray, 4, 1) + pad_none(listoffsetarray, 4, 1) ) @@ -1162,7 +1086,7 @@ def test_rpad_list_array(): [5.5, 6.6, 7.7], [8.8], ] - assert to_list(ak._do.pad_none(array, 1, 0)) == [ + assert to_list(pad_none(array, 1, 0)) == [ [0.0, 1.1, 2.2], [], [4.4, 5.5], @@ -1171,9 +1095,9 @@ def test_rpad_list_array(): ] assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 5 - ) == ak.operations.type(ak._do.pad_none(array, 1, 0)) + ) == ak.operations.type(pad_none(array, 1, 0)) - assert to_list(ak._do.pad_none(array, 2, 0)) == [ + assert to_list(pad_none(array, 2, 0)) == [ [0.0, 1.1, 2.2], [], [4.4, 5.5], @@ -1182,9 +1106,9 @@ def test_rpad_list_array(): ] assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 5 - ) == ak.operations.type(ak._do.pad_none(array, 2, 0)) + ) == ak.operations.type(pad_none(array, 2, 0)) - assert to_list(ak._do.pad_none(array, 7, 0)) == [ + assert to_list(pad_none(array, 7, 0)) == [ [0.0, 1.1, 2.2], [], [4.4, 5.5], @@ -1195,9 +1119,9 @@ def test_rpad_list_array(): ] assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 7 - ) == ak.operations.type(ak._do.pad_none(array, 7, 0)) + ) == ak.operations.type(pad_none(array, 7, 0)) - assert to_list(ak._do.pad_none(array, 1, 1)) == [ + assert to_list(pad_none(array, 1, 1)) == [ [0.0, 1.1, 2.2], [None], [4.4, 5.5], @@ -1205,7 +1129,7 @@ def test_rpad_list_array(): [8.8], ] - assert to_list(ak._do.pad_none(array, 2, 1)) == [ + assert to_list(pad_none(array, 2, 1)) == [ [0.0, 1.1, 2.2], [None, None], [4.4, 5.5], @@ -1213,7 +1137,7 @@ def test_rpad_list_array(): [8.8, None], ] - assert to_list(ak._do.pad_none(array, 3, 1)) == [ + assert to_list(pad_none(array, 3, 1)) == [ [0.0, 1.1, 2.2], [None, None, None], [4.4, 5.5, None], @@ -1221,7 +1145,7 @@ def test_rpad_list_array(): [8.8, None, None], ] - assert to_list(ak._do.pad_none(array, 4, 1)) == [ + assert to_list(pad_none(array, 4, 1)) == [ [0.0, 1.1, 2.2, None], [None, None, None, None], [4.4, 5.5, None, None], @@ -1245,25 +1169,25 @@ def test_rpad_and_clip_list_array(): [5.5, 6.6, 7.7], [8.8], ] - assert to_list(ak._do.pad_none(array, 1, 0, clip=True)) == [[0.0, 1.1, 2.2]] + assert to_list(pad_none(array, 1, 0, clip=True)) == [[0.0, 1.1, 2.2]] assert ( - ak._do.pad_none(array.to_typetracer(), 1, 0, clip=True).form - == ak._do.pad_none(array, 1, 0, clip=True).form + pad_none(array.to_typetracer(), 1, 0, clip=True).form + == pad_none(array, 1, 0, clip=True).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 1 - ) == ak.operations.type(ak._do.pad_none(array, 1, 0, clip=True)) + ) == ak.operations.type(pad_none(array, 1, 0, clip=True)) - assert to_list(ak._do.pad_none(array, 2, 0, clip=True)) == [[0.0, 1.1, 2.2], []] + assert to_list(pad_none(array, 2, 0, clip=True)) == [[0.0, 1.1, 2.2], []] assert ( - ak._do.pad_none(array.to_typetracer(), 2, 0, clip=True).form - == ak._do.pad_none(array, 2, 0, clip=True).form + pad_none(array.to_typetracer(), 2, 0, clip=True).form + == pad_none(array, 2, 0, clip=True).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 2 - ) == ak.operations.type(ak._do.pad_none(array, 2, 0, clip=True)) + ) == ak.operations.type(pad_none(array, 2, 0, clip=True)) - assert to_list(ak._do.pad_none(array, 7, 0, clip=True)) == [ + assert to_list(pad_none(array, 7, 0, clip=True)) == [ [0.0, 1.1, 2.2], [], [4.4, 5.5], @@ -1273,14 +1197,14 @@ def test_rpad_and_clip_list_array(): None, ] assert ( - ak._do.pad_none(array.to_typetracer(), 7, 0, clip=True).form - == ak._do.pad_none(array, 7, 0, clip=True).form + pad_none(array.to_typetracer(), 7, 0, clip=True).form + == pad_none(array, 7, 0, clip=True).form ) assert ak.types.ArrayType( ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("float64"))), 7 - ) == ak.operations.type(ak._do.pad_none(array, 7, 0, clip=True)) + ) == ak.operations.type(pad_none(array, 7, 0, clip=True)) - assert to_list(ak._do.pad_none(array, 1, 1, clip=True)) == [ + assert to_list(pad_none(array, 1, 1, clip=True)) == [ [0.0], [None], [4.4], @@ -1288,11 +1212,11 @@ def test_rpad_and_clip_list_array(): [8.8], ] assert ( - ak._do.pad_none(array.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(array, 1, 1, clip=True).form + pad_none(array.to_typetracer(), 1, 1, clip=True).form + == pad_none(array, 1, 1, clip=True).form ) - assert to_list(ak._do.pad_none(array, 2, 1, clip=True)) == [ + assert to_list(pad_none(array, 2, 1, clip=True)) == [ [0.0, 1.1], [None, None], [4.4, 5.5], @@ -1300,8 +1224,8 @@ def test_rpad_and_clip_list_array(): [8.8, None], ] assert ( - ak._do.pad_none(array.to_typetracer(), 2, 1, clip=True).form - == ak._do.pad_none(array, 2, 1, clip=True).form + pad_none(array.to_typetracer(), 2, 1, clip=True).form + == pad_none(array, 2, 1, clip=True).form ) @@ -1328,17 +1252,15 @@ def test_rpad_indexed_array(): [0.0, 1.1, 2.2], ] - assert to_list(ak._do.pad_none(backward, 4, 1)) == to_list( - ak._do.pad_none(indexedarray, 4, 1) - ) - assert to_list(ak._do.pad_none(indexedarray, 1, 0)) == [ + assert to_list(pad_none(backward, 4, 1)) == to_list(pad_none(indexedarray, 4, 1)) + assert to_list(pad_none(indexedarray, 1, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], [], [0.0, 1.1, 2.2], ] - assert to_list(ak._do.pad_none(indexedarray, 2, 1)) == [ + assert to_list(pad_none(indexedarray, 2, 1)) == [ [6.6, 7.7, 8.8, 9.9], [5.5, None], [3.3, 4.4], @@ -1346,10 +1268,10 @@ def test_rpad_indexed_array(): [0.0, 1.1, 2.2], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 2, 1).form - == ak._do.pad_none(indexedarray, 2, 1).form + pad_none(indexedarray.to_typetracer(), 2, 1).form + == pad_none(indexedarray, 2, 1).form ) - assert to_list(ak._do.pad_none(indexedarray, 3, 1)) == [ + assert to_list(pad_none(indexedarray, 3, 1)) == [ [6.6, 7.7, 8.8, 9.9], [5.5, None, None], [3.3, 4.4, None], @@ -1357,10 +1279,10 @@ def test_rpad_indexed_array(): [0.0, 1.1, 2.2], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 3, 1).form - == ak._do.pad_none(indexedarray, 3, 1).form + pad_none(indexedarray.to_typetracer(), 3, 1).form + == pad_none(indexedarray, 3, 1).form ) - assert to_list(ak._do.pad_none(indexedarray, 4, 0)) == [ + assert to_list(pad_none(indexedarray, 4, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1368,10 +1290,10 @@ def test_rpad_indexed_array(): [0.0, 1.1, 2.2], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 4, 0).form - == ak._do.pad_none(indexedarray, 4, 0).form + pad_none(indexedarray.to_typetracer(), 4, 0).form + == pad_none(indexedarray, 4, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 5, 0)) == [ + assert to_list(pad_none(indexedarray, 5, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1379,10 +1301,10 @@ def test_rpad_indexed_array(): [0.0, 1.1, 2.2], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 5, 0).form - == ak._do.pad_none(indexedarray, 5, 0).form + pad_none(indexedarray.to_typetracer(), 5, 0).form + == pad_none(indexedarray, 5, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 6, 0)) == [ + assert to_list(pad_none(indexedarray, 6, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1391,10 +1313,10 @@ def test_rpad_indexed_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 6, 0).form - == ak._do.pad_none(indexedarray, 6, 0).form + pad_none(indexedarray.to_typetracer(), 6, 0).form + == pad_none(indexedarray, 6, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 7, 0)) == [ + assert to_list(pad_none(indexedarray, 7, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1404,8 +1326,8 @@ def test_rpad_indexed_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 7, 0).form - == ak._do.pad_none(indexedarray, 7, 0).form + pad_none(indexedarray.to_typetracer(), 7, 0).form + == pad_none(indexedarray, 7, 0).form ) @@ -1431,44 +1353,42 @@ def test_rpad_and_clip_indexed_array(): [0.0, 1.1, 2.2], ] - assert to_list(ak._do.pad_none(backward, 4, 1, clip=True)) == to_list( - ak._do.pad_none(indexedarray, 4, 1, clip=True) + assert to_list(pad_none(backward, 4, 1, clip=True)) == to_list( + pad_none(indexedarray, 4, 1, clip=True) ) - assert to_list(ak._do.pad_none(indexedarray, 1, 0, clip=True)) == [ - [6.6, 7.7, 8.8, 9.9] - ] + assert to_list(pad_none(indexedarray, 1, 0, clip=True)) == [[6.6, 7.7, 8.8, 9.9]] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 1, 0, clip=True).form - == ak._do.pad_none(indexedarray, 1, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 1, 0, clip=True).form + == pad_none(indexedarray, 1, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 2, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 2, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 2, 0, clip=True).form - == ak._do.pad_none(indexedarray, 2, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 2, 0, clip=True).form + == pad_none(indexedarray, 2, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 3, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 3, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 3, 0, clip=True).form - == ak._do.pad_none(indexedarray, 3, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 3, 0, clip=True).form + == pad_none(indexedarray, 3, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 4, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 4, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], [], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 4, 0, clip=True).form - == ak._do.pad_none(indexedarray, 4, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 4, 0, clip=True).form + == pad_none(indexedarray, 4, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 5, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 5, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1476,10 +1396,10 @@ def test_rpad_and_clip_indexed_array(): [0.0, 1.1, 2.2], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 5, 0, clip=True).form - == ak._do.pad_none(indexedarray, 5, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 5, 0, clip=True).form + == pad_none(indexedarray, 5, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 6, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 6, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1488,10 +1408,10 @@ def test_rpad_and_clip_indexed_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 6, 0, clip=True).form - == ak._do.pad_none(indexedarray, 6, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 6, 0, clip=True).form + == pad_none(indexedarray, 6, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 7, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 7, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1501,10 +1421,10 @@ def test_rpad_and_clip_indexed_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 7, 0, clip=True).form - == ak._do.pad_none(indexedarray, 7, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 7, 0, clip=True).form + == pad_none(indexedarray, 7, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 8, 0, clip=True)) == [ + assert to_list(pad_none(indexedarray, 8, 0, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1515,11 +1435,11 @@ def test_rpad_and_clip_indexed_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 8, 0, clip=True).form - == ak._do.pad_none(indexedarray, 8, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 8, 0, clip=True).form + == pad_none(indexedarray, 8, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 1, 1, clip=True)) == [ + assert to_list(pad_none(indexedarray, 1, 1, clip=True)) == [ [6.6], [5.5], [3.3], @@ -1527,10 +1447,10 @@ def test_rpad_and_clip_indexed_array(): [0.0], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(indexedarray, 1, 1, clip=True).form + pad_none(indexedarray.to_typetracer(), 1, 1, clip=True).form + == pad_none(indexedarray, 1, 1, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 2, 1, clip=True)) == [ + assert to_list(pad_none(indexedarray, 2, 1, clip=True)) == [ [6.6, 7.7], [5.5, None], [3.3, 4.4], @@ -1538,10 +1458,10 @@ def test_rpad_and_clip_indexed_array(): [0.0, 1.1], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 2, 1, clip=True).form - == ak._do.pad_none(indexedarray, 2, 1, clip=True).form + pad_none(indexedarray.to_typetracer(), 2, 1, clip=True).form + == pad_none(indexedarray, 2, 1, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 3, 1, clip=True)) == [ + assert to_list(pad_none(indexedarray, 3, 1, clip=True)) == [ [6.6, 7.7, 8.8], [5.5, None, None], [3.3, 4.4, None], @@ -1549,10 +1469,10 @@ def test_rpad_and_clip_indexed_array(): [0.0, 1.1, 2.2], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 3, 1, clip=True).form - == ak._do.pad_none(indexedarray, 3, 1, clip=True).form + pad_none(indexedarray.to_typetracer(), 3, 1, clip=True).form + == pad_none(indexedarray, 3, 1, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 4, 1, clip=True)) == [ + assert to_list(pad_none(indexedarray, 4, 1, clip=True)) == [ [6.6, 7.7, 8.8, 9.9], [5.5, None, None, None], [3.3, 4.4, None, None], @@ -1560,10 +1480,10 @@ def test_rpad_and_clip_indexed_array(): [0.0, 1.1, 2.2, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 4, 1, clip=True).form - == ak._do.pad_none(indexedarray, 4, 1, clip=True).form + pad_none(indexedarray.to_typetracer(), 4, 1, clip=True).form + == pad_none(indexedarray, 4, 1, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 5, 1, clip=True)) == [ + assert to_list(pad_none(indexedarray, 5, 1, clip=True)) == [ [6.6, 7.7, 8.8, 9.9, None], [5.5, None, None, None, None], [3.3, 4.4, None, None, None], @@ -1571,8 +1491,8 @@ def test_rpad_and_clip_indexed_array(): [0.0, 1.1, 2.2, None, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 5, 1, clip=True).form - == ak._do.pad_none(indexedarray, 5, 1, clip=True).form + pad_none(indexedarray.to_typetracer(), 5, 1, clip=True).form + == pad_none(indexedarray, 5, 1, clip=True).form ) @@ -1630,10 +1550,8 @@ def test_rpad_indexed_option_array(): [0.0, None, None], ] - assert to_list(ak._do.pad_none(backward, 4, 1)) == to_list( - ak._do.pad_none(indexedarray, 4, 1) - ) - assert to_list(ak._do.pad_none(indexedarray, 1, 0)) == [ + assert to_list(pad_none(backward, 4, 1)) == to_list(pad_none(indexedarray, 4, 1)) + assert to_list(pad_none(indexedarray, 1, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1641,10 +1559,10 @@ def test_rpad_indexed_option_array(): [0.0, None, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 1, 0).form - == ak._do.pad_none(indexedarray, 1, 0).form + pad_none(indexedarray.to_typetracer(), 1, 0).form + == pad_none(indexedarray, 1, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 1, 1)) == [ + assert to_list(pad_none(indexedarray, 1, 1)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1652,10 +1570,10 @@ def test_rpad_indexed_option_array(): [0.0, None, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 1, 1).form - == ak._do.pad_none(indexedarray, 1, 1).form + pad_none(indexedarray.to_typetracer(), 1, 1).form + == pad_none(indexedarray, 1, 1).form ) - assert to_list(ak._do.pad_none(indexedarray, 3, 1)) == [ + assert to_list(pad_none(indexedarray, 3, 1)) == [ [6.6, 7.7, 8.8, 9.9], [5.5, None, None], [3.3, 4.4, None], @@ -1663,10 +1581,10 @@ def test_rpad_indexed_option_array(): [0.0, None, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 3, 1).form - == ak._do.pad_none(indexedarray, 3, 1).form + pad_none(indexedarray.to_typetracer(), 3, 1).form + == pad_none(indexedarray, 3, 1).form ) - assert to_list(ak._do.pad_none(indexedarray, 4, 0)) == [ + assert to_list(pad_none(indexedarray, 4, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1674,10 +1592,10 @@ def test_rpad_indexed_option_array(): [0.0, None, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 4, 0).form - == ak._do.pad_none(indexedarray, 4, 0).form + pad_none(indexedarray.to_typetracer(), 4, 0).form + == pad_none(indexedarray, 4, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 5, 0)) == [ + assert to_list(pad_none(indexedarray, 5, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1685,10 +1603,10 @@ def test_rpad_indexed_option_array(): [0.0, None, None], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 5, 0).form - == ak._do.pad_none(indexedarray, 5, 0).form + pad_none(indexedarray.to_typetracer(), 5, 0).form + == pad_none(indexedarray, 5, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 6, 0)) == [ + assert to_list(pad_none(indexedarray, 6, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1697,10 +1615,10 @@ def test_rpad_indexed_option_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 6, 0).form - == ak._do.pad_none(indexedarray, 6, 0).form + pad_none(indexedarray.to_typetracer(), 6, 0).form + == pad_none(indexedarray, 6, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 7, 0)) == [ + assert to_list(pad_none(indexedarray, 7, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1710,10 +1628,10 @@ def test_rpad_indexed_option_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 7, 0).form - == ak._do.pad_none(indexedarray, 7, 0).form + pad_none(indexedarray.to_typetracer(), 7, 0).form + == pad_none(indexedarray, 7, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 8, 0)) == [ + assert to_list(pad_none(indexedarray, 8, 0)) == [ [6.6, 7.7, 8.8, 9.9], [5.5], [3.3, 4.4], @@ -1724,18 +1642,16 @@ def test_rpad_indexed_option_array(): None, ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 8, 0).form - == ak._do.pad_none(indexedarray, 8, 0).form + pad_none(indexedarray.to_typetracer(), 8, 0).form + == pad_none(indexedarray, 8, 0).form ) - assert to_list(ak._do.pad_none(indexedarray, 1, 0, clip=True)) == [ - [6.6, 7.7, 8.8, 9.9] - ] + assert to_list(pad_none(indexedarray, 1, 0, clip=True)) == [[6.6, 7.7, 8.8, 9.9]] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 1, 0, clip=True).form - == ak._do.pad_none(indexedarray, 1, 0, clip=True).form + pad_none(indexedarray.to_typetracer(), 1, 0, clip=True).form + == pad_none(indexedarray, 1, 0, clip=True).form ) - assert to_list(ak._do.pad_none(indexedarray, 1, 1, clip=True)) == [ + assert to_list(pad_none(indexedarray, 1, 1, clip=True)) == [ [6.6], [5.5], [3.3], @@ -1743,8 +1659,8 @@ def test_rpad_indexed_option_array(): [0.0], ] assert ( - ak._do.pad_none(indexedarray.to_typetracer(), 1, 1, clip=True).form - == ak._do.pad_none(indexedarray, 1, 1, clip=True).form + pad_none(indexedarray.to_typetracer(), 1, 1, clip=True).form + == pad_none(indexedarray, 1, 1, clip=True).form ) @@ -1759,27 +1675,21 @@ def test_rpad_recordarray(): contents = [content1, content2] array = ak.contents.recordarray.RecordArray(contents, keys) - assert to_list(ak._do.pad_none(array, 5, 0)) == [ + assert to_list(pad_none(array, 5, 0)) == [ {"x": [], "y": [2, 2]}, {"x": [1.1], "y": [1]}, {"x": [2.2, 2.2], "y": []}, None, None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 5, 0).form - == ak._do.pad_none(array, 5, 0).form - ) + assert pad_none(array.to_typetracer(), 5, 0).form == pad_none(array, 5, 0).form - assert to_list(ak._do.pad_none(array, 2, 1)) == [ + assert to_list(pad_none(array, 2, 1)) == [ {"x": [None, None], "y": [2, 2]}, {"x": [1.1, None], "y": [1, None]}, {"x": [2.2, 2.2], "y": [None, None]}, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 2, 1).form - == ak._do.pad_none(array, 2, 1).form - ) + assert pad_none(array.to_typetracer(), 2, 1).form == pad_none(array, 2, 1).form def test_rpad_unionarray(): @@ -1794,7 +1704,7 @@ def test_rpad_unionarray(): array = ak.contents.unionarray.UnionArray(tags, index, [content1, content2]) assert to_list(array) == [[], ["2", "2"], [1.1], ["1"], [2.2, 2.2], []] - assert to_list(ak._do.pad_none(array, 7, 0)) == [ + assert to_list(pad_none(array, 7, 0)) == [ [], ["2", "2"], [1.1], @@ -1803,12 +1713,9 @@ def test_rpad_unionarray(): [], None, ] - assert ( - ak._do.pad_none(array.to_typetracer(), 7, 0).form - == ak._do.pad_none(array, 7, 0).form - ) + assert pad_none(array.to_typetracer(), 7, 0).form == pad_none(array, 7, 0).form - assert to_list(ak._do.pad_none(array, 2, 1)) == [ + assert to_list(pad_none(array, 2, 1)) == [ [None, None], ["2", "2"], [1.1, None], @@ -1816,7 +1723,4 @@ def test_rpad_unionarray(): [2.2, 2.2], [None, None], ] - assert ( - ak._do.pad_none(array.to_typetracer(), 2, 1).form - == ak._do.pad_none(array, 2, 1).form - ) + assert pad_none(array.to_typetracer(), 2, 1).form == pad_none(array, 2, 1).form diff --git a/tests/test_1142_numbers_to_type.py b/tests/test_1142_numbers_to_type.py index c909dc71e0..976f82cb89 100644 --- a/tests/test_1142_numbers_to_type.py +++ b/tests/test_1142_numbers_to_type.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np import pytest # noqa: F401 import awkward as ak +from awkward._do.content import numbers_to_type def test_numbers_to_type(): @@ -14,250 +14,226 @@ def test_numbers_to_type(): ak.highlevel.Array([4, 5]).layout, ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "bool", False)).dtype == np.dtype( - np.bool_ - ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "int8", False)).dtype == np.dtype( - np.int8 - ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "uint8", False)).dtype == np.dtype( - np.uint8 - ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "int16", False)).dtype == np.dtype( - np.int16 - ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "uint16", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(one, "bool", False)).dtype == np.dtype(np.bool_) + assert ak.to_numpy(numbers_to_type(one, "int8", False)).dtype == np.dtype(np.int8) + assert ak.to_numpy(numbers_to_type(one, "uint8", False)).dtype == np.dtype(np.uint8) + assert ak.to_numpy(numbers_to_type(one, "int16", False)).dtype == np.dtype(np.int16) + assert ak.to_numpy(numbers_to_type(one, "uint16", False)).dtype == np.dtype( np.uint16 ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "int32", False)).dtype == np.dtype( - np.int32 - ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "uint32", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(one, "int32", False)).dtype == np.dtype(np.int32) + assert ak.to_numpy(numbers_to_type(one, "uint32", False)).dtype == np.dtype( np.uint32 ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "int64", False)).dtype == np.dtype( - np.int64 - ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "uint64", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(one, "int64", False)).dtype == np.dtype(np.int64) + assert ak.to_numpy(numbers_to_type(one, "uint64", False)).dtype == np.dtype( np.uint64 ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "float32", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(one, "float32", False)).dtype == np.dtype( np.float32 ) - assert ak.to_numpy(ak._do.numbers_to_type(one, "float64", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(one, "float64", False)).dtype == np.dtype( np.float64 ) + assert np.asarray(numbers_to_type(one, "complex64", False).data).dtype == np.dtype( + np.complex64 + ) + assert np.asarray(numbers_to_type(one, "complex128", False).data).dtype == np.dtype( + np.complex128 + ) + assert np.asarray(numbers_to_type(one, "datetime64", False).data).dtype == np.dtype( + np.datetime64 + ) assert np.asarray( - ak._do.numbers_to_type(one, "complex64", False).data - ).dtype == np.dtype(np.complex64) - assert np.asarray( - ak._do.numbers_to_type(one, "complex128", False).data - ).dtype == np.dtype(np.complex128) - assert np.asarray( - ak._do.numbers_to_type(one, "datetime64", False).data - ).dtype == np.dtype(np.datetime64) - assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[Y]", False).data + numbers_to_type(one, "datetime64[Y]", False).data ).dtype == np.dtype("datetime64[Y]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[M]", False).data + numbers_to_type(one, "datetime64[M]", False).data ).dtype == np.dtype("datetime64[M]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[W]", False).data + numbers_to_type(one, "datetime64[W]", False).data ).dtype == np.dtype("datetime64[W]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[D]", False).data + numbers_to_type(one, "datetime64[D]", False).data ).dtype == np.dtype("datetime64[D]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[h]", False).data + numbers_to_type(one, "datetime64[h]", False).data ).dtype == np.dtype("datetime64[h]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[m]", False).data + numbers_to_type(one, "datetime64[m]", False).data ).dtype == np.dtype("datetime64[m]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[s]", False).data + numbers_to_type(one, "datetime64[s]", False).data ).dtype == np.dtype("datetime64[s]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[ms]", False).data + numbers_to_type(one, "datetime64[ms]", False).data ).dtype == np.dtype("datetime64[ms]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[us]", False).data + numbers_to_type(one, "datetime64[us]", False).data ).dtype == np.dtype("datetime64[us]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[ns]", False).data + numbers_to_type(one, "datetime64[ns]", False).data ).dtype == np.dtype("datetime64[ns]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[ps]", False).data + numbers_to_type(one, "datetime64[ps]", False).data ).dtype == np.dtype("datetime64[ps]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[fs]", False).data + numbers_to_type(one, "datetime64[fs]", False).data ).dtype == np.dtype("datetime64[fs]") assert np.asarray( - ak._do.numbers_to_type(one, "datetime64[as]", False).data + numbers_to_type(one, "datetime64[as]", False).data ).dtype == np.dtype("datetime64[as]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64", False).data + numbers_to_type(one, "timedelta64", False).data ).dtype == np.dtype(np.timedelta64) assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[Y]", False).data + numbers_to_type(one, "timedelta64[Y]", False).data ).dtype == np.dtype("timedelta64[Y]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[M]", False).data + numbers_to_type(one, "timedelta64[M]", False).data ).dtype == np.dtype("timedelta64[M]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[W]", False).data + numbers_to_type(one, "timedelta64[W]", False).data ).dtype == np.dtype("timedelta64[W]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[D]", False).data + numbers_to_type(one, "timedelta64[D]", False).data ).dtype == np.dtype("timedelta64[D]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[h]", False).data + numbers_to_type(one, "timedelta64[h]", False).data ).dtype == np.dtype("timedelta64[h]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[m]", False).data + numbers_to_type(one, "timedelta64[m]", False).data ).dtype == np.dtype("timedelta64[m]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[s]", False).data + numbers_to_type(one, "timedelta64[s]", False).data ).dtype == np.dtype("timedelta64[s]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[ms]", False).data + numbers_to_type(one, "timedelta64[ms]", False).data ).dtype == np.dtype("timedelta64[ms]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[us]", False).data + numbers_to_type(one, "timedelta64[us]", False).data ).dtype == np.dtype("timedelta64[us]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[ns]", False).data + numbers_to_type(one, "timedelta64[ns]", False).data ).dtype == np.dtype("timedelta64[ns]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[ps]", False).data + numbers_to_type(one, "timedelta64[ps]", False).data ).dtype == np.dtype("timedelta64[ps]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[fs]", False).data + numbers_to_type(one, "timedelta64[fs]", False).data ).dtype == np.dtype("timedelta64[fs]") assert np.asarray( - ak._do.numbers_to_type(one, "timedelta64[as]", False).data + numbers_to_type(one, "timedelta64[as]", False).data ).dtype == np.dtype("timedelta64[as]") - assert ak.to_numpy(ak._do.numbers_to_type(two, "bool", False)).dtype == np.dtype( - np.bool_ - ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "int8", False)).dtype == np.dtype( - np.int8 - ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "uint8", False)).dtype == np.dtype( - np.uint8 - ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "int16", False)).dtype == np.dtype( - np.int16 - ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "uint16", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(two, "bool", False)).dtype == np.dtype(np.bool_) + assert ak.to_numpy(numbers_to_type(two, "int8", False)).dtype == np.dtype(np.int8) + assert ak.to_numpy(numbers_to_type(two, "uint8", False)).dtype == np.dtype(np.uint8) + assert ak.to_numpy(numbers_to_type(two, "int16", False)).dtype == np.dtype(np.int16) + assert ak.to_numpy(numbers_to_type(two, "uint16", False)).dtype == np.dtype( np.uint16 ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "int32", False)).dtype == np.dtype( - np.int32 - ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "uint32", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(two, "int32", False)).dtype == np.dtype(np.int32) + assert ak.to_numpy(numbers_to_type(two, "uint32", False)).dtype == np.dtype( np.uint32 ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "int64", False)).dtype == np.dtype( - np.int64 - ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "uint64", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(two, "int64", False)).dtype == np.dtype(np.int64) + assert ak.to_numpy(numbers_to_type(two, "uint64", False)).dtype == np.dtype( np.uint64 ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "float32", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(two, "float32", False)).dtype == np.dtype( np.float32 ) - assert ak.to_numpy(ak._do.numbers_to_type(two, "float64", False)).dtype == np.dtype( + assert ak.to_numpy(numbers_to_type(two, "float64", False)).dtype == np.dtype( np.float64 ) + assert np.asarray(numbers_to_type(two, "complex64", False).data).dtype == np.dtype( + np.complex64 + ) + assert np.asarray(numbers_to_type(two, "complex128", False).data).dtype == np.dtype( + np.complex128 + ) + assert np.asarray(numbers_to_type(two, "datetime64", False).data).dtype == np.dtype( + np.datetime64 + ) assert np.asarray( - ak._do.numbers_to_type(two, "complex64", False).data - ).dtype == np.dtype(np.complex64) - assert np.asarray( - ak._do.numbers_to_type(two, "complex128", False).data - ).dtype == np.dtype(np.complex128) - assert np.asarray( - ak._do.numbers_to_type(two, "datetime64", False).data - ).dtype == np.dtype(np.datetime64) - assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[Y]", False).data + numbers_to_type(two, "datetime64[Y]", False).data ).dtype == np.dtype("datetime64[Y]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[M]", False).data + numbers_to_type(two, "datetime64[M]", False).data ).dtype == np.dtype("datetime64[M]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[W]", False).data + numbers_to_type(two, "datetime64[W]", False).data ).dtype == np.dtype("datetime64[W]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[D]", False).data + numbers_to_type(two, "datetime64[D]", False).data ).dtype == np.dtype("datetime64[D]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[h]", False).data + numbers_to_type(two, "datetime64[h]", False).data ).dtype == np.dtype("datetime64[h]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[m]", False).data + numbers_to_type(two, "datetime64[m]", False).data ).dtype == np.dtype("datetime64[m]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[s]", False).data + numbers_to_type(two, "datetime64[s]", False).data ).dtype == np.dtype("datetime64[s]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[ms]", False).data + numbers_to_type(two, "datetime64[ms]", False).data ).dtype == np.dtype("datetime64[ms]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[us]", False).data + numbers_to_type(two, "datetime64[us]", False).data ).dtype == np.dtype("datetime64[us]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[ns]", False).data + numbers_to_type(two, "datetime64[ns]", False).data ).dtype == np.dtype("datetime64[ns]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[ps]", False).data + numbers_to_type(two, "datetime64[ps]", False).data ).dtype == np.dtype("datetime64[ps]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[fs]", False).data + numbers_to_type(two, "datetime64[fs]", False).data ).dtype == np.dtype("datetime64[fs]") assert np.asarray( - ak._do.numbers_to_type(two, "datetime64[as]", False).data + numbers_to_type(two, "datetime64[as]", False).data ).dtype == np.dtype("datetime64[as]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64", False).data + numbers_to_type(two, "timedelta64", False).data ).dtype == np.dtype(np.timedelta64) assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[Y]", False).data + numbers_to_type(two, "timedelta64[Y]", False).data ).dtype == np.dtype("timedelta64[Y]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[M]", False).data + numbers_to_type(two, "timedelta64[M]", False).data ).dtype == np.dtype("timedelta64[M]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[W]", False).data + numbers_to_type(two, "timedelta64[W]", False).data ).dtype == np.dtype("timedelta64[W]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[D]", False).data + numbers_to_type(two, "timedelta64[D]", False).data ).dtype == np.dtype("timedelta64[D]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[h]", False).data + numbers_to_type(two, "timedelta64[h]", False).data ).dtype == np.dtype("timedelta64[h]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[m]", False).data + numbers_to_type(two, "timedelta64[m]", False).data ).dtype == np.dtype("timedelta64[m]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[s]", False).data + numbers_to_type(two, "timedelta64[s]", False).data ).dtype == np.dtype("timedelta64[s]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[ms]", False).data + numbers_to_type(two, "timedelta64[ms]", False).data ).dtype == np.dtype("timedelta64[ms]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[us]", False).data + numbers_to_type(two, "timedelta64[us]", False).data ).dtype == np.dtype("timedelta64[us]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[ns]", False).data + numbers_to_type(two, "timedelta64[ns]", False).data ).dtype == np.dtype("timedelta64[ns]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[ps]", False).data + numbers_to_type(two, "timedelta64[ps]", False).data ).dtype == np.dtype("timedelta64[ps]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[fs]", False).data + numbers_to_type(two, "timedelta64[fs]", False).data ).dtype == np.dtype("timedelta64[fs]") assert np.asarray( - ak._do.numbers_to_type(two, "timedelta64[as]", False).data + numbers_to_type(two, "timedelta64[as]", False).data ).dtype == np.dtype("timedelta64[as]") diff --git a/tests/test_1149_datetime_sort.py b/tests/test_1149_datetime_sort.py index 63d4b977ed..3be58837b2 100644 --- a/tests/test_1149_datetime_sort.py +++ b/tests/test_1149_datetime_sort.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import datetime @@ -8,6 +7,7 @@ import pytest # noqa: F401 import awkward as ak +from awkward._do.content import is_unique, unique to_list = ak.operations.to_list @@ -49,8 +49,8 @@ def test_date_time_sort_argsort_unique(): datetime.datetime(2020, 7, 27, 10, 41, 11), ] assert to_list(ak.argsort(array, highlevel=False)) == [1, 2, 0] - assert ak._do.is_unique(array) is True - assert to_list(ak._do.unique(array)) == [ + assert is_unique(array) is True + assert to_list(unique(array)) == [ datetime.datetime(2019, 1, 1, 0, 0), datetime.datetime(2020, 1, 1, 0, 0), datetime.datetime(2020, 7, 27, 10, 41, 11), @@ -73,8 +73,8 @@ def test_time_delta_sort_argsort_unique(): datetime.timedelta(days=41), ] assert to_list(ak.argsort(array, highlevel=False)) == [1, 2, 0] - assert ak._do.is_unique(array) is True - assert to_list(ak._do.unique(array)) == [ + assert is_unique(array) is True + assert to_list(unique(array)) == [ datetime.timedelta(days=1), datetime.timedelta(days=20), datetime.timedelta(days=41), diff --git a/tests/test_1240_v2_implementation_of_numba_1.py b/tests/test_1240_v2_implementation_of_numba_1.py index 84aff82361..a38b54d974 100644 --- a/tests/test_1240_v2_implementation_of_numba_1.py +++ b/tests/test_1240_v2_implementation_of_numba_1.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import sys diff --git a/tests/test_2408_layoutbuilder_in_numba.py b/tests/test_2408_layoutbuilder_in_numba.py index 8277f79a7b..0597eb73c3 100644 --- a/tests/test_2408_layoutbuilder_in_numba.py +++ b/tests/test_2408_layoutbuilder_in_numba.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np diff --git a/tests/test_2616_use_pyarrow_for_strings.py b/tests/test_2616_use_pyarrow_for_strings.py index 2e58f73f78..cb46944205 100644 --- a/tests/test_2616_use_pyarrow_for_strings.py +++ b/tests/test_2616_use_pyarrow_for_strings.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import pytest diff --git a/tests/test_2808_dtype_ufunc_bool.py b/tests/test_2808_dtype_ufunc_bool.py index fc56bf29d6..79812c103c 100644 --- a/tests/test_2808_dtype_ufunc_bool.py +++ b/tests/test_2808_dtype_ufunc_bool.py @@ -1,5 +1,4 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE - from __future__ import annotations import numpy as np From 58ec7ebe5570a27d8ae3b1512e0db6bdf29492af Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 13:41:58 +0000 Subject: [PATCH 05/12] fix: merging --- src/awkward/_do/content.py | 13 ++++++++++--- src/awkward/_do/meta.py | 14 ++++---------- src/awkward/_meta/numpymeta.py | 14 ++++++++++---- src/awkward/_meta/recordmeta.py | 4 ++-- src/awkward/_nplikes/array_module.py | 5 ----- src/awkward/_nplikes/numpy_like.py | 7 ++----- src/awkward/_nplikes/typetracer.py | 5 ----- src/awkward/forms/numpyform.py | 6 ++++++ src/awkward/operations/ak_strings_astype.py | 4 ++-- src/awkward/operations/ak_values_astype.py | 3 ++- src/awkward/operations/str/__init__.py | 2 +- src/awkward/typetracer.py | 2 +- 12 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/awkward/_do/content.py b/src/awkward/_do/content.py index 271a175e56..7c63904c59 100644 --- a/src/awkward/_do/content.py +++ b/src/awkward/_do/content.py @@ -9,14 +9,16 @@ import awkward as ak from awkward._backends.backend import Backend from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import Any, AxisMaybeNone, Literal -from awkward.contents.content import ActionType, Content +from awkward._typing import TYPE_CHECKING, Any, AxisMaybeNone, Literal from awkward.errors import AxisError from awkward.forms import form -from awkward.record import Record np = NumpyMetadata.instance() +if TYPE_CHECKING: + from awkward.contents.content import ActionType, Content + from awkward.record import Record + def recursively_apply( layout: Content | Record, @@ -32,6 +34,9 @@ def recursively_apply( function_name: str | None = None, regular_to_jagged=False, ) -> Content | Record | None: + from awkward.contents.content import Content + from awkward.record import Record + if isinstance(layout, Content): return layout._recursively_apply( action, @@ -201,6 +206,8 @@ def remove_structure( allow_records: bool = False, list_to_regular: bool = False, ): + from awkward.record import Record + if isinstance(layout, Record): return remove_structure( layout._array[layout._at : layout._at + 1], diff --git a/src/awkward/_do/meta.py b/src/awkward/_do/meta.py index 7333049952..09ddca9dfb 100644 --- a/src/awkward/_do/meta.py +++ b/src/awkward/_do/meta.py @@ -55,19 +55,13 @@ def is_indexed(meta: Meta) -> TypeGuard[IndexedOptionMeta, IndexedMeta]: return meta.is_indexed -class ImplementsTuple(RecordMeta): # Intersection - _fields: None - - -def is_record_tuple(meta: Meta) -> TypeGuard[ImplementsTuple]: +# FIXME: narrow this to have `is_tuple` be a const True +def is_record_tuple(meta: Meta) -> TypeGuard[RecordMeta]: return meta.is_record and meta.is_tuple -class ImplementsRecord(RecordMeta): - _fields: list[str] - - -def is_record_record(meta: Meta) -> TypeGuard[ImplementsRecord]: +# FIXME: narrow this to have `is_tuple` be a const False +def is_record_record(meta: Meta) -> TypeGuard[RecordMeta]: return meta.is_record and not meta.is_tuple diff --git a/src/awkward/_meta/numpymeta.py b/src/awkward/_meta/numpymeta.py index 7175cd7ac7..e81241f04e 100644 --- a/src/awkward/_meta/numpymeta.py +++ b/src/awkward/_meta/numpymeta.py @@ -4,10 +4,12 @@ from awkward._do.meta import is_indexed, is_numpy, is_option from awkward._meta.meta import Meta +from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import ShapeItem from awkward._parameters import type_parameters_equal -from awkward._typing import TYPE_CHECKING, JSONSerializable +from awkward._typing import TYPE_CHECKING, DType, JSONSerializable +np = NumpyMetadata.instance() if TYPE_CHECKING: from awkward._meta.regularmeta import RegularMeta @@ -17,6 +19,10 @@ class NumpyMeta(Meta): is_leaf = True inner_shape: tuple[ShapeItem, ...] + @property + def dtype(self) -> DType: + raise NotImplementedError + def purelist_parameters(self, *keys: str) -> JSONSerializable: if self._parameters is not None: for key in keys: @@ -104,9 +110,9 @@ def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: # Default merging (can we cast one to the other) else: - return self.backend.nplike.can_cast( - self.dtype, other.dtype - ) or self.backend.nplike.can_cast(other.dtype, self.dtype) + return np.can_cast( + self.dtype, other.dtype, casting="same_kind" + ) or np.can_cast(other.dtype, self.dtype, casting="same_kind") else: return False diff --git a/src/awkward/_meta/recordmeta.py b/src/awkward/_meta/recordmeta.py index 7448227159..61cad64ed5 100644 --- a/src/awkward/_meta/recordmeta.py +++ b/src/awkward/_meta/recordmeta.py @@ -170,10 +170,10 @@ def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: return False elif is_record_record(self) and is_record_record(other): - if set(self._fields) != set(other._fields): + if set(self._fields) != set(other._fields): # type: ignore[arg-type] return False - for i, field in enumerate(self._fields): + for i, field in enumerate(self._fields): # type: ignore[arg-type] x = self._contents[i] y = other.contents[other.field_to_index(field)] if not x._mergeable_next(y, mergebool): diff --git a/src/awkward/_nplikes/array_module.py b/src/awkward/_nplikes/array_module.py index 82ef7a11d1..7d5e4bb151 100644 --- a/src/awkward/_nplikes/array_module.py +++ b/src/awkward/_nplikes/array_module.py @@ -653,11 +653,6 @@ def astype( assert not isinstance(x, PlaceholderArray) return x.astype(dtype, copy=copy) # type: ignore[attr-defined] - def can_cast( - self, from_: DTypeLike | ArrayLikeT, to: DTypeLike | ArrayLikeT - ) -> bool: - return self._module.can_cast(from_, to, casting="same_kind") - @classmethod def is_own_array(cls, obj) -> bool: return cls.is_own_array_type(type(obj)) diff --git a/src/awkward/_nplikes/numpy_like.py b/src/awkward/_nplikes/numpy_like.py index 19119d754c..7cf550adbe 100644 --- a/src/awkward/_nplikes/numpy_like.py +++ b/src/awkward/_nplikes/numpy_like.py @@ -83,7 +83,8 @@ class NumpyMetadata(PublicSingleton): datetime_data = staticmethod(numpy.datetime_data) issubdtype = staticmethod(numpy.issubdtype) - AxisError = numpy.AxisError + AxisError = staticmethod(numpy.AxisError) + can_cast = staticmethod(numpy.can_cast) if hasattr(numpy, "float16"): @@ -537,10 +538,6 @@ def astype( ) -> ArrayLikeT: ... - @abstractmethod - def can_cast(self, from_: DType | ArrayLikeT, to: DType | ArrayLikeT) -> bool: - ... - @abstractmethod def is_c_contiguous(self, x: ArrayLikeT | PlaceholderArray) -> bool: ... diff --git a/src/awkward/_nplikes/typetracer.py b/src/awkward/_nplikes/typetracer.py index 236626ef02..423af36e7c 100644 --- a/src/awkward/_nplikes/typetracer.py +++ b/src/awkward/_nplikes/typetracer.py @@ -1512,11 +1512,6 @@ def astype( x.touch_data() return TypeTracerArray._new(np.dtype(dtype), x.shape) - def can_cast( - self, from_: DTypeLike | TypeTracerArray, to: DTypeLike | TypeTracerArray - ) -> bool: - return numpy.can_cast(from_, to, casting="same_kind") - @classmethod def is_own_array_type(cls, type_: type) -> bool: return issubclass(type_, TypeTracerArray) diff --git a/src/awkward/forms/numpyform.py b/src/awkward/forms/numpyform.py index 11de6bcf87..d3a7b77328 100644 --- a/src/awkward/forms/numpyform.py +++ b/src/awkward/forms/numpyform.py @@ -262,6 +262,12 @@ def _expected_from_buffers( def _to_regular_primitive(self) -> RegularForm | NumpyForm: return self.to_RegularForm() + @property + def dtype(self) -> DType: + from awkward.types.numpytype import primitive_to_dtype + + return primitive_to_dtype(self.primitive) + def _is_equal_to(self, other: Any, all_parameters: bool, form_key: bool) -> bool: return self._is_equal_to_generic(other, all_parameters, form_key) and ( self._primitive == other._primitive diff --git a/src/awkward/operations/ak_strings_astype.py b/src/awkward/operations/ak_strings_astype.py index 16ff6eeba0..3f799068d1 100644 --- a/src/awkward/operations/ak_strings_astype.py +++ b/src/awkward/operations/ak_strings_astype.py @@ -4,7 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function -from awkward._do.content import recursively_apply +from awkward._do.content import pad_none, recursively_apply from awkward._layout import HighLevelContext from awkward._nplikes.numpy import Numpy from awkward._nplikes.numpy_like import NumpyMetadata @@ -68,7 +68,7 @@ def action(layout, **kwargs): layout, highlevel=False, behavior=behavior ) max_length = ak.operations.max(ak.operations.num(layout, behavior=behavior)) - regulararray = ak._do.pad_none(layout, max_length, 1) + regulararray = pad_none(layout, max_length, 1) maskedarray = ak.operations.to_numpy(regulararray, allow_missing=True) npstrings = maskedarray.data if maskedarray.mask is not False: diff --git a/src/awkward/operations/ak_values_astype.py b/src/awkward/operations/ak_values_astype.py index 714a4320d9..49d1207ff9 100644 --- a/src/awkward/operations/ak_values_astype.py +++ b/src/awkward/operations/ak_values_astype.py @@ -4,6 +4,7 @@ import awkward as ak from awkward._dispatch import high_level_function +from awkward._do.content import numbers_to_type from awkward._layout import HighLevelContext from awkward._nplikes.numpy_like import NumpyMetadata @@ -73,5 +74,5 @@ def _impl(array, to, including_unknown, highlevel, behavior, attrs): with HighLevelContext(behavior=behavior, attrs=attrs) as ctx: layout = ctx.unwrap(array, allow_record=False, primitive_policy="error") to_str = ak.types.numpytype.dtype_to_primitive(np.dtype(to)) - out = ak._do.numbers_to_type(layout, to_str, including_unknown) + out = numbers_to_type(layout, to_str, including_unknown) return ctx.wrap(out, highlevel=highlevel) diff --git a/src/awkward/operations/str/__init__.py b/src/awkward/operations/str/__init__.py index 3a6d776904..e362571a72 100644 --- a/src/awkward/operations/str/__init__.py +++ b/src/awkward/operations/str/__init__.py @@ -85,7 +85,7 @@ def _drop_option_preserving_form(layout, ensure_empty_mask: bool = False): - from awkward._do import recursively_apply + from awkward._do.content import recursively_apply from awkward.contents import UnmaskedArray, IndexedOptionArray, IndexedArray def action(_, continuation, **kwargs): diff --git a/src/awkward/typetracer.py b/src/awkward/typetracer.py index abaf542ceb..6cbcacf246 100644 --- a/src/awkward/typetracer.py +++ b/src/awkward/typetracer.py @@ -6,7 +6,7 @@ import awkward.forms from awkward._backends.typetracer import TypeTracerBackend -from awkward._do import touch_data as _touch_data +from awkward._do.content import touch_data as _touch_data from awkward._layout import HighLevelContext, wrap_layout from awkward._nplikes.numpy import NumpyMetadata from awkward._nplikes.placeholder import PlaceholderArray From 97606982b0fc2262bd5b7113228990f002e97977 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 13:51:08 +0000 Subject: [PATCH 06/12] chore: add note about `_to_regular_primitive` --- src/awkward/_meta/numpymeta.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/awkward/_meta/numpymeta.py b/src/awkward/_meta/numpymeta.py index e81241f04e..0fa674b3b5 100644 --- a/src/awkward/_meta/numpymeta.py +++ b/src/awkward/_meta/numpymeta.py @@ -78,16 +78,19 @@ def _mergeable_next(self, other: Meta, mergebool: bool) -> bool: return False # Simplify *this* branch to be 1D self elif len(self.inner_shape) > 0: - return self._to_regular_primitive()._mergeable_next( - other, mergebool - ) # TODO + # TODO: `_to_regular_primitive` is a mechanism for re-using our merge + # logic that already handles `RegularArray`. Rather than + # converting the NumpyArray into a contiguous `RegularArray`, + # we return something with arbitrary data (e.g. a broadcasted empty array!) + # N.B. NumpyForm doesn't need to do this, only NumpyArray. + return self._to_regular_primitive()._mergeable_next(other, mergebool) elif is_numpy(other): if len(self.inner_shape) != len(other.inner_shape): return False # Obvious fast-path - if self.dtype == other.dtype: # TODO + if self.dtype == other.dtype: return True # Special-case booleans i.e. {bool, number} From 663d6ae5fb0241b14d958d940eec4f9e3cd6fa09 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 21:37:50 +0000 Subject: [PATCH 07/12] refactor: move `is_XXX` from `ak._do` to `ak._meta` --- src/awkward/_do/meta.py | 56 +------------------------- src/awkward/_meta/bitmaskedmeta.py | 3 +- src/awkward/_meta/bytemaskedmeta.py | 3 +- src/awkward/_meta/indexedmeta.py | 3 +- src/awkward/_meta/indexedoptionmeta.py | 3 +- src/awkward/_meta/listmeta.py | 3 +- src/awkward/_meta/listoffsetmeta.py | 3 +- src/awkward/_meta/meta.py | 55 +++++++++++++++++++++++++ src/awkward/_meta/numpymeta.py | 3 +- src/awkward/_meta/recordmeta.py | 4 +- src/awkward/_meta/regularmeta.py | 3 +- src/awkward/_meta/unmaskedmeta.py | 3 +- 12 files changed, 67 insertions(+), 75 deletions(-) diff --git a/src/awkward/_do/meta.py b/src/awkward/_do/meta.py index 09ddca9dfb..272c9e29ad 100644 --- a/src/awkward/_do/meta.py +++ b/src/awkward/_do/meta.py @@ -3,67 +3,13 @@ from __future__ import annotations from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._typing import TYPE_CHECKING, TypeGuard, TypeVar +from awkward._typing import TYPE_CHECKING if TYPE_CHECKING: - from awkward._meta.bitmaskedmeta import BitMaskedMeta - from awkward._meta.bytemaskedmeta import ByteMaskedMeta - from awkward._meta.indexedmeta import IndexedMeta - from awkward._meta.indexedoptionmeta import IndexedOptionMeta - from awkward._meta.listmeta import ListMeta - from awkward._meta.listoffsetmeta import ListOffsetMeta from awkward._meta.meta import Meta - from awkward._meta.numpymeta import NumpyMeta - from awkward._meta.recordmeta import RecordMeta - from awkward._meta.regularmeta import RegularMeta - from awkward._meta.unionmeta import UnionMeta - from awkward._meta.unmaskedmeta import UnmaskedMeta np = NumpyMetadata.instance() -T = TypeVar("T", bound="Meta") - - -def is_option( - meta: Meta -) -> TypeGuard[IndexedOptionMeta | BitMaskedMeta | ByteMaskedMeta | UnmaskedMeta]: - return meta.is_option - - -def is_list(meta: Meta) -> TypeGuard[RegularMeta | ListOffsetMeta | ListMeta]: - return meta.is_list - - -def is_numpy(meta: Meta) -> TypeGuard[NumpyMeta]: - return meta.is_numpy - - -def is_regular(meta: Meta) -> TypeGuard[RegularMeta]: - return meta.is_regular - - -def is_union(meta: Meta) -> TypeGuard[UnionMeta]: - return meta.is_union - - -def is_record(meta: Meta) -> TypeGuard[RecordMeta]: - return meta.is_record - - -def is_indexed(meta: Meta) -> TypeGuard[IndexedOptionMeta, IndexedMeta]: - return meta.is_indexed - - -# FIXME: narrow this to have `is_tuple` be a const True -def is_record_tuple(meta: Meta) -> TypeGuard[RecordMeta]: - return meta.is_record and meta.is_tuple - - -# FIXME: narrow this to have `is_tuple` be a const False -def is_record_record(meta: Meta) -> TypeGuard[RecordMeta]: - return meta.is_record and not meta.is_tuple - - def mergeable(one: Meta, two: Meta, mergebool: bool = True) -> bool: return one._mergeable_next(two, mergebool=mergebool) diff --git a/src/awkward/_meta/bitmaskedmeta.py b/src/awkward/_meta/bitmaskedmeta.py index 55e70ef3a4..fc8cb6dc25 100644 --- a/src/awkward/_meta/bitmaskedmeta.py +++ b/src/awkward/_meta/bitmaskedmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/bytemaskedmeta.py b/src/awkward/_meta/bytemaskedmeta.py index 6945ddd8fd..e343b31b1b 100644 --- a/src/awkward/_meta/bytemaskedmeta.py +++ b/src/awkward/_meta/bytemaskedmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/indexedmeta.py b/src/awkward/_meta/indexedmeta.py index cf5f0aac48..e2ad858921 100644 --- a/src/awkward/_meta/indexedmeta.py +++ b/src/awkward/_meta/indexedmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/indexedoptionmeta.py b/src/awkward/_meta/indexedoptionmeta.py index 5891a36e91..3834cbdbdd 100644 --- a/src/awkward/_meta/indexedoptionmeta.py +++ b/src/awkward/_meta/indexedoptionmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/listmeta.py b/src/awkward/_meta/listmeta.py index 887f6b162a..cec5ba8dfe 100644 --- a/src/awkward/_meta/listmeta.py +++ b/src/awkward/_meta/listmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_list, is_numpy, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_list, is_numpy, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/listoffsetmeta.py b/src/awkward/_meta/listoffsetmeta.py index f82918e1c6..af77d974c7 100644 --- a/src/awkward/_meta/listoffsetmeta.py +++ b/src/awkward/_meta/listoffsetmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_list, is_numpy, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_list, is_numpy, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/meta.py b/src/awkward/_meta/meta.py index 31ddb6b7fc..c2f399fad0 100644 --- a/src/awkward/_meta/meta.py +++ b/src/awkward/_meta/meta.py @@ -3,13 +3,68 @@ from __future__ import annotations from awkward._typing import ( + TYPE_CHECKING, ClassVar, JSONMapping, JSONSerializable, Self, + TypeGuard, ) from awkward._util import UNSET, Sentinel +if TYPE_CHECKING: + from awkward._meta.bitmaskedmeta import BitMaskedMeta + from awkward._meta.bytemaskedmeta import ByteMaskedMeta + from awkward._meta.indexedmeta import IndexedMeta + from awkward._meta.indexedoptionmeta import IndexedOptionMeta + from awkward._meta.listmeta import ListMeta + from awkward._meta.listoffsetmeta import ListOffsetMeta + from awkward._meta.numpymeta import NumpyMeta + from awkward._meta.recordmeta import RecordMeta + from awkward._meta.regularmeta import RegularMeta + from awkward._meta.unionmeta import UnionMeta + from awkward._meta.unmaskedmeta import UnmaskedMeta + + +def is_option( + meta: Meta +) -> TypeGuard[IndexedOptionMeta | BitMaskedMeta | ByteMaskedMeta | UnmaskedMeta]: + return meta.is_option + + +def is_list(meta: Meta) -> TypeGuard[RegularMeta | ListOffsetMeta | ListMeta]: + return meta.is_list + + +def is_numpy(meta: Meta) -> TypeGuard[NumpyMeta]: + return meta.is_numpy + + +def is_regular(meta: Meta) -> TypeGuard[RegularMeta]: + return meta.is_regular + + +def is_union(meta: Meta) -> TypeGuard[UnionMeta]: + return meta.is_union + + +def is_record(meta: Meta) -> TypeGuard[RecordMeta]: + return meta.is_record + + +def is_indexed(meta: Meta) -> TypeGuard[IndexedOptionMeta | IndexedMeta]: + return meta.is_indexed + + +# FIXME: narrow this to have `is_tuple` be a const True +def is_record_tuple(meta: Meta) -> TypeGuard[RecordMeta]: + return meta.is_record and meta.is_tuple + + +# FIXME: narrow this to have `is_tuple` be a const False +def is_record_record(meta: Meta) -> TypeGuard[RecordMeta]: + return meta.is_record and not meta.is_tuple + class Meta: is_numpy: ClassVar[bool] = False diff --git a/src/awkward/_meta/numpymeta.py b/src/awkward/_meta/numpymeta.py index 0fa674b3b5..7ac9e93bb3 100644 --- a/src/awkward/_meta/numpymeta.py +++ b/src/awkward/_meta/numpymeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_numpy, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_numpy, is_option from awkward._nplikes.numpy_like import NumpyMetadata from awkward._nplikes.shape import ShapeItem from awkward._parameters import type_parameters_equal diff --git a/src/awkward/_meta/recordmeta.py b/src/awkward/_meta/recordmeta.py index 61cad64ed5..a43b311168 100644 --- a/src/awkward/_meta/recordmeta.py +++ b/src/awkward/_meta/recordmeta.py @@ -2,14 +2,14 @@ from __future__ import annotations -from awkward._do.meta import ( +from awkward._meta.meta import ( + Meta, is_indexed, is_option, is_record, is_record_record, is_record_tuple, ) -from awkward._meta.meta import Meta from awkward._parameters import type_parameters_equal from awkward._regularize import is_integer from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/regularmeta.py b/src/awkward/_meta/regularmeta.py index 2b91d46d4e..5962adeb33 100644 --- a/src/awkward/_meta/regularmeta.py +++ b/src/awkward/_meta/regularmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_list, is_numpy, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_list, is_numpy, is_option from awkward._nplikes.shape import ShapeItem from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable diff --git a/src/awkward/_meta/unmaskedmeta.py b/src/awkward/_meta/unmaskedmeta.py index d6a03379c3..65c41c123f 100644 --- a/src/awkward/_meta/unmaskedmeta.py +++ b/src/awkward/_meta/unmaskedmeta.py @@ -2,8 +2,7 @@ from __future__ import annotations -from awkward._do.meta import is_indexed, is_option -from awkward._meta.meta import Meta +from awkward._meta.meta import Meta, is_indexed, is_option from awkward._parameters import type_parameters_equal from awkward._typing import JSONSerializable From a052a5561a2ca6f4da8f8545afd8117338ebd02a Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 22:18:08 +0000 Subject: [PATCH 08/12] fix: typing import --- src/awkward/_typing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/awkward/_typing.py b/src/awkward/_typing.py index afca0fe43f..8780307214 100644 --- a/src/awkward/_typing.py +++ b/src/awkward/_typing.py @@ -7,6 +7,7 @@ import sys import typing from typing import * # noqa: F403 +from typing import TypeVar import numpy @@ -70,7 +71,7 @@ DType: TypeAlias = numpy.dtype -AxisMaybeNone = TypeVar("AxisMaybeNone", int, None) # noqa: F405 +AxisMaybeNone = TypeVar("AxisMaybeNone", int, None) T = TypeVar("T") From 8f7208cdf3bd6731cb3ccdba7c4fc79b536b66f9 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 22:21:35 +0000 Subject: [PATCH 09/12] fix: invert test order --- src/awkward/_pickle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/awkward/_pickle.py b/src/awkward/_pickle.py index b36cc3e733..d8e4cb4af6 100644 --- a/src/awkward/_pickle.py +++ b/src/awkward/_pickle.py @@ -90,7 +90,7 @@ def use_builtin_reducer(): def custom_reduce(obj, protocol: int) -> tuple | NotImplemented: - if (plugin := get_custom_reducer()) is None or _DISABLE_CUSTOM_REDUCER: + if _DISABLE_CUSTOM_REDUCER or (plugin := get_custom_reducer()) is None: return NotImplemented else: return plugin(obj, protocol) From bd3d6687d10bcf62ba6aff0b1096dd1148f358d5 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 23:15:42 +0000 Subject: [PATCH 10/12] test: always disable custom pickler in tests --- tests/conftest.py | 12 ++++++++++++ tests/test_2757_attrs_metadata.py | 20 ++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000000..8471ea511e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +import pytest + +from awkward._pickle import use_builtin_reducer + + +@pytest.fixture(autouse=True) +def disable_external_pickler(): + """Fixture to disable external pickler implementation for every test""" + with use_builtin_reducer(): + yield diff --git a/tests/test_2757_attrs_metadata.py b/tests/test_2757_attrs_metadata.py index ab6fcf3776..3fd29c83e6 100644 --- a/tests/test_2757_attrs_metadata.py +++ b/tests/test_2757_attrs_metadata.py @@ -1,20 +1,12 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE from __future__ import annotations +import pickle + import packaging.version import pytest import awkward as ak -from awkward._pickle import use_builtin_reducer - - -@pytest.fixture -def array_pickler(): - import pickle - - with use_builtin_reducer(): - yield pickle - SOME_ATTRS = {"foo": "!SOME"} OTHER_ATTRS = {"bar": "!OTHER", "foo": "!OTHER"} @@ -31,18 +23,18 @@ def test_set_attrs(): array.attrs = "Hello world!" -def test_serialise_with_transient_attrs(array_pickler): +def test_serialise_with_transient_attrs(): attrs = {**SOME_ATTRS, "@transient_key": lambda: None} array = ak.Array([1, 2, 3], attrs=attrs) - result = array_pickler.loads(array_pickler.dumps(array)) + result = pickle.loads(pickle.dumps(array)) assert result.attrs == SOME_ATTRS -def test_serialise_with_nonserialisable_attrs(array_pickler): +def test_serialise_with_nonserialisable_attrs(): attrs = {**SOME_ATTRS, "non_transient_key": lambda: None} array = ak.Array([1, 2, 3], attrs=attrs) with pytest.raises(AttributeError, match=r"Can't pickle local object"): - array_pickler.loads(array_pickler.dumps(array)) + pickle.loads(pickle.dumps(array)) def test_transient_metadata_persists(): From 7d628582beea374b5ef7276871bf61824f32a155 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 29 Nov 2023 23:17:23 +0000 Subject: [PATCH 11/12] test: add note about custom pickler --- tests/test_2682_custom_pickler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_2682_custom_pickler.py b/tests/test_2682_custom_pickler.py index 688ff9d986..cb84829f76 100644 --- a/tests/test_2682_custom_pickler.py +++ b/tests/test_2682_custom_pickler.py @@ -44,6 +44,8 @@ def _pickle_complex_array_and_return_form_impl(): return pickle.loads(pickle.dumps(array)).layout.form +# NOTE: custom picklers are disabled in our tests, but the subprocess that is +# spawned here doesn't pick up that configuration, thus it can be tested! def pickle_complex_array_and_return_form(pickler_source, tmp_path): """Create a new (spawned) process, and register the given pickler source via entrypoints""" From dc9645fb4c5e672c19510bc2781fd7674f4a2764 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 4 Dec 2023 11:01:41 +0000 Subject: [PATCH 12/12] chore: run pre-commit --- src/awkward/_connect/numpy.py | 4 ++-- src/awkward/forms/bitmaskedform.py | 3 +-- src/awkward/forms/bytemaskedform.py | 3 +-- src/awkward/forms/indexedform.py | 3 +-- src/awkward/forms/indexedoptionform.py | 3 +-- src/awkward/forms/listform.py | 3 +-- src/awkward/forms/recordform.py | 1 - src/awkward/forms/regularform.py | 1 - src/awkward/forms/unionform.py | 3 +-- src/awkward/forms/unmaskedform.py | 1 - 10 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/awkward/_connect/numpy.py b/src/awkward/_connect/numpy.py index 7702047d24..519cc9d419 100644 --- a/src/awkward/_connect/numpy.py +++ b/src/awkward/_connect/numpy.py @@ -5,7 +5,7 @@ import collections import functools import inspect -from collections.abc import Iterable +from collections.abc import Iterable, Iterator, Mapping from itertools import chain import numpy @@ -26,7 +26,7 @@ from awkward._nplikes import to_nplike from awkward._parameters import parameters_intersect from awkward._regularize import is_non_string_like_iterable -from awkward._typing import Any, Iterator, Mapping +from awkward._typing import Any from awkward._util import Sentinel from awkward.contents.numpyarray import NumpyArray diff --git a/src/awkward/forms/bitmaskedform.py b/src/awkward/forms/bitmaskedform.py index b68a724b68..5fdcf94dc8 100644 --- a/src/awkward/forms/bitmaskedform.py +++ b/src/awkward/forms/bitmaskedform.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Iterator import awkward as ak from awkward._meta.bitmaskedmeta import BitMaskedMeta @@ -11,7 +11,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/bytemaskedform.py b/src/awkward/forms/bytemaskedform.py index 338058d4df..fb06daf108 100644 --- a/src/awkward/forms/bytemaskedform.py +++ b/src/awkward/forms/bytemaskedform.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Iterator import awkward as ak from awkward._meta.bytemaskedmeta import ByteMaskedMeta @@ -11,7 +11,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/indexedform.py b/src/awkward/forms/indexedform.py index a76b347a7d..3cc9892952 100644 --- a/src/awkward/forms/indexedform.py +++ b/src/awkward/forms/indexedform.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Iterator import awkward as ak from awkward._meta.indexedmeta import IndexedMeta @@ -12,7 +12,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/indexedoptionform.py b/src/awkward/forms/indexedoptionform.py index 3ad52de4b9..ebab0713ce 100644 --- a/src/awkward/forms/indexedoptionform.py +++ b/src/awkward/forms/indexedoptionform.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Iterator import awkward as ak from awkward._meta.indexedoptionmeta import IndexedOptionMeta @@ -12,7 +12,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/listform.py b/src/awkward/forms/listform.py index 4181f2f92a..1d1541fa96 100644 --- a/src/awkward/forms/listform.py +++ b/src/awkward/forms/listform.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Iterator import awkward as ak from awkward._meta.listmeta import ListMeta @@ -11,7 +11,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/recordform.py b/src/awkward/forms/recordform.py index 860be071cb..0cd8f9f4dd 100644 --- a/src/awkward/forms/recordform.py +++ b/src/awkward/forms/recordform.py @@ -11,7 +11,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/regularform.py b/src/awkward/forms/regularform.py index 5eeb30a595..9057804e5b 100644 --- a/src/awkward/forms/regularform.py +++ b/src/awkward/forms/regularform.py @@ -13,7 +13,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/unionform.py b/src/awkward/forms/unionform.py index 05b0eb7bde..aecc0889f7 100644 --- a/src/awkward/forms/unionform.py +++ b/src/awkward/forms/unionform.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable, Iterable +from collections.abc import Callable, Iterable, Iterator from itertools import permutations import awkward as ak @@ -12,7 +12,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, ) diff --git a/src/awkward/forms/unmaskedform.py b/src/awkward/forms/unmaskedform.py index 15ec3791a9..5a59c15222 100644 --- a/src/awkward/forms/unmaskedform.py +++ b/src/awkward/forms/unmaskedform.py @@ -12,7 +12,6 @@ Any, DType, ImplementsReadOnlyProperty, - Iterator, Self, final, )