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

refactor!: make Content initialisers take nplike, parameters as keyword #1921

Merged
merged 16 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
eab311b
refactor: make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
e8fa681
refactor(indexedarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
222c651
refactor(emptyarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
a4c6f25
refactor(bytemaskedarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
f9166aa
refactor(bitmaskedarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
5ead9d6
refactor(listarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
36d1b81
refactor(listoffsetarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
e322f1c
refactor(numpyarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
ff6f712
refactor(recordarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
f15dfc7
refactor(regulararray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
bac2a29
refactor(unionarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
6e62e6d
refactor(unmaskedarray): make parameters, nplike, keyword arguments
agoose77 Nov 29, 2022
b9cd7bc
Merge branch 'main' into agoose77/refactor-content-keyword
jpivarski Nov 29, 2022
cceb90d
Form's parameters and form_key are now keyword-only.
jpivarski Nov 29, 2022
b58475c
Type's parameters and typestr are now keyword-only.
jpivarski Nov 29, 2022
b3cd399
Also the copy method, which has the same arguments as __init__.
jpivarski Nov 29, 2022
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
6 changes: 5 additions & 1 deletion src/awkward/_broadcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def broadcast_pack(inputs, isscalar):
elif isinstance(x, Content):
nextinputs.append(
RegularArray(
x, x.length if x.nplike.known_shape else 1, 1, None, x.nplike
x,
x.length if x.nplike.known_shape else 1,
1,
parameters=None,
nplike=x.nplike,
)
)
isscalar.append(False)
Expand Down
4 changes: 3 additions & 1 deletion src/awkward/_connect/jax/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def action(node, **kwargs):
if not (numpy.is_own_array(buffer) or jax.is_own_array(buffer)):
return
else:
return ak.contents.NumpyArray(buffer, node.parameters, nplike=nplike)
return ak.contents.NumpyArray(
buffer, parameters=node.parameters, nplike=nplike
)

return layout.recursively_apply(action=action, numpy_to_regular=False)

Expand Down
6 changes: 3 additions & 3 deletions src/awkward/_connect/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def remove_optiontype(akarray):
assert type(akarray).is_option
if isinstance(akarray, ak.contents.IndexedOptionArray):
return ak.contents.IndexedArray(
akarray.index, akarray.content, akarray.parameters
akarray.index, akarray.content, parameters=akarray.parameters
)
else:
return akarray.content
Expand All @@ -888,8 +888,8 @@ def form_remove_optiontype(akform):
return ak.forms.IndexedForm(
akform.index,
akform.content,
akform.parameters,
akform.form_key,
parameters=akform.parameters,
form_key=akform.form_key,
)
else:
return akform.content
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,5 @@ def getitem_next_array_wrap(outcontent, shape, outer_length=0):
size = shape[i]
if isinstance(size, ak._typetracer.UnknownLengthType):
size = 1
outcontent = ak.contents.RegularArray(outcontent, size, length, None)
outcontent = ak.contents.RegularArray(outcontent, size, length, parameters=None)
return outcontent
4 changes: 2 additions & 2 deletions src/awkward/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def union_to_record(unionarray, anonymous):
unionarray.tags,
unionarray.index,
contents,
unionarray.parameters,
parameters=unionarray.parameters,
)

else:
Expand Down Expand Up @@ -524,7 +524,7 @@ def union_to_record(unionarray, anonymous):
unionarray.tags,
unionarray.index,
union_contents,
unionarray.parameters,
parameters=unionarray.parameters,
).simplify_uniontype()
)

Expand Down
54 changes: 28 additions & 26 deletions src/awkward/contents/bitmaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def copy(
valid_when=unset,
length=unset,
lsb_order=unset,
*,
parameters=unset,
nplike=unset,
):
Expand All @@ -33,8 +34,8 @@ def copy(
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._parameters if parameters is unset else parameters,
self._nplike if nplike is unset else nplike,
parameters=self._parameters if parameters is unset else parameters,
nplike=self._nplike if nplike is unset else nplike,
)

def __copy__(self):
Expand All @@ -54,6 +55,7 @@ def __init__(
valid_when,
length,
lsb_order,
*,
parameters=None,
nplike=None,
):
Expand Down Expand Up @@ -170,8 +172,8 @@ def typetracer(self):
self._valid_when,
self._length,
self._lsb_order,
self._parameters,
tt,
parameters=self._parameters,
nplike=tt,
)

@property
Expand All @@ -185,8 +187,8 @@ def _forget_length(self):
self._valid_when,
ak._typetracer.UnknownLength,
self._lsb_order,
self._parameters,
self._nplike,
parameters=self._parameters,
nplike=self._nplike,
)

def __repr__(self):
Expand Down Expand Up @@ -215,8 +217,8 @@ def merge_parameters(self, parameters):
self._valid_when,
self._length,
self._lsb_order,
ak._util.merge_parameters(self._parameters, parameters),
self._nplike,
parameters=ak._util.merge_parameters(self._parameters, parameters),
nplike=self._nplike,
)

def to_IndexedOptionArray64(self):
Expand All @@ -238,8 +240,8 @@ def to_IndexedOptionArray64(self):
return ak.contents.IndexedOptionArray(
index[0 : self._length],
self._content,
self._parameters,
self._nplike,
parameters=self._parameters,
nplike=self._nplike,
)

def to_ByteMaskedArray(self):
Expand All @@ -262,8 +264,8 @@ def to_ByteMaskedArray(self):
bytemask[: self._length],
self._content,
self._valid_when,
self._parameters,
self._nplike,
parameters=self._parameters,
nplike=self._nplike,
)

def to_BitMaskedArray(self, valid_when, lsb_order):
Expand All @@ -277,8 +279,8 @@ def to_BitMaskedArray(self, valid_when, lsb_order):
valid_when,
self._length,
lsb_order,
self._parameters,
self._nplike,
parameters=self._parameters,
nplike=self._nplike,
)

else:
Expand All @@ -298,8 +300,8 @@ def to_BitMaskedArray(self, valid_when, lsb_order):
valid_when,
self._length,
lsb_order,
self._parameters,
self._nplike,
parameters=self._parameters,
nplike=self._nplike,
)

def mask_as_bool(self, valid_when=None, nplike=None):
Expand Down Expand Up @@ -355,8 +357,8 @@ def _getitem_field(self, where, only_fields=()):
self._valid_when,
self._length,
self._lsb_order,
None,
self._nplike,
parameters=None,
nplike=self._nplike,
).simplify_optiontype()

def _getitem_fields(self, where, only_fields=()):
Expand All @@ -366,8 +368,8 @@ def _getitem_fields(self, where, only_fields=()):
self._valid_when,
self._length,
self._lsb_order,
None,
self._nplike,
parameters=None,
nplike=self._nplike,
).simplify_optiontype()

def _carry(self, carry, allow_lazy):
Expand Down Expand Up @@ -623,8 +625,8 @@ def continuation():
self._valid_when,
self._length,
self._lsb_order,
self._parameters if options["keep_parameters"] else None,
self._nplike,
parameters=self._parameters if options["keep_parameters"] else None,
nplike=self._nplike,
)

else:
Expand Down Expand Up @@ -668,8 +670,8 @@ def packed(self):
return ak.contents.IndexedOptionArray(
next._index,
content,
next._parameters,
self._nplike,
parameters=next._parameters,
nplike=self._nplike,
)

else:
Expand All @@ -689,8 +691,8 @@ def packed(self):
self._valid_when,
self._length,
self._lsb_order,
self._parameters,
self._nplike,
parameters=self._parameters,
nplike=self._nplike,
)

def _to_list(self, behavior, json_conversions):
Expand Down
Loading