Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public interface for layout.recursively_apply and broadcast_and_apply. #1610

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/awkward/_v2/contents/bitmaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import awkward as ak
from awkward._v2.index import Index
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.contents.bytemaskedarray import ByteMaskedArray
from awkward._v2.forms.bitmaskedform import BitMaskedForm
from awkward._v2.forms.form import _parameters_equal
Expand All @@ -18,6 +18,28 @@
class BitMaskedArray(Content):
is_OptionType = True

def copy(
self,
mask=unset,
content=unset,
valid_when=unset,
length=unset,
lsb_order=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return BitMaskedArray(
self._mask if mask is unset else mask,
self._content if content is unset else content,
self._valid_when if valid_when is unset else valid_when,
self._length if length is unset else length,
self._lsb_order if lsb_order is unset else lsb_order,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(
self,
mask,
Expand Down Expand Up @@ -635,6 +657,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
22 changes: 21 additions & 1 deletion src/awkward/_v2/contents/bytemaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import awkward as ak
from awkward._v2.index import Index
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.bytemaskedform import ByteMaskedForm
from awkward._v2.forms.form import _parameters_equal

Expand All @@ -17,6 +17,24 @@
class ByteMaskedArray(Content):
is_OptionType = True

def copy(
self,
mask=unset,
content=unset,
valid_when=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return ByteMaskedArray(
self._mask if mask is unset else mask,
self._content if content is unset else content,
self._valid_when if valid_when is unset else valid_when,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(
self, mask, content, valid_when, identifier=None, parameters=None, nplike=None
):
Expand Down Expand Up @@ -1052,6 +1070,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
4 changes: 3 additions & 1 deletion src/awkward/_v2/contents/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
np = ak.nplike.NumpyMetadata.instance()
numpy = ak.nplike.Numpy.instance()

unset = object()


class Content:
is_NumpyType = False
Expand Down Expand Up @@ -1346,7 +1348,7 @@ def recursively_apply(
action,
behavior,
1,
depth_context,
copy.copy(depth_context),
lateral_context,
{
"allow_records": allow_records,
Expand Down
16 changes: 15 additions & 1 deletion src/awkward/_v2/contents/emptyarray.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import awkward as ak
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.emptyform import EmptyForm
from awkward._v2.forms.form import _parameters_equal

Expand All @@ -13,6 +13,18 @@ class EmptyArray(Content):
is_NumpyType = True
is_UnknownType = True

def copy(
self,
identifier=unset,
parameters=unset,
nplike=unset,
):
return EmptyArray(
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(self, identifier=None, parameters=None, nplike=None):
if nplike is None:
nplike = numpy
Expand Down Expand Up @@ -334,6 +346,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
20 changes: 19 additions & 1 deletion src/awkward/_v2/contents/indexedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import awkward as ak
from awkward._v2.index import Index
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.indexedform import IndexedForm
from awkward._v2.forms.form import _parameters_equal

Expand All @@ -15,6 +15,22 @@
class IndexedArray(Content):
is_IndexedType = True

def copy(
self,
index=unset,
content=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return IndexedArray(
self._index if index is unset else index,
self._content if content is unset else content,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(self, index, content, identifier=None, parameters=None, nplike=None):
if not (
isinstance(index, Index)
Expand Down Expand Up @@ -1226,6 +1242,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
20 changes: 19 additions & 1 deletion src/awkward/_v2/contents/indexedoptionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import awkward as ak
from awkward._v2.index import Index
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.indexedoptionform import IndexedOptionForm
from awkward._v2.forms.form import _parameters_equal

Expand All @@ -16,6 +16,22 @@ class IndexedOptionArray(Content):
is_OptionType = True
is_IndexedType = True

def copy(
self,
index=unset,
content=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return IndexedOptionArray(
self._index if index is unset else index,
self._content if content is unset else content,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(self, index, content, identifier=None, parameters=None, nplike=None):
if not (
isinstance(index, Index)
Expand Down Expand Up @@ -1665,6 +1681,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
22 changes: 21 additions & 1 deletion src/awkward/_v2/contents/listarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import awkward as ak
from awkward._v2.index import Index
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.contents.listoffsetarray import ListOffsetArray
from awkward._v2.forms.listform import ListForm
from awkward._v2.forms.form import _parameters_equal
Expand All @@ -15,6 +15,24 @@
class ListArray(Content):
is_ListType = True

def copy(
self,
starts=unset,
stops=unset,
content=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return ListArray(
self._starts if starts is unset else starts,
self._stops if stops is unset else stops,
self._content if content is unset else content,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(
self, starts, stops, content, identifier=None, parameters=None, nplike=None
):
Expand Down Expand Up @@ -1458,6 +1476,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
20 changes: 19 additions & 1 deletion src/awkward/_v2/contents/listoffsetarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import awkward as ak
from awkward._v2.index import Index
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.listoffsetform import ListOffsetForm
from awkward._v2.forms.form import _parameters_equal

Expand All @@ -15,6 +15,22 @@
class ListOffsetArray(Content):
is_ListType = True

def copy(
self,
offsets=unset,
content=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return ListOffsetArray(
self._offsets if offsets is unset else offsets,
self._content if content is unset else content,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(self, offsets, content, identifier=None, parameters=None, nplike=None):
if not isinstance(offsets, Index) and offsets.dtype in (
np.dtype(np.int32),
Expand Down Expand Up @@ -2082,6 +2098,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
18 changes: 17 additions & 1 deletion src/awkward/_v2/contents/numpyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import copy
import awkward as ak
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.numpyform import NumpyForm
from awkward._v2.forms.form import _parameters_equal
from awkward._v2.types.numpytype import primitive_to_dtype
Expand All @@ -14,6 +14,20 @@
class NumpyArray(Content):
is_NumpyType = True

def copy(
self,
data=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return NumpyArray(
self._data if data is unset else data,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(self, data, identifier=None, parameters=None, nplike=None):
if nplike is None:
nplike = ak.nplike.of(data)
Expand Down Expand Up @@ -1312,6 +1326,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
22 changes: 21 additions & 1 deletion src/awkward/_v2/contents/recordarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import awkward as ak
from awkward._v2.record import Record
from awkward._v2.contents.content import Content
from awkward._v2.contents.content import Content, unset
from awkward._v2.forms.recordform import RecordForm
from awkward._v2.forms.form import _parameters_equal

Expand All @@ -18,6 +18,24 @@
class RecordArray(Content):
is_RecordType = True

def copy(
self,
contents=unset,
fields=unset,
length=unset,
identifier=unset,
parameters=unset,
nplike=unset,
):
return RecordArray(
self._contents if contents is unset else contents,
self._fields if fields is unset else fields,
self._length if length is unset else length,
self._identifier if identifier is unset else identifier,
self._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
)

def __init__(
self,
contents,
Expand Down Expand Up @@ -1007,6 +1025,8 @@ def continuation():
depth_context=depth_context,
lateral_context=lateral_context,
continuation=continuation,
behavior=behavior,
nplike=self._nplike,
options=options,
)

Expand Down
Loading