From eab311bb888d112f31a886dc296e9cb6c435541c Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 09:39:29 +0000 Subject: [PATCH 01/15] refactor: make parameters, nplike, keyword arguments --- src/awkward/contents/bitmaskedarray.py | 8 +- src/awkward/contents/bytemaskedarray.py | 33 ++--- src/awkward/contents/content.py | 11 +- src/awkward/contents/indexedarray.py | 18 +-- src/awkward/contents/indexedoptionarray.py | 149 +++++++++++---------- src/awkward/contents/listarray.py | 9 +- src/awkward/contents/listoffsetarray.py | 8 +- src/awkward/contents/regulararray.py | 4 +- src/awkward/contents/unmaskedarray.py | 4 +- src/awkward/operations/ak_from_buffers.py | 2 +- src/awkward/operations/ak_singletons.py | 2 +- 11 files changed, 133 insertions(+), 115 deletions(-) diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index 626ee0771c..baa906f7b3 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -238,8 +238,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): @@ -668,8 +668,8 @@ def packed(self): return ak.contents.IndexedOptionArray( next._index, content, - next._parameters, - self._nplike, + parameters=next._parameters, + nplike=self._nplike, ) else: diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index d74ccc7915..98e2d5d764 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -186,7 +186,7 @@ def to_IndexedOptionArray64(self): ) return ak.contents.IndexedOptionArray( - index, self._content, self._parameters, self._nplike + index, self._content, parameters=self._parameters, nplike=self._nplike ) def to_ByteMaskedArray(self, valid_when): @@ -402,7 +402,7 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta out = next._getitem_next_jagged(reducedstarts, reducedstops, slicecontent, tail) out2 = ak.contents.IndexedOptionArray( - outindex, out, self._parameters, self._nplike + outindex, out, parameters=self._parameters, nplike=self._nplike ) return out2.simplify_optiontype() @@ -426,8 +426,8 @@ def _getitem_next(self, head, tail, advanced): out2 = ak.contents.IndexedOptionArray( outindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out2.simplify_optiontype() @@ -556,7 +556,7 @@ def num(self, axis, depth=0): out = next.num(posaxis, depth) out2 = ak.contents.IndexedOptionArray( - outindex, out, self.parameters, self._nplike + outindex, out, parameters=self.parameters, nplike=self._nplike ) return out2.simplify_optiontype() @@ -575,7 +575,10 @@ def _offsets_and_flattened(self, axis, depth): return ( offsets, ak.contents.IndexedOptionArray( - outindex, flattened, self._parameters, self._nplike + outindex, + flattened, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -668,8 +671,8 @@ def _local_index(self, axis, depth): out2 = ak.contents.IndexedOptionArray( outindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out2.simplify_optiontype() @@ -750,7 +753,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): n, replacement, recordlookup, parameters, posaxis, depth ) out2 = ak.contents.IndexedOptionArray( - outindex, out, parameters, self._nplike + outindex, out, parameters=parameters, nplike=self._nplike ) return out2.simplify_optiontype() @@ -904,8 +907,8 @@ def _reduce_next( tmp = ak.contents.IndexedOptionArray( outindex, out_content, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ).simplify_optiontype() return ak.contents.ListOffsetArray( @@ -958,8 +961,8 @@ def _pad_none(self, target, axis, depth, clip): return ak.contents.IndexedOptionArray( index, next, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() else: return ak.contents.ByteMaskedArray( @@ -1057,8 +1060,8 @@ def packed(self): return ak.contents.IndexedOptionArray( next._index, content, - next._parameters, - self._nplike, + parameters=next._parameters, + nplike=self._nplike, ) else: diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index e336631917..9fdb295895 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -383,7 +383,7 @@ def _getitem_next_regular_missing( ) out = ak.contents.IndexedOptionArray( - outindex, raw.content, self._parameters, self._nplike + outindex, raw.content, parameters=self._parameters, nplike=self._nplike ) return ak.contents.RegularArray( @@ -443,7 +443,7 @@ def _getitem_next_missing_jagged( tmp = content._getitem_next_jagged(starts, stops, jagged.content, tail) out = ak.contents.IndexedOptionArray( - outputmask, tmp, self._parameters, self._nplike + outputmask, tmp, parameters=self._parameters, nplike=self._nplike ) return ak.contents.RegularArray( out.simplify_optiontype(), @@ -1489,8 +1489,8 @@ def pad_none_axis0(self, target: Integral, clip: bool) -> Content: next = ak.contents.IndexedOptionArray( index, self, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return next.simplify_optiontype() @@ -1815,3 +1815,6 @@ def _layout_equal( def _repr(self, indent: str, pre: str, post: str) -> str: raise ak._errors.wrap_error(NotImplementedError) + + def numbers_to_type(self, name: str) -> Self: + raise ak._errors.wrap_error(NotImplementedError) diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index 69a027491b..889a0d9059 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -143,7 +143,7 @@ def merge_parameters(self, parameters): def to_IndexedOptionArray64(self): return ak.contents.IndexedOptionArray( - self._index, self._content, self._parameters, self._nplike + self._index, self._content, parameters=self._parameters, nplike=self._nplike ) def mask_as_bool(self, valid_when=True): @@ -325,8 +325,8 @@ def project(self, mask=None): next = ak.contents.IndexedOptionArray( nextindex, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return next.project() @@ -421,8 +421,8 @@ def simplify_optiontype(self): return ak.contents.IndexedOptionArray( result, self._content.content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -799,8 +799,8 @@ def _unique(self, negaxis, starts, parents, outlength): return ak.contents.IndexedOptionArray( nextoutindex, unique, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() if not branch and negaxis == depth: @@ -859,8 +859,8 @@ def _unique(self, negaxis, starts, parents, outlength): out = ak.contents.IndexedOptionArray( nextoutindex, unique, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() return out diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index c2f394e08c..7466cd0719 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -25,8 +25,8 @@ def copy( return IndexedOptionArray( self._index if index is unset else index, self._content if content is unset else content, - 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): @@ -39,7 +39,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, index, content, parameters=None, nplike=None): + def __init__(self, index, content, *, parameters=None, nplike=None): if not ( isinstance(index, Index) and index.dtype @@ -102,8 +102,8 @@ def typetracer(self): return IndexedOptionArray( ak.index.Index(self._index.raw(tt)), self._content.typetracer, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -114,8 +114,8 @@ def _forget_length(self): return IndexedOptionArray( self._index.forget_length(), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -137,8 +137,8 @@ def merge_parameters(self, parameters): return IndexedOptionArray( self._index, self._content, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_IndexedOptionArray64(self): @@ -148,8 +148,8 @@ def to_IndexedOptionArray64(self): return IndexedOptionArray( self._index.astype(np.int64), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def to_ByteMaskedArray(self, valid_when): @@ -171,8 +171,8 @@ def to_ByteMaskedArray(self, valid_when): mask, content, valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def to_BitMaskedArray(self, valid_when, lsb_order): @@ -214,24 +214,24 @@ def _getitem_range(self, where): return IndexedOptionArray( self._index[start:stop], self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): return IndexedOptionArray( self._index, self._content._getitem_field(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _getitem_fields(self, where, only_fields=()): return IndexedOptionArray( self._index, self._content._getitem_fields(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _carry(self, carry, allow_lazy): @@ -245,8 +245,8 @@ def _carry(self, carry, allow_lazy): return IndexedOptionArray( nextindex, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _nextcarry_outindex(self, nplike): @@ -337,7 +337,7 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta out = next._getitem_next_jagged(reducedstarts, reducedstops, slicecontent, tail) out2 = ak.contents.IndexedOptionArray( - outindex, out, self._parameters, self._nplike + outindex, out, parameters=self._parameters, nplike=self._nplike ) return out2.simplify_optiontype() @@ -359,7 +359,9 @@ def _getitem_next(self, head, tail, advanced): next = self._content._carry(nextcarry, True) out = next._getitem_next(head, tail, advanced) - out2 = IndexedOptionArray(outindex, out, self._parameters, self._nplike) + out2 = IndexedOptionArray( + outindex, out, parameters=self._parameters, nplike=self._nplike + ) return out2.simplify_optiontype() elif isinstance(head, str): @@ -412,8 +414,8 @@ def project(self, mask=None): next = ak.contents.IndexedOptionArray( nextindex, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return next.project() else: @@ -506,8 +508,8 @@ def simplify_optiontype(self): return ak.contents.IndexedOptionArray( result, self._content.content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -525,7 +527,7 @@ def num(self, axis, depth=0): next = self._content._carry(nextcarry, False) out = next.num(posaxis, depth) out2 = ak.contents.IndexedOptionArray( - outindex, out, self.parameters, self._nplike + outindex, out, parameters=self.parameters, nplike=self._nplike ) return out2.simplify_optiontype() @@ -543,7 +545,10 @@ def _offsets_and_flattened(self, axis, depth): return ( offsets, ak.contents.IndexedOptionArray( - outindex, flattened, self._parameters, self._nplike + outindex, + flattened, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -663,7 +668,9 @@ def _reverse_merge(self, other): ) parameters = ak._util.merge_parameters(self._parameters, other._parameters) - return ak.contents.IndexedOptionArray(index, content, parameters, self._nplike) + return ak.contents.IndexedOptionArray( + index, content, parameters=parameters, nplike=self._nplike + ) def mergemany(self, others): if len(others) == 0: @@ -740,7 +747,7 @@ def mergemany(self, others): tail_contents = contents[1:] nextcontent = contents[0].mergemany(tail_contents) next = ak.contents.IndexedOptionArray( - nextindex, nextcontent, parameters, self._nplike + nextindex, nextcontent, parameters=parameters, nplike=self._nplike ) if len(tail) == 0: @@ -775,7 +782,7 @@ def fill_none(self, value): ](index.data, self._index.data, tags.length) ) out = ak.contents.UnionArray( - tags, index, contents, self._parameters, self._nplike + tags, index, contents, parameters=self._parameters, nplike=self._nplike ) return out.simplify_uniontype(True, True) @@ -791,8 +798,8 @@ def _local_index(self, axis, depth): out2 = ak.contents.IndexedOptionArray( outindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out2 @@ -864,8 +871,8 @@ def numbers_to_type(self, name): return ak.contents.IndexedOptionArray( self._index, self._content.numbers_to_type(name), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -921,8 +928,8 @@ def _unique(self, negaxis, starts, parents, outlength): return ak.contents.IndexedOptionArray( nextoutindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() if isinstance(out, ak.contents.ListOffsetArray): @@ -976,15 +983,15 @@ def _unique(self, negaxis, starts, parents, outlength): out = ak.contents.IndexedOptionArray( newindex[: newoffsets[-1]], out._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() return ak.contents.ListOffsetArray( newoffsets, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) if isinstance(out, ak.contents.NumpyArray): @@ -1007,8 +1014,8 @@ def _unique(self, negaxis, starts, parents, outlength): return ak.contents.IndexedOptionArray( nextoutindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() if inject_nones: @@ -1016,8 +1023,8 @@ def _unique(self, negaxis, starts, parents, outlength): out, out.length, 0, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out @@ -1223,8 +1230,8 @@ def _argsort_next( out = ak.contents.IndexedOptionArray( nextoutindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() inject_nones = ( @@ -1239,8 +1246,8 @@ def _argsort_next( return ak.contents.IndexedOptionArray( outindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() # Otherwise, if we are rearranging (e.g sorting) the contents of this layout, # then we do NOT want to return an optional layout, @@ -1289,8 +1296,8 @@ def _sort_next( out = ak.contents.IndexedOptionArray( nextoutindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() inject_nones = True if not branch and negaxis != depth else False @@ -1303,8 +1310,8 @@ def _sort_next( return ak.contents.IndexedOptionArray( outindex, out, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() # Otherwise, if we are rearranging (e.g sorting) the contents of this layout, # then we do NOT want to return an optional layout @@ -1400,16 +1407,16 @@ def _reduce_next( inner = ak.contents.IndexedOptionArray( outindex, out_content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() # Re-wrap content return ak.contents.ListOffsetArray( outoffsets, inner, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): @@ -1423,7 +1430,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): n, replacement, recordlookup, parameters, posaxis, depth ) out2 = ak.contents.IndexedOptionArray( - outindex, out, parameters, self._nplike + outindex, out, parameters=parameters, nplike=self._nplike ) return out2.simplify_optiontype() @@ -1480,15 +1487,15 @@ def _pad_none(self, target, axis, depth, clip): return ak.contents.IndexedOptionArray( index, next, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() else: return ak.contents.IndexedOptionArray( self._index, self._content._pad_none(target, posaxis, depth, clip), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): @@ -1607,8 +1614,8 @@ def continuation(): lateral_context, options, ), - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -1651,8 +1658,8 @@ def packed(self): return ak.contents.IndexedOptionArray( self._index, self._content.packed(), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -1667,8 +1674,8 @@ def packed(self): return ak.contents.IndexedOptionArray( ak.index.Index(new_index, nplike=self.nplike), self.project().packed(), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_list(self, behavior, json_conversions): @@ -1691,7 +1698,9 @@ def _to_list(self, behavior, json_conversions): def _to_nplike(self, nplike): index = self._index._to_nplike(nplike) content = self._content._to_nplike(nplike) - return IndexedOptionArray(index, content, self.parameters, nplike=nplike) + return IndexedOptionArray( + index, content, parameters=self.parameters, nplike=nplike + ) def _layout_equal(self, other, index_dtype=True, numpyarray=True): return self.index.layout_equal( diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 7edc402347..d5ed6b5066 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -521,7 +521,10 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): else: missing_trim = missing indexedoptionarray = ak.contents.IndexedOptionArray( - missing_trim, content, self._parameters, self._nplike + missing_trim, + content, + parameters=self._parameters, + nplike=self._nplike, ) if isinstance(self._nplike, ak._typetracer.TypeTracer): indexedoptionarray = indexedoptionarray.typetracer @@ -1334,8 +1337,8 @@ def _pad_none(self, target, axis, depth, clip): next = ak.contents.IndexedOptionArray( index, self._content, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) return ak.contents.ListArray( diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index c73d7c36fe..237ea4eb76 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -1781,8 +1781,8 @@ def _pad_none(self, target, axis, depth, clip): next = ak.contents.IndexedOptionArray( outindex, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return ak.contents.ListOffsetArray( offsets_, @@ -1829,8 +1829,8 @@ def _pad_none(self, target, axis, depth, clip): next = ak.contents.IndexedOptionArray( outindex, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return ak.contents.RegularArray( next.simplify_optiontype(), diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index 2f8e0c31a6..a76bc2d440 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -1176,8 +1176,8 @@ def _pad_none(self, target, axis, depth, clip): next = ak.contents.IndexedOptionArray( index, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return ak.contents.RegularArray( next.simplify_optiontype(), diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index b4157f86b7..356f17f9e0 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -113,8 +113,8 @@ def to_IndexedOptionArray64(self): return ak.contents.IndexedOptionArray( ak.index.Index64(arange, nplike=self.nplike), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def to_ByteMaskedArray(self, valid_when): diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index bbb51e2a9a..c5ebb8d108 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -189,7 +189,7 @@ def reconstitute(form, length, container, getkey, nplike): return ak.contents.IndexedOptionArray( ak.index.Index(index), reconstitute(form.content, next_length, container, getkey, nplike), - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.IndexedForm): diff --git a/src/awkward/operations/ak_singletons.py b/src/awkward/operations/ak_singletons.py index 29ae9910a6..b873bc5aea 100644 --- a/src/awkward/operations/ak_singletons.py +++ b/src/awkward/operations/ak_singletons.py @@ -56,7 +56,7 @@ def action(layout, **kwargs): ak.contents.IndexedOptionArray( layout.index, layout.content, - layout.parameters, + parameters=layout.parameters, ) ) From e8fa681e4ca19e873764e1b8decda7957b4d1e7d Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:14:12 +0000 Subject: [PATCH 02/15] refactor(indexedarray): make parameters, nplike, keyword arguments --- src/awkward/_connect/pyarrow.py | 2 +- src/awkward/contents/content.py | 6 +- src/awkward/contents/indexedarray.py | 70 ++++++++++------------ src/awkward/contents/indexedoptionarray.py | 4 +- src/awkward/contents/recordarray.py | 5 +- src/awkward/operations/ak_from_buffers.py | 2 +- 6 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/awkward/_connect/pyarrow.py b/src/awkward/_connect/pyarrow.py index 5d25fa719e..18b10bc2bd 100644 --- a/src/awkward/_connect/pyarrow.py +++ b/src/awkward/_connect/pyarrow.py @@ -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 diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index 9fdb295895..107df81a6c 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -1208,7 +1208,11 @@ def _combinations_axis0( contents = [] length = None for ptr in tocarry: - contents.append(ak.contents.IndexedArray(ptr, self, None, self._nplike)) + contents.append( + ak.contents.IndexedArray( + ptr, self, parameters=None, nplike=self._nplike + ) + ) length = contents[-1].length assert length is not None return ak.contents.RecordArray( diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index 889a0d9059..6202d1bc01 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -24,8 +24,8 @@ def copy( return IndexedArray( self._index if index is unset else index, self._content if content is unset else content, - 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): @@ -38,7 +38,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, index, content, parameters=None, nplike=None): + def __init__(self, index, content, *, parameters=None, nplike=None): if not ( isinstance(index, Index) and index.dtype @@ -102,8 +102,8 @@ def typetracer(self): return IndexedArray( ak.index.Index(self._index.raw(tt)), self._content.typetracer, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -114,8 +114,8 @@ def _forget_length(self): return IndexedArray( self._index.forget_length(), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -137,8 +137,8 @@ def merge_parameters(self, parameters): return IndexedArray( self._index, self._content, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_IndexedOptionArray64(self): @@ -174,24 +174,24 @@ def _getitem_range(self, where): return IndexedArray( self._index[start:stop], self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): return IndexedArray( self._index, self._content._getitem_field(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _getitem_fields(self, where, only_fields=()): return IndexedArray( self._index, self._content._getitem_fields(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _carry(self, carry, allow_lazy): @@ -203,10 +203,7 @@ def _carry(self, carry, allow_lazy): raise ak._errors.index_error(self, carry.data, str(err)) from err return IndexedArray( - nextindex, - self._content, - self._parameters, - self._nplike, + nextindex, self._content, parameters=self._parameters, nplike=self._nplike ) def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, tail): @@ -405,8 +402,8 @@ def simplify_optiontype(self): return IndexedArray( result, self._content.content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) if isinstance( @@ -534,7 +531,9 @@ def _reverse_merge(self, other): ) parameters = ak._util.merge_parameters(self._parameters, other._parameters) - return ak.contents.IndexedArray(index, content, parameters, self._nplike) + return ak.contents.IndexedArray( + index, content, parameters=parameters, nplike=self._nplike + ) def mergemany(self, others): if len(others) == 0: @@ -610,7 +609,7 @@ def mergemany(self, others): tail_contents = contents[1:] nextcontent = contents[0].mergemany(tail_contents) next = ak.contents.IndexedArray( - nextindex, nextcontent, parameters, self._nplike + nextindex, nextcontent, parameters=parameters, nplike=self._nplike ) if len(tail) == 0: @@ -636,8 +635,8 @@ def fill_none(self, value): return IndexedArray( self._index, self._content.fill_none(value), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _local_index(self, axis, depth): @@ -710,8 +709,8 @@ def numbers_to_type(self, name): return ak.contents.IndexedArray( self._index, self._content.numbers_to_type(name), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -838,10 +837,7 @@ def _unique(self, negaxis, starts, parents, outlength): ) tmp = ak.contents.IndexedArray( - outindex, - unique._content, - None, - self._nplike, + outindex, unique._content, parameters=None, nplike=self._nplike ) return ak.contents.ListOffsetArray( @@ -992,8 +988,8 @@ def _pad_none(self, target, axis, depth, clip): return ak.contents.IndexedArray( self._index, self._content._pad_none(target, posaxis, depth, clip), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): @@ -1006,8 +1002,8 @@ def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): next = IndexedArray( self._index, self._content, - next_parameters, - self._nplike, + parameters=next_parameters, + nplike=self._nplike, ) return next._to_arrow(pyarrow, mask_node, validbytes, length, options) @@ -1083,8 +1079,8 @@ def continuation(): lateral_context, options, ), - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index 7466cd0719..d2606bd83b 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -1513,8 +1513,8 @@ def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): next = ak.contents.IndexedArray( ak.index.Index(index), self._content, - next_parameters, - self._nplike, + parameters=next_parameters, + nplike=self._nplike, ) return next._to_arrow( pyarrow, diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 2c1edfae1d..0a93f18c50 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -374,10 +374,7 @@ def _carry(self, carry, allow_lazy): nextindex = ak.index.Index64(where, nplike=self.nplike) return ak.contents.IndexedArray( - nextindex, - self, - None, - self._nplike, + nextindex, self, parameters=None, nplike=self._nplike ) else: diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index c5ebb8d108..88829c1101 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -201,7 +201,7 @@ def reconstitute(form, length, container, getkey, nplike): return ak.contents.IndexedArray( ak.index.Index(index), reconstitute(form.content, next_length, container, getkey, nplike), - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.ListForm): From 222c6519016c93ad009ecf59af9dcf6f2c360694 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:19:29 +0000 Subject: [PATCH 03/15] refactor(emptyarray): make parameters, nplike, keyword arguments --- src/awkward/contents/emptyarray.py | 26 +++++++++++++---------- src/awkward/operations/ak_from_buffers.py | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/awkward/contents/emptyarray.py b/src/awkward/contents/emptyarray.py index 4fb2d3631f..299c0247e4 100644 --- a/src/awkward/contents/emptyarray.py +++ b/src/awkward/contents/emptyarray.py @@ -20,8 +20,8 @@ def copy( nplike=unset, ): return EmptyArray( - 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): @@ -30,7 +30,7 @@ def __copy__(self): def __deepcopy__(self, memo): return self.copy(parameters=copy.deepcopy(self._parameters, memo)) - def __init__(self, parameters=None, nplike=None): + def __init__(self, *, parameters=None, nplike=None): if nplike is None: nplike = numpy self._init(parameters, nplike) @@ -46,14 +46,14 @@ def _to_buffers(self, form, getkey, container, nplike): @property def typetracer(self): tt = ak._typetracer.TypeTracer.instance() - return EmptyArray(self._parameters, tt) + return EmptyArray(parameters=self._parameters, nplike=tt) @property def length(self): return 0 def _forget_length(self): - return EmptyArray(self._parameters, self._nplike) + return EmptyArray(parameters=self._parameters, nplike=self._nplike) def __repr__(self): return self._repr("", "", "") @@ -71,7 +71,8 @@ def _repr(self, indent, pre, post): def merge_parameters(self, parameters): return EmptyArray( - ak._util.merge_parameters(self._parameters, parameters), self._nplike + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_NumpyArray(self, dtype, nplike=None): @@ -179,7 +180,10 @@ def _offsets_and_flattened(self, axis, depth): ) else: offsets = ak.index.Index64.zeros(1, self._nplike) - return (offsets, EmptyArray(self._parameters, self._nplike)) + return ( + offsets, + EmptyArray(parameters=self._parameters, nplike=self._nplike), + ) def _mergeable(self, other, mergebool): return True @@ -196,7 +200,7 @@ def mergemany(self, others): return others[0].mergemany(tail_others) def fill_none(self, value): - return EmptyArray(self._parameters, self._nplike) + return EmptyArray(parameters=self._parameters, nplike=self._nplike) def _local_index(self, axis, depth): return ak.contents.NumpyArray( @@ -204,7 +208,7 @@ def _local_index(self, axis, depth): ) def numbers_to_type(self, name): - return ak.contents.EmptyArray(self._parameters, self._nplike) + return ak.contents.EmptyArray(parameters=self._parameters, nplike=self._nplike) def _is_unique(self, negaxis, starts, parents, outlength): return True @@ -243,7 +247,7 @@ def _sort_next( return self def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): - return ak.contents.EmptyArray(self._parameters, self._nplike) + return ak.contents.EmptyArray(parameters=self._parameters, nplike=self._nplike) def _reduce_next( self, @@ -326,7 +330,7 @@ def continuation(): if options["keep_parameters"]: return self else: - return EmptyArray(None, self._nplike) + return EmptyArray(parameters=None, nplike=self._nplike) else: diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 88829c1101..397792aaff 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -131,7 +131,7 @@ def reconstitute(form, length, container, getkey, nplike): raise ak._errors.wrap_error( ValueError(f"EmptyForm node, but the expected length is {length}") ) - return ak.contents.EmptyArray(form.parameters) + return ak.contents.EmptyArray(parameters=form.parameters) elif isinstance(form, ak.forms.NumpyForm): dtype = ak.types.numpytype.primitive_to_dtype(form.primitive) From a4c6f2519e9267e30b1059a998ee9f9c8a0356c0 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:25:28 +0000 Subject: [PATCH 04/15] refactor(bytemaskedarray): make parameters, nplike, keyword arguments --- src/awkward/contents/bitmaskedarray.py | 4 +- src/awkward/contents/bytemaskedarray.py | 62 +++++++++++------------ src/awkward/contents/numpyarray.py | 6 +-- src/awkward/contents/unmaskedarray.py | 8 +-- src/awkward/operations/ak_from_buffers.py | 2 +- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index baa906f7b3..e1b6e0bd8f 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -262,8 +262,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): diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index 98e2d5d764..f86ed447f6 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -28,8 +28,8 @@ def copy( 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._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): @@ -42,7 +42,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, mask, content, valid_when, parameters=None, nplike=None): + def __init__(self, mask, content, valid_when, *, parameters=None, nplike=None): if not (isinstance(mask, Index) and mask.dtype == np.dtype(np.int8)): raise ak._errors.wrap_error( TypeError( @@ -126,8 +126,8 @@ def typetracer(self): ak.index.Index(self._mask.raw(tt)), self._content.typetracer, self._valid_when, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -139,8 +139,8 @@ def _forget_length(self): self._mask.forget_length(), self._content, self._valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -165,8 +165,8 @@ def merge_parameters(self, parameters): self._mask, self._content, self._valid_when, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_IndexedOptionArray64(self): @@ -201,8 +201,8 @@ def to_ByteMaskedArray(self, valid_when): ), self._content, valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def to_BitMaskedArray(self, valid_when, lsb_order): @@ -274,8 +274,8 @@ def _getitem_range(self, where): self._mask[start:stop], self._content._getitem_range(slice(start, stop)), self._valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): @@ -283,8 +283,8 @@ def _getitem_field(self, where, only_fields=()): self._mask, self._content._getitem_field(where, only_fields), self._valid_when, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ).simplify_optiontype() def _getitem_fields(self, where, only_fields=()): @@ -292,8 +292,8 @@ def _getitem_fields(self, where, only_fields=()): self._mask, self._content._getitem_fields(where, only_fields), self._valid_when, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ).simplify_optiontype() def _carry(self, carry, allow_lazy): @@ -308,8 +308,8 @@ def _carry(self, carry, allow_lazy): nextmask, self._content._carry(carry, allow_lazy), self._valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _nextcarry_outindex(self, nplike): @@ -488,8 +488,8 @@ def project(self, mask=None): nextmask, self._content, valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return next.project() @@ -649,8 +649,8 @@ def mergemany(self, others): ak.index.Index8(self._nplike.concatenate(masks)), self._content[: self.length].mergemany(tail_contents), self._valid_when, - parameters, - self._nplike, + parameters=parameters, + nplike=self._nplike, ) else: @@ -681,8 +681,8 @@ def numbers_to_type(self, name): self._mask, self._content.numbers_to_type(name), self._valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -969,8 +969,8 @@ def _pad_none(self, target, axis, depth, clip): self._mask, self._content._pad_none(target, posaxis, depth, clip), self._valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): @@ -1016,8 +1016,8 @@ def continuation(): options, ), self._valid_when, - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -1073,8 +1073,8 @@ def packed(self): self._mask, content, self._valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_list(self, behavior, json_conversions): diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index 488b6b4d3a..b4df59e153 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -1149,11 +1149,7 @@ def _reduce_next( ) out = ak.contents.ByteMaskedArray( - outmask, - out, - False, - None, - self._nplike, + outmask, out, False, parameters=None, nplike=self._nplike ) if keepdims: diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index 356f17f9e0..bb7f2ad719 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -124,8 +124,8 @@ def to_ByteMaskedArray(self, valid_when): ), self._content, valid_when, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def to_BitMaskedArray(self, valid_when, lsb_order): @@ -242,8 +242,8 @@ def project(self, mask=None): mask, self._content, False, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).project() else: return self._content diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 397792aaff..c073b84a01 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -175,7 +175,7 @@ def reconstitute(form, length, container, getkey, nplike): ak.index.Index(mask), reconstitute(form.content, length, container, getkey, nplike), form.valid_when, - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.IndexedOptionForm): From f9166aacbf35fcff7da01e439e2c04e5f9aaf50d Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:28:42 +0000 Subject: [PATCH 05/15] refactor(bitmaskedarray): make parameters, nplike, keyword arguments --- src/awkward/contents/bitmaskedarray.py | 41 ++++++++++++----------- src/awkward/contents/bytemaskedarray.py | 8 ++--- src/awkward/contents/unmaskedarray.py | 4 +-- src/awkward/operations/ak_from_buffers.py | 2 +- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index e1b6e0bd8f..0286521fab 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -33,8 +33,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): @@ -54,6 +54,7 @@ def __init__( valid_when, length, lsb_order, + *, parameters=None, nplike=None, ): @@ -170,8 +171,8 @@ def typetracer(self): self._valid_when, self._length, self._lsb_order, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -185,8 +186,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): @@ -215,8 +216,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): @@ -277,8 +278,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: @@ -298,8 +299,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): @@ -355,8 +356,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=()): @@ -366,8 +367,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): @@ -623,8 +624,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: @@ -689,8 +690,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): diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index f86ed447f6..49869d7501 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -217,8 +217,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: @@ -233,8 +233,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): diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index bb7f2ad719..66ab68ea4b 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -141,8 +141,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=True, nplike=None): diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index c073b84a01..cc53dc5755 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -163,7 +163,7 @@ def reconstitute(form, length, container, getkey, nplike): form.valid_when, length, form.lsb_order, - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.ByteMaskedForm): From 5ead9d6b2a05e7b11913c9f827642aeb6a77cec0 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:30:43 +0000 Subject: [PATCH 06/15] refactor(listarray): make parameters, nplike, keyword arguments --- src/awkward/contents/bytemaskedarray.py | 6 +- src/awkward/contents/emptyarray.py | 6 +- src/awkward/contents/indexedarray.py | 6 +- src/awkward/contents/indexedoptionarray.py | 6 +- src/awkward/contents/listarray.py | 76 +++++++++++++--------- src/awkward/contents/listoffsetarray.py | 28 ++++---- src/awkward/contents/numpyarray.py | 6 +- src/awkward/contents/unionarray.py | 6 +- src/awkward/operations/ak_from_buffers.py | 2 +- 9 files changed, 89 insertions(+), 53 deletions(-) diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index 49869d7501..ea2897d19a 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -360,7 +360,11 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "cannot fit jagged slice with length {} into {} of size {}".format( slicestarts.length, type(self).__name__, self.length diff --git a/src/awkward/contents/emptyarray.py b/src/awkward/contents/emptyarray.py index 299c0247e4..637e961f04 100644 --- a/src/awkward/contents/emptyarray.py +++ b/src/awkward/contents/emptyarray.py @@ -117,7 +117,11 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "too many jagged slice dimensions for array", ) diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index 6202d1bc01..1630b312e4 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -211,7 +211,11 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "cannot fit jagged slice with length {} into {} of size {}".format( slicestarts.length, type(self).__name__, self.length diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index d2606bd83b..070a77c072 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -297,7 +297,11 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "cannot fit jagged slice with length {} into {} of size {}".format( slicestarts.length, type(self).__name__, self.length diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index d5ed6b5066..39887a3e59 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -26,8 +26,8 @@ def copy( 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._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): @@ -41,7 +41,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, starts, stops, content, parameters=None, nplike=None): + def __init__(self, starts, stops, content, *, parameters=None, nplike=None): if not isinstance(starts, Index) and starts.dtype in ( np.dtype(np.int32), np.dtype(np.uint32), @@ -131,8 +131,8 @@ def typetracer(self): ak.index.Index(self._starts.raw(tt)), ak.index.Index(self._stops.raw(tt)), self._content.typetracer, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -144,8 +144,8 @@ def _forget_length(self): self._starts.forget_length(), self._stops, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -169,8 +169,8 @@ def merge_parameters(self, parameters): self._starts, self._stops, self._content, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_ListOffsetArray64(self, start_at_zero=False): @@ -236,8 +236,8 @@ def _getitem_range(self, where): self._starts[start:stop], self._stops[start:stop], self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): @@ -245,8 +245,8 @@ def _getitem_field(self, where, only_fields=()): self._starts, self._stops, self._content._getitem_field(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _getitem_fields(self, where, only_fields=()): @@ -254,8 +254,8 @@ def _getitem_fields(self, where, only_fields=()): self._starts, self._stops, self._content._getitem_fields(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _carry(self, carry, allow_lazy): @@ -271,8 +271,8 @@ def _carry(self, carry, allow_lazy): nextstarts, nextstops, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _compact_offsets64(self, start_at_zero): @@ -308,7 +308,11 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "cannot fit jagged slice with length {} into {} of size {}".format( slicestarts.length, type(self).__name__, self.length @@ -429,7 +433,11 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "jagged slice length differs from array length", ) @@ -1064,7 +1072,11 @@ def mergemany(self, others): pass next = ak.contents.ListArray( - nextstarts, nextstops, nextcontent, parameters, self._nplike + nextstarts, + nextstops, + nextcontent, + parameters=parameters, + nplike=self._nplike, ) if len(tail) == 0: @@ -1081,8 +1093,8 @@ def fill_none(self, value): self._starts, self._stops, self._content.fill_none(value), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _local_index(self, axis, depth): @@ -1119,8 +1131,8 @@ def _local_index(self, axis, depth): self._starts, self._stops, self._content._local_index(posaxis, depth + 1), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def numbers_to_type(self, name): @@ -1128,8 +1140,8 @@ def numbers_to_type(self, name): self._starts, self._stops, self._content.numbers_to_type(name), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -1345,16 +1357,16 @@ def _pad_none(self, target, axis, depth, clip): starts_, stops_, next.simplify_optiontype(), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return ak.contents.ListArray( self._starts, self._stops, self._content._pad_none(target, posaxis, depth + 1, clip), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return self.to_ListOffsetArray64(True)._pad_none( @@ -1411,8 +1423,8 @@ def continuation(): lateral_context, options, ), - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 237ea4eb76..8a072e5210 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -263,8 +263,8 @@ def _carry(self, carry, allow_lazy): nextstarts, nextstops, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _compact_offsets64(self, start_at_zero): @@ -334,8 +334,8 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): self.starts, self.stops, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out._getitem_next_jagged(slicestarts, slicestops, slicecontent, tail) @@ -595,8 +595,8 @@ def _getitem_next(self, head, tail, advanced): self.starts, self.stops, self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return listarray._getitem_next(head, tail, advanced) @@ -736,7 +736,11 @@ def mergemany(self, others): if len(others) == 0: return self listarray = ak.contents.ListArray( - self.starts, self.stops, self._content, self._parameters, self._nplike + self.starts, + self.stops, + self._content, + parameters=self._parameters, + nplike=self._nplike, ) out = listarray.mergemany(others) @@ -1531,11 +1535,7 @@ def _reduce_next( ) out = ak.contents.ListArray( - outstarts, - outstops, - outcontent, - None, - self._nplike, + outstarts, outstops, outcontent, parameters=None, nplike=self._nplike ) if keepdims: @@ -1878,8 +1878,8 @@ def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): ak.index.Index(new_starts), ak.index.Index(new_stops), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return next.to_ListOffsetArray64(True)._to_arrow( pyarrow, mask_node, validbytes, length, options diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index b4df59e153..e50d663bda 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -260,7 +260,11 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "too many jagged slice dimensions for array", ) diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index 150d4db364..a206634a24 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -405,7 +405,11 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta raise ak._errors.index_error( self, ak.contents.ListArray( - slicestarts, slicestops, slicecontent, None, self._nplike + slicestarts, + slicestops, + slicecontent, + parameters=None, + nplike=self._nplike, ), "cannot apply jagged slices to irreducible union arrays", ) diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index cc53dc5755..7679922e82 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -219,7 +219,7 @@ def reconstitute(form, length, container, getkey, nplike): ak.index.Index(starts), ak.index.Index(stops), reconstitute(form.content, next_length, container, getkey, nplike), - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.ListOffsetForm): From 36d1b810895ad57a569f052be4d838177ef09b5d Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:33:43 +0000 Subject: [PATCH 07/15] refactor(listoffsetarray): make parameters, nplike, keyword arguments --- src/awkward/contents/bytemaskedarray.py | 5 +- src/awkward/contents/indexedarray.py | 5 +- src/awkward/contents/listarray.py | 33 ++--- src/awkward/contents/listoffsetarray.py | 143 ++++++++++------------ src/awkward/contents/numpyarray.py | 4 +- src/awkward/contents/regulararray.py | 9 +- src/awkward/operations/ak_from_buffers.py | 2 +- 7 files changed, 93 insertions(+), 108 deletions(-) diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index ea2897d19a..666dfa3716 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -916,10 +916,7 @@ def _reduce_next( ).simplify_optiontype() return ak.contents.ListOffsetArray( - outoffsets, - tmp, - None, - self._nplike, + outoffsets, tmp, parameters=None, nplike=self._nplike ) def _validity_error(self, path): diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index 1630b312e4..acf9e338db 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -845,10 +845,7 @@ def _unique(self, negaxis, starts, parents, outlength): ) return ak.contents.ListOffsetArray( - outoffsets, - tmp, - None, - self._nplike, + outoffsets, tmp, parameters=None, nplike=self._nplike ) elif isinstance(unique, ak.contents.NumpyArray): diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 39887a3e59..1f13c27d79 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -184,8 +184,8 @@ def to_ListOffsetArray64(self, start_at_zero=False): return ListOffsetArray( ak.index.Index(offsets, nplike=self._nplike), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) elif self._nplike.index_nplike.array_equal(starts[1:], stops[:-1]): @@ -200,8 +200,8 @@ def to_ListOffsetArray64(self, start_at_zero=False): return ListOffsetArray( ak.index.Index(offsets, nplike=self._nplike), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).to_ListOffsetArray64(start_at_zero=start_at_zero) else: @@ -359,7 +359,7 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): ) return ak.contents.ListOffsetArray( - outoffsets, outcontent, self._parameters, self._nplike + outoffsets, outcontent, parameters=self._parameters, nplike=self._nplike ) elif isinstance(slicecontent, ak.contents.NumpyArray): @@ -425,7 +425,7 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): outcontent = nextcontent._getitem_next(nexthead, nexttail, None) return ak.contents.ListOffsetArray( - outoffsets, outcontent, None, self._nplike + outoffsets, outcontent, parameters=None, nplike=self._nplike ) elif isinstance(slicecontent, ak.contents.IndexedOptionArray): @@ -511,7 +511,10 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): as_list_offset_array = self.to_ListOffsetArray64(True) nextcontent = as_list_offset_array._content._carry(nextcarry, True) next = ak.contents.ListOffsetArray( - smalloffsets, nextcontent, self._parameters, self._nplike + smalloffsets, + nextcontent, + parameters=self._parameters, + nplike=self._nplike, ) out = next._getitem_next_jagged( smalloffsets[:-1], smalloffsets[1:], slicecontent._content, tail @@ -539,8 +542,8 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): return ak.contents.ListOffsetArray( largeoffsets, indexedoptionarray.simplify_optiontype(), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: raise ak._errors.wrap_error( @@ -675,8 +678,8 @@ def _getitem_next(self, head, tail, advanced): return ak.contents.ListOffsetArray( nextoffsets, nextcontent._getitem_next(nexthead, nexttail, advanced), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: if self._nplike.known_shape: @@ -725,8 +728,8 @@ def _getitem_next(self, head, tail, advanced): return ak.contents.ListOffsetArray( nextoffsets, nextcontent._getitem_next(nexthead, nexttail, nextadvanced), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) elif isinstance(head, str): @@ -1123,8 +1126,8 @@ def _local_index(self, axis, depth): return ak.contents.ListOffsetArray( offsets, ak.contents.NumpyArray(localindex), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return ak.contents.ListArray( diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 8a072e5210..ac1ca8ef5d 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -24,8 +24,8 @@ def copy( return ListOffsetArray( self._offsets if offsets is unset else offsets, self._content if content is unset else content, - 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): @@ -38,7 +38,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, offsets, content, parameters=None, nplike=None): + def __init__(self, offsets, content, *, parameters=None, nplike=None): if not isinstance(offsets, Index) and offsets.dtype in ( np.dtype(np.int32), np.dtype(np.uint32), @@ -114,8 +114,8 @@ def typetracer(self): return ListOffsetArray( ak.index.Index(self._offsets.raw(tt)), self._content.typetracer, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -126,8 +126,8 @@ def _forget_length(self): return ListOffsetArray( self._offsets.forget_length(), self._content, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -149,8 +149,8 @@ def merge_parameters(self, parameters): return ListOffsetArray( self._offsets, self._content, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_ListOffsetArray64(self, start_at_zero=False): @@ -171,7 +171,9 @@ def to_ListOffsetArray64(self, start_at_zero=False): else: offsets, content = self._offsets, self._content - return ListOffsetArray(offsets, content, self._parameters, self._nplike) + return ListOffsetArray( + offsets, content, parameters=self._parameters, nplike=self._nplike + ) else: offsets = self._compact_offsets64(start_at_zero) @@ -228,26 +230,23 @@ def _getitem_range(self, where): nplike=self.nplike, ) return ListOffsetArray( - offsets, - self._content, - self._parameters, - self._nplike, + offsets, self._content, parameters=self._parameters, nplike=self._nplike ) def _getitem_field(self, where, only_fields=()): return ListOffsetArray( self._offsets, self._content._getitem_field(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _getitem_fields(self, where, only_fields=()): return ListOffsetArray( self._offsets, self._content._getitem_fields(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _carry(self, carry, allow_lazy): @@ -327,7 +326,9 @@ def _broadcast_tooffsets64(self, offsets): nextcontent = self._content._carry(nextcarry, True) - return ListOffsetArray(offsets, nextcontent, self._parameters, self._nplike) + return ListOffsetArray( + offsets, nextcontent, parameters=self._parameters, nplike=self._nplike + ) def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): out = ak.contents.ListArray( @@ -447,8 +448,8 @@ def _getitem_next(self, head, tail, advanced): return ak.contents.ListOffsetArray( nextoffsets, nextcontent._getitem_next(nexthead, nexttail, advanced), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -493,8 +494,8 @@ def _getitem_next(self, head, tail, advanced): return ak.contents.ListOffsetArray( nextoffsets, nextcontent._getitem_next(nexthead, nexttail, nextadvanced), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) elif isinstance(head, str): @@ -639,7 +640,7 @@ def num(self, axis, depth=0): next = self._content.num(posaxis, depth + 1) offsets = self._compact_offsets64(True) return ak.contents.ListOffsetArray( - offsets, next, self.parameters, self._nplike + offsets, next, parameters=self.parameters, nplike=self._nplike ) def _offsets_and_flattened(self, axis, depth): @@ -663,7 +664,10 @@ def _offsets_and_flattened(self, axis, depth): return ( offsets, ListOffsetArray( - self._offsets, flattened, self._parameters, self._nplike + self._offsets, + flattened, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -672,7 +676,10 @@ def _offsets_and_flattened(self, axis, depth): return ( offsets, ListOffsetArray( - tooffsets, flattened, self._parameters, self._nplike + tooffsets, + flattened, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -702,7 +709,10 @@ def _offsets_and_flattened(self, axis, depth): return ( offsets, ListOffsetArray( - tooffsets, flattened, self._parameters, self._nplike + tooffsets, + flattened, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -756,8 +766,8 @@ def fill_none(self, value): return ListOffsetArray( self._offsets, self._content.fill_none(value), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _local_index(self, axis, depth): @@ -786,23 +796,23 @@ def _local_index(self, axis, depth): return ak.contents.ListOffsetArray( offsets, ak.contents.NumpyArray(localindex), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return ak.contents.ListOffsetArray( self._offsets, self._content._local_index(posaxis, depth + 1), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def numbers_to_type(self, name): return ak.contents.ListOffsetArray( self._offsets, self._content.numbers_to_type(name), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -827,10 +837,7 @@ def _is_unique(self, negaxis, starts, parents, outlength): if isinstance(self._content, ak.contents.NumpyArray): out, outoffsets = self._content._as_unique_strings(self._offsets) out2 = ak.contents.ListOffsetArray( - outoffsets, - out, - self._parameters, - self._nplike, + outoffsets, out, parameters=self._parameters, nplike=self._nplike ) return out2.length == self.length @@ -883,10 +890,7 @@ def _unique(self, negaxis, starts, parents, outlength): if isinstance(self._content, ak.contents.NumpyArray): out, nextoffsets = self._content._as_unique_strings(self._offsets) return ak.contents.ListOffsetArray( - nextoffsets, - out, - self._parameters, - self._nplike, + nextoffsets, out, parameters=self._parameters, nplike=self._nplike ) if not branch and (negaxis == depth): @@ -935,8 +939,8 @@ def _unique(self, negaxis, starts, parents, outlength): return ak.contents.ListOffsetArray( outcontent._compact_offsets64(True), outcontent._content._carry(outcarry, False), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -973,10 +977,7 @@ def _unique(self, negaxis, starts, parents, outlength): outoffsets = self._compact_offsets64(True) return ak.contents.ListOffsetArray( - outoffsets, - outcontent, - self._parameters, - self._nplike, + outoffsets, outcontent, parameters=self._parameters, nplike=self._nplike ) def _argsort_next( @@ -1127,10 +1128,7 @@ def _argsort_next( out_offsets = self._compact_offsets64(True) out = outcontent._carry(outcarry, False) return ak.contents.ListOffsetArray( - out_offsets, - out, - self._parameters, - self._nplike, + out_offsets, out, parameters=self._parameters, nplike=self._nplike ) else: nextparents = ak.index.Index64.empty( @@ -1167,10 +1165,7 @@ def _argsort_next( ) outoffsets = self._compact_offsets64(True) return ak.contents.ListOffsetArray( - outoffsets, - outcontent, - self._parameters, - self._nplike, + outoffsets, outcontent, parameters=self._parameters, nplike=self._nplike ) def _sort_next( @@ -1274,8 +1269,8 @@ def _sort_next( return ak.contents.ListOffsetArray( self._compact_offsets64(True), outcontent._carry(outcarry, False), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: nextparents = ak.index.Index64.empty( @@ -1311,10 +1306,7 @@ def _sort_next( ) outoffsets = self._compact_offsets64(True) return ak.contents.ListOffsetArray( - outoffsets, - outcontent, - self._parameters, - self._nplike, + outoffsets, outcontent, parameters=self._parameters, nplike=self._nplike ) def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): @@ -1407,7 +1399,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): contents, recordlookup, None, parameters, self._nplike ) return ak.contents.ListOffsetArray( - offsets, recordarray, self._parameters, self._nplike + offsets, recordarray, parameters=self._parameters, nplike=self._nplike ) else: compact = self.to_ListOffsetArray64(True) @@ -1415,7 +1407,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): n, replacement, recordlookup, parameters, posaxis, depth + 1 ) return ak.contents.ListOffsetArray( - compact.offsets, next, self._parameters, self._nplike + compact.offsets, next, parameters=self._parameters, nplike=self._nplike ) def _reduce_next( @@ -1611,10 +1603,7 @@ def _reduce_next( outcontent = outcontent.to_ListOffsetArray64(False) return ak.contents.ListOffsetArray( - outoffsets, - outcontent, - None, - self._nplike, + outoffsets, outcontent, parameters=None, nplike=self._nplike ) def _rearrange_prepare_next(self, outlength, parents): @@ -1787,8 +1776,8 @@ def _pad_none(self, target, axis, depth, clip): return ak.contents.ListOffsetArray( offsets_, next.simplify_optiontype(), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: starts_ = ak.index.Index64.empty(self._offsets.length - 1, self._nplike) @@ -1843,8 +1832,8 @@ def _pad_none(self, target, axis, depth, clip): return ak.contents.ListOffsetArray( self._offsets, self._content._pad_none(target, posaxis, depth + 1, clip), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): @@ -2002,8 +1991,8 @@ def continuation(): lateral_context, options, ), - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -2041,7 +2030,9 @@ def packed(self): content = next._content.packed() if content.length != next._offsets[-1]: content = content[: next._offsets[-1]] - return ListOffsetArray(next._offsets, content, next._parameters, self._nplike) + return ListOffsetArray( + next._offsets, content, parameters=next._parameters, nplike=self._nplike + ) def _to_list(self, behavior, json_conversions): starts, stops = self.starts, self.stops diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index e50d663bda..82a82e222b 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -827,8 +827,8 @@ def _unique(self, negaxis, starts, parents, outlength): return ak.contents.ListOffsetArray( outoffsets, ak.contents.NumpyArray(out), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _argsort_next( diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index a76bc2d440..09b435de5d 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -319,7 +319,7 @@ def _broadcast_tooffsets64(self, offsets): ) nextcontent = self._content._carry(nextcarry, True) return ak.contents.ListOffsetArray( - offsets, nextcontent, self._parameters, self._nplike + offsets, nextcontent, parameters=self._parameters, nplike=self._nplike ) else: @@ -334,7 +334,7 @@ def _broadcast_tooffsets64(self, offsets): ) ) return ak.contents.ListOffsetArray( - offsets, self._content, self._parameters, self._nplike + offsets, self._content, parameters=self._parameters, nplike=self._nplike ) def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): @@ -1133,10 +1133,7 @@ def _reduce_next( ) return ak.contents.ListOffsetArray( - outoffsets, - outcontent, - None, - self._nplike, + outoffsets, outcontent, parameters=None, nplike=self._nplike ) def _validity_error(self, path): diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 7679922e82..557abe263a 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -231,7 +231,7 @@ def reconstitute(form, length, container, getkey, nplike): return ak.contents.ListOffsetArray( ak.index.Index(offsets), reconstitute(form.content, next_length, container, getkey, nplike), - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.RegularForm): From e322f1c212012678a54b7c74d0420bcbe829d9c1 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:37:05 +0000 Subject: [PATCH 08/15] refactor(numpyarray): make parameters, nplike, keyword arguments --- src/awkward/_connect/jax/trees.py | 4 +- src/awkward/contents/content.py | 6 +- src/awkward/contents/emptyarray.py | 8 ++- src/awkward/contents/indexedoptionarray.py | 4 +- src/awkward/contents/listarray.py | 2 +- src/awkward/contents/listoffsetarray.py | 6 +- src/awkward/contents/numpyarray.py | 74 +++++++++------------- src/awkward/contents/recordarray.py | 8 ++- src/awkward/contents/regulararray.py | 8 ++- src/awkward/contents/unionarray.py | 2 +- src/awkward/operations/ak_from_buffers.py | 2 +- src/awkward/operations/ak_full_like.py | 9 +-- 12 files changed, 66 insertions(+), 67 deletions(-) diff --git a/src/awkward/_connect/jax/trees.py b/src/awkward/_connect/jax/trees.py index 47abba9210..28e17260ef 100644 --- a/src/awkward/_connect/jax/trees.py +++ b/src/awkward/_connect/jax/trees.py @@ -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) diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index 107df81a6c..afe07537f8 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -637,7 +637,9 @@ def _getitem(self, where): return self._getitem(layout) else: return self._getitem( - ak.contents.NumpyArray(as_array, None, layout.nplike) + ak.contents.NumpyArray( + as_array, parameters=None, nplike=layout.nplike + ) ) else: @@ -731,7 +733,7 @@ def _local_index_axis0(self) -> ak.contents.NumpyArray: localindex.length, ) ) - return ak.contents.NumpyArray(localindex, None, self._nplike) + return ak.contents.NumpyArray(localindex, parameters=None, nplike=self._nplike) def merge(self, other: Content) -> Content: others = [other] diff --git a/src/awkward/contents/emptyarray.py b/src/awkward/contents/emptyarray.py index 637e961f04..4daeb2c62f 100644 --- a/src/awkward/contents/emptyarray.py +++ b/src/awkward/contents/emptyarray.py @@ -80,7 +80,9 @@ def to_NumpyArray(self, dtype, nplike=None): nplike = self._nplike if nplike is None: nplike = numpy - return ak.contents.NumpyArray(nplike.empty(0, dtype), self._parameters, nplike) + return ak.contents.NumpyArray( + nplike.empty(0, dtype), parameters=self._parameters, nplike=nplike + ) def __array__(self, **kwargs): return numpy.empty((0,)) @@ -174,7 +176,7 @@ def num(self, axis, depth=0): return out else: out = ak.index.Index64.empty(0, self._nplike) - return ak.contents.NumpyArray(out, None, self._nplike) + return ak.contents.NumpyArray(out, parameters=None, nplike=self._nplike) def _offsets_and_flattened(self, axis, depth): posaxis = self.axis_wrap_if_negative(axis) @@ -208,7 +210,7 @@ def fill_none(self, value): def _local_index(self, axis, depth): return ak.contents.NumpyArray( - self._nplike.empty(0, np.int64), None, self._nplike + self._nplike.empty(0, np.int64), parameters=None, nplike=self._nplike ) def numbers_to_type(self, name): diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index 070a77c072..f90457499a 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -1188,7 +1188,9 @@ def _argsort_next( # We can test for this condition by seeing whether the NumpyArray of indices # is mergeable with our content (`out = next._argsort_next result`). # If so, try to concatenate them at the end of `out`.` - nulls_index_content = ak.contents.NumpyArray(nulls_index, None, self._nplike) + nulls_index_content = ak.contents.NumpyArray( + nulls_index, parameters=None, nplike=self._nplike + ) if out.mergeable(nulls_index_content, True): out = out.merge(nulls_index_content) nulls_merged = True diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 1f13c27d79..c6ea4ddbdb 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -919,7 +919,7 @@ def num(self, axis, depth=0): self.length, ) ) - return ak.contents.NumpyArray(tonum, None, self._nplike) + return ak.contents.NumpyArray(tonum, parameters=None, nplike=self._nplike) else: return self.to_ListOffsetArray64(True).num(posaxis, depth) diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index ac1ca8ef5d..6412f829c0 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -635,7 +635,7 @@ def num(self, axis, depth=0): self.length, ) ) - return ak.contents.NumpyArray(tonum, None, self._nplike) + return ak.contents.NumpyArray(tonum, parameters=None, nplike=self._nplike) else: next = self._content.num(posaxis, depth + 1) offsets = self._compact_offsets64(True) @@ -1038,7 +1038,9 @@ def _argsort_next( True, ) ) - return ak.contents.NumpyArray(nextcarry, None, self._nplike) + return ak.contents.NumpyArray( + nextcarry, parameters=None, nplike=self._nplike + ) if not branch and (negaxis == depth): if ( diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index 82a82e222b..a60441f648 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -22,8 +22,8 @@ def copy( ): return NumpyArray( self._data if data is unset else data, - 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): @@ -35,7 +35,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, data, parameters=None, nplike=None): + def __init__(self, data, *, parameters=None, nplike=None): if nplike is None: nplike = ak.nplikes.nplike_of(data) if isinstance(data, ak.index.Index): @@ -111,11 +111,7 @@ def _to_buffers(self, form, getkey, container, nplike): @property def typetracer(self): tt = ak._typetracer.TypeTracer.instance() - return NumpyArray( - self.raw(tt), - self._parameters, - tt, - ) + return NumpyArray(self.raw(tt), parameters=self._parameters, nplike=tt) @property def length(self): @@ -123,9 +119,7 @@ def length(self): def _forget_length(self): return NumpyArray( - self._data.forget_length(), - self._parameters, - self._nplike, + self._data.forget_length(), parameters=self._parameters, nplike=self._nplike ) def __repr__(self): @@ -168,8 +162,8 @@ def _repr(self, indent, pre, post): def merge_parameters(self, parameters): return NumpyArray( self._data, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_RegularArray(self): @@ -178,7 +172,7 @@ def to_RegularArray(self): for x in shape: zeroslen.append(zeroslen[-1] * x) - out = NumpyArray(self._data.reshape(-1), None, self._nplike) + out = NumpyArray(self._data.reshape(-1), parameters=None, nplike=self._nplike) for i in range(len(shape) - 1, 0, -1): out = ak.contents.RegularArray( out, shape[i], zeroslen[i], None, self._nplike @@ -198,9 +192,7 @@ def __iter__(self): def _getitem_nothing(self): tmp = self._data[0:0] return NumpyArray( - tmp.reshape((0,) + tmp.shape[2:]), - None, - self._nplike, + tmp.reshape((0,) + tmp.shape[2:]), parameters=None, nplike=self._nplike ) def _getitem_at(self, where): @@ -213,7 +205,7 @@ def _getitem_at(self, where): raise ak._errors.index_error(self, where, str(err)) from err if hasattr(out, "shape") and len(out.shape) != 0: - return NumpyArray(out, None, self._nplike) + return NumpyArray(out, parameters=None, nplike=self._nplike) else: return out @@ -229,11 +221,7 @@ def _getitem_range(self, where): except IndexError as err: raise ak._errors.index_error(self, where, str(err)) from err - return NumpyArray( - out, - self._parameters, - self._nplike, - ) + return NumpyArray(out, parameters=self._parameters, nplike=self._nplike) def _getitem_field(self, where, only_fields=()): raise ak._errors.index_error(self, where, "not an array of records") @@ -249,11 +237,7 @@ def _carry(self, carry, allow_lazy): nextdata = self._data[carry.data] except IndexError as err: raise ak._errors.index_error(self, carry.data, str(err)) from err - return NumpyArray( - nextdata, - self._parameters, - self._nplike, - ) + return NumpyArray(nextdata, parameters=self._parameters, nplike=self._nplike) def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): if self._data.ndim == 1: @@ -287,7 +271,7 @@ def _getitem_next(self, head, tail, advanced): raise ak._errors.index_error(self, (head,) + tail, str(err)) from err if hasattr(out, "shape") and len(out.shape) != 0: - return NumpyArray(out, None, self._nplike) + return NumpyArray(out, parameters=None, nplike=self._nplike) else: return out @@ -297,7 +281,7 @@ def _getitem_next(self, head, tail, advanced): out = self._data[where] except IndexError as err: raise ak._errors.index_error(self, (head,) + tail, str(err)) from err - out2 = NumpyArray(out, self._parameters, self._nplike) + out2 = NumpyArray(out, parameters=self._parameters, nplike=self._nplike) return out2 elif isinstance(head, str): @@ -320,7 +304,7 @@ def _getitem_next(self, head, tail, advanced): except IndexError as err: raise ak._errors.index_error(self, (head,) + tail, str(err)) from err - return NumpyArray(out, self._parameters, self._nplike) + return NumpyArray(out, parameters=self._parameters, nplike=self._nplike) elif isinstance(head, ak.contents.ListOffsetArray): where = (slice(None), head) + tail @@ -328,7 +312,7 @@ def _getitem_next(self, head, tail, advanced): out = self._data[where] except IndexError as err: raise ak._errors.index_error(self, (head,) + tail, str(err)) from err - out2 = NumpyArray(out, self._parameters, self._nplike) + out2 = NumpyArray(out, parameters=self._parameters, nplike=self._nplike) return out2 elif isinstance(head, ak.contents.IndexedOptionArray): @@ -369,7 +353,7 @@ def num(self, axis, depth=0): ) ) return ak.contents.NumpyArray( - tonum.data.reshape(shape), self.parameters, self._nplike + tonum.data.reshape(shape), parameters=self.parameters, nplike=self._nplike ) def _offsets_and_flattened(self, axis, depth): @@ -472,7 +456,7 @@ def mergemany(self, others): contiguous_arrays = self._nplike.concatenate(contiguous_arrays) - next = NumpyArray(contiguous_arrays, parameters, self._nplike) + next = NumpyArray(contiguous_arrays, parameters=parameters, nplike=self._nplike) if len(tail) == 0: return next @@ -503,8 +487,8 @@ def contiguous(self): else: return ak.contents.NumpyArray( self._nplike.ascontiguousarray(self._data), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) @property @@ -622,7 +606,7 @@ def _as_unique_strings(self, offsets): outlength.data, ) ) - out2 = NumpyArray(out, self._parameters, self._nplike) + out2 = NumpyArray(out, parameters=self._parameters, nplike=self._nplike) return out2, nextoffsets[: outlength[0]] @@ -638,8 +622,8 @@ def numbers_to_type(self, name): dtype = primitive_to_dtype(name) return NumpyArray( self._nplike.asarray(self._data, dtype=dtype), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -718,8 +702,8 @@ def _unique(self, negaxis, starts, parents, outlength): return ak.contents.NumpyArray( self._nplike.asarray(out[: nextlength[0]], self.dtype), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) # axis is not None @@ -947,7 +931,7 @@ def _argsort_next( starts.length, ) ) - out = NumpyArray(nextcarry, None, self._nplike) + out = NumpyArray(nextcarry, parameters=None, nplike=self._nplike) return out def _sort_next( @@ -1030,7 +1014,9 @@ def _sort_next( ) ) return ak.contents.NumpyArray( - self._nplike.asarray(out, self.dtype), None, self._nplike + self._nplike.asarray(out, self.dtype), + parameters=None, + nplike=self._nplike, ) def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): @@ -1255,7 +1241,7 @@ def continuation(): if options["keep_parameters"]: return self else: - return NumpyArray(self._data, None, self._nplike) + return NumpyArray(self._data, parameters=None, nplike=self._nplike) else: diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 0a93f18c50..36fc6d71d2 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -450,7 +450,9 @@ def num(self, axis, depth=0): if posaxis == depth: npsingle = self._nplike.index_nplike.full((1,), self.length, np.int64) single = ak.index.Index64(npsingle, nplike=self._nplike) - singleton = ak.contents.NumpyArray(single, None, self._nplike) + singleton = ak.contents.NumpyArray( + single, parameters=None, nplike=self._nplike + ) contents = [singleton] * len(self._contents) record = ak.contents.RecordArray( contents, self._fields, 1, self._parameters, self._nplike @@ -736,7 +738,9 @@ def _sort_next( ): if self._fields is None or len(self._fields) == 0: return ak.contents.NumpyArray( - self._nplike.instance().empty(0, np.int64), None, self._nplike + self._nplike.instance().empty(0, np.int64), + parameters=None, + nplike=self._nplike, ) contents = [] diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index 09b435de5d..f3dc8c1402 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -176,8 +176,10 @@ def maybe_to_NumpyArray(self): shape = (self._length, self._size) + content.data.shape[1:] return ak.contents.NumpyArray( content.data.reshape(shape), - ak._util.merge_parameters(self._parameters, content.parameters, True), - self._nplike, + parameters=ak._util.merge_parameters( + self._parameters, content.parameters, True + ), + nplike=self._nplike, ) def _getitem_nothing(self): @@ -626,7 +628,7 @@ def num(self, axis, depth=0): tonum.data, self._size, self._length ) ) - return ak.contents.NumpyArray(tonum, None, self._nplike) + return ak.contents.NumpyArray(tonum, parameters=None, nplike=self._nplike) else: next = self._content.num(posaxis, depth + 1) return ak.contents.RegularArray( diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index a206634a24..48d3c37ad3 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -1064,7 +1064,7 @@ def _argsort_next( simplified = self.simplify_uniontype(mergebool=True) if simplified.length == 0: return ak.contents.NumpyArray( - self._nplike.empty(0, np.int64), None, self._nplike + self._nplike.empty(0, np.int64), parameters=None, nplike=self._nplike ) if isinstance(simplified, ak.contents.UnionArray): diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 557abe263a..f8c873ff7c 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -145,7 +145,7 @@ def reconstitute(form, length, container, getkey, nplike): data = data.reshape((length,) + form.inner_shape) else: data = data.reshape((-1,) + form.inner_shape) - return ak.contents.NumpyArray(data, form.parameters, nplike) + return ak.contents.NumpyArray(data, parameters=form.parameters, nplike=nplike) elif isinstance(form, ak.forms.UnmaskedForm): content = reconstitute(form.content, length, container, getkey, nplike) diff --git a/src/awkward/operations/ak_full_like.py b/src/awkward/operations/ak_full_like.py index 9484796e04..ac2d22a5e0 100644 --- a/src/awkward/operations/ak_full_like.py +++ b/src/awkward/operations/ak_full_like.py @@ -174,18 +174,15 @@ def action(layout, **kwargs): if fill_value == 0 or fill_value is _ZEROS: return ak.contents.NumpyArray( - nplike.zeros_like(original), - layout.parameters, + nplike.zeros_like(original), parameters=layout.parameters ) elif fill_value == 1: return ak.contents.NumpyArray( - nplike.ones_like(original), - layout.parameters, + nplike.ones_like(original), parameters=layout.parameters ) else: return ak.contents.NumpyArray( - nplike.full_like(original, fill_value), - layout.parameters, + nplike.full_like(original, fill_value), parameters=layout.parameters ) else: return None From ff6f712098048c3cbbfa08df6c7db018b7766809 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 10:50:04 +0000 Subject: [PATCH 09/15] refactor(recordarray): make parameters, nplike, keyword arguments --- src/awkward/contents/content.py | 6 +- src/awkward/contents/listoffsetarray.py | 2 +- src/awkward/contents/recordarray.py | 107 ++++++++++++---------- src/awkward/contents/regulararray.py | 6 +- src/awkward/operations/ak_from_buffers.py | 2 +- src/awkward/operations/ak_with_name.py | 5 +- 6 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index afe07537f8..1a05df844a 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -512,8 +512,8 @@ def _getitem_next_missing( contents, nextcontent._fields, None, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -1218,7 +1218,7 @@ def _combinations_axis0( length = contents[-1].length assert length is not None return ak.contents.RecordArray( - contents, recordlookup, length, parameters, self._nplike + contents, recordlookup, length, parameters=parameters, nplike=self._nplike ) def combinations( diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 6412f829c0..15bef43997 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -1398,7 +1398,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): contents.append(self._content._carry(ptr, True)) recordarray = ak.contents.RecordArray( - contents, recordlookup, None, parameters, self._nplike + contents, recordlookup, None, parameters=parameters, nplike=self._nplike ) return ak.contents.ListOffsetArray( offsets, recordarray, parameters=self._parameters, nplike=self._nplike diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 36fc6d71d2..1d9cf232b4 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -28,8 +28,8 @@ def copy( 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._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): @@ -47,6 +47,7 @@ def __init__( contents, fields, length=None, + *, parameters=None, nplike=None, ): @@ -171,11 +172,7 @@ def is_tuple(self): @property def as_tuple(self): return RecordArray( - self._contents, - None, - self._length, - None, - self._nplike, + self._contents, None, self._length, parameters=None, nplike=self._nplike ) Form = RecordForm @@ -205,8 +202,8 @@ def typetracer(self): [x.typetracer for x in self._contents], self._fields, self._length, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -218,8 +215,8 @@ def _forget_length(self): [x._forget_length() for x in self._contents], self._fields, ak._typetracer.UnknownLength, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -258,8 +255,8 @@ def merge_parameters(self, parameters): self._contents, self._fields, self._length, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def index_to_field(self, index): @@ -304,8 +301,8 @@ def _getitem_range(self, where): [], self._fields, stop - start, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: nextslice = slice(start, stop) @@ -313,8 +310,8 @@ def _getitem_range(self, where): [x._getitem_range(nextslice) for x in self._contents], self._fields, stop - start, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): @@ -349,11 +346,7 @@ def _getitem_fields(self, where, only_fields=()): ] return RecordArray( - contents, - fields, - self._length, - None, - self._nplike, + contents, fields, self._length, parameters=None, nplike=self._nplike ) def _carry(self, carry, allow_lazy): @@ -394,8 +387,8 @@ def _carry(self, carry, allow_lazy): contents, self._fields, length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): @@ -406,7 +399,9 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): slicestarts, slicestops, slicecontent, tail ) ) - return RecordArray(contents, self._fields, self._length, None, self._nplike) + return RecordArray( + contents, self._fields, self._length, parameters=None, nplike=self._nplike + ) def _getitem_next(self, head, tail, advanced): if head == (): @@ -442,7 +437,9 @@ def _getitem_next(self, head, tail, advanced): or advanced is None ): parameters = self._parameters - next = RecordArray(contents, self._fields, None, parameters, self._nplike) + next = RecordArray( + contents, self._fields, None, parameters=parameters, nplike=self._nplike + ) return next._getitem_next(nexthead, nexttail, advanced) def num(self, axis, depth=0): @@ -455,7 +452,11 @@ def num(self, axis, depth=0): ) contents = [singleton] * len(self._contents) record = ak.contents.RecordArray( - contents, self._fields, 1, self._parameters, self._nplike + contents, + self._fields, + 1, + parameters=self._parameters, + nplike=self._nplike, ) return record[0] else: @@ -466,8 +467,8 @@ def num(self, axis, depth=0): contents, self._fields, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _offsets_and_flattened(self, axis, depth): @@ -501,8 +502,8 @@ def _offsets_and_flattened(self, axis, depth): contents, self._fields, self._length, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ), ) @@ -652,7 +653,11 @@ def mergemany(self, others): minlength += x.length next = RecordArray( - nextcontents, self._fields, minlength, parameters, self._nplike + nextcontents, + self._fields, + minlength, + parameters=parameters, + nplike=self._nplike, ) if len(tail) == 0: @@ -678,8 +683,8 @@ def fill_none(self, value): contents, self._fields, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _local_index(self, axis, depth): @@ -694,8 +699,8 @@ def _local_index(self, axis, depth): contents, self._fields, self.length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def numbers_to_type(self, name): @@ -706,8 +711,8 @@ def numbers_to_type(self, name): contents, self._fields, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -758,7 +763,11 @@ def _sort_next( ) ) return RecordArray( - contents, self._fields, self._length, self._parameters, self._nplike + contents, + self._fields, + self._length, + parameters=self._parameters, + nplike=self._nplike, ) def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): @@ -777,8 +786,8 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): contents, recordlookup, self.length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _reduce_next( @@ -838,16 +847,16 @@ def _pad_none(self, target, axis, depth, clip): contents, self._fields, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return ak.contents.RecordArray( contents, self._fields, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): @@ -957,8 +966,8 @@ def continuation(): ], self._fields, self._length, - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -1000,8 +1009,8 @@ def packed(self): ], self._fields, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_list(self, behavior, json_conversions): diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index f3dc8c1402..a9fc2081cc 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -917,7 +917,11 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): length = contents[-1].length assert length is not None recordarray = ak.contents.RecordArray( - contents, recordlookup, length, parameters, self._nplike + contents, + recordlookup, + length, + parameters=parameters, + nplike=self._nplike, ) return ak.contents.RegularArray( recordarray, diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index f8c873ff7c..7d79a51485 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -251,7 +251,7 @@ def reconstitute(form, length, container, getkey, nplike): ], None if form.is_tuple else form.fields, length, - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.UnionForm): diff --git a/src/awkward/operations/ak_with_name.py b/src/awkward/operations/ak_with_name.py index 7a35d9e68f..eceb70f622 100644 --- a/src/awkward/operations/ak_with_name.py +++ b/src/awkward/operations/ak_with_name.py @@ -44,10 +44,7 @@ def action(layout, **ignore): parameters = dict(layout.parameters) parameters["__record__"] = name return ak.contents.RecordArray( - layout.contents, - layout.fields, - len(layout), - parameters, + layout.contents, layout.fields, len(layout), parameters=parameters ) else: return None From f15dfc70b2d1b2f2a0f11d7f6011b60591c2863d Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 11:03:42 +0000 Subject: [PATCH 10/15] refactor(regulararray): make parameters, nplike, keyword arguments --- src/awkward/_broadcasting.py | 6 +- src/awkward/_slicing.py | 2 +- src/awkward/contents/content.py | 20 ++-- src/awkward/contents/listarray.py | 2 +- src/awkward/contents/listoffsetarray.py | 14 +-- src/awkward/contents/numpyarray.py | 8 +- src/awkward/contents/regulararray.py | 115 +++++++++++----------- src/awkward/contents/unmaskedarray.py | 10 +- src/awkward/operations/ak_from_buffers.py | 2 +- 9 files changed, 86 insertions(+), 93 deletions(-) diff --git a/src/awkward/_broadcasting.py b/src/awkward/_broadcasting.py index c98616bf2c..978dde814c 100644 --- a/src/awkward/_broadcasting.py +++ b/src/awkward/_broadcasting.py @@ -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) diff --git a/src/awkward/_slicing.py b/src/awkward/_slicing.py index 85b97eb34f..f2ca70fe88 100644 --- a/src/awkward/_slicing.py +++ b/src/awkward/_slicing.py @@ -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 diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index 1a05df844a..95636459ff 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -331,10 +331,10 @@ def _getitem_next_newaxis(self, tail, advanced: ak.index.Index | None): nexthead, nexttail = ak._slicing.headtail(tail) return ak.contents.RegularArray( self._getitem_next(nexthead, nexttail, advanced), - 1, # size - 0, # zeros_length is irrelevant when the size is 1 (!= 0) - None, - self._nplike, + 1, + 0, + parameters=None, + nplike=self._nplike, ) def _getitem_next_ellipsis(self, tail, advanced: ak.index.Index | None): @@ -390,8 +390,8 @@ def _getitem_next_regular_missing( out.simplify_optiontype(), indexlength, 1, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_next_missing_jagged( @@ -449,8 +449,8 @@ def _getitem_next_missing_jagged( out.simplify_optiontype(), index.length, 1, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_next_missing( @@ -558,8 +558,8 @@ def _getitem(self, where): self, self.length if self._nplike.known_shape else 1, 1, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) out = next._getitem_next(nextwhere[0], nextwhere[1:], None) diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index c6ea4ddbdb..01858672a5 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -882,7 +882,7 @@ def _getitem_next(self, head, tail, advanced): ) return ak.contents.RegularArray( - down, headlength, 1, self._parameters, self._nplike + down, headlength, 1, parameters=self._parameters, nplike=self._nplike ) elif isinstance(head, ak.contents.IndexedOptionArray): diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 15bef43997..e4065aa469 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -200,8 +200,8 @@ def to_RegularArray(self): content, size[0], self._offsets.length - 1, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_nothing(self): @@ -1534,11 +1534,7 @@ def _reduce_next( if keepdims: out = ak.contents.RegularArray( - out, - 1, - self.length, - None, - self._nplike, + out, 1, self.length, parameters=None, nplike=self._nplike ) return out @@ -1827,8 +1823,8 @@ def _pad_none(self, target, axis, depth, clip): next.simplify_optiontype(), target, self.length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return ak.contents.ListOffsetArray( diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index a60441f648..0b6be68809 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -175,7 +175,7 @@ def to_RegularArray(self): out = NumpyArray(self._data.reshape(-1), parameters=None, nplike=self._nplike) for i in range(len(shape) - 1, 0, -1): out = ak.contents.RegularArray( - out, shape[i], zeroslen[i], None, self._nplike + out, shape[i], zeroslen[i], parameters=None, nplike=self._nplike ) out._parameters = self._parameters return out @@ -1144,11 +1144,7 @@ def _reduce_next( if keepdims: out = ak.contents.RegularArray( - out, - 1, - self.length, - None, - self._nplike, + out, 1, self.length, parameters=None, nplike=self._nplike ) return out diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index a9fc2081cc..b054207bf7 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -26,8 +26,8 @@ def copy( self._content if content is unset else content, self._size if size is unset else size, self._length if zeros_length is unset else zeros_length, - 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): @@ -44,6 +44,7 @@ def __init__( content, size, zeros_length=0, + *, parameters=None, nplike=None, ): @@ -116,8 +117,8 @@ def typetracer(self): self._content.typetracer, self._size, self._length, - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -129,8 +130,8 @@ def _forget_length(self): self._content._forget_length(), self._size, ak._typetracer.UnknownLength, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -154,8 +155,8 @@ def merge_parameters(self, parameters): self._content, self._size, self._length, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_ListOffsetArray64(self, start_at_zero=False): @@ -206,8 +207,8 @@ def _getitem_range(self, where): self._content._getitem_range(slice(substart, substop)), self._size, zeros_length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): @@ -215,8 +216,8 @@ def _getitem_field(self, where, only_fields=()): self._content._getitem_field(where, only_fields), self._size, self._length, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _getitem_fields(self, where, only_fields=()): @@ -224,8 +225,8 @@ def _getitem_fields(self, where, only_fields=()): self._content._getitem_fields(where, only_fields), self._size, self._length, - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _carry(self, carry, allow_lazy): @@ -269,8 +270,8 @@ def _carry(self, carry, allow_lazy): self._content._carry(nextcarry, allow_lazy), self._size, where.shape[0], - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _compact_offsets64(self, start_at_zero): @@ -412,8 +413,8 @@ def _getitem_next(self, head, tail, advanced): nextcontent._getitem_next(nexthead, nexttail, advanced), nextsize, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: nextadvanced = ak.index.Index64.empty( @@ -441,8 +442,8 @@ def _getitem_next(self, head, tail, advanced): nextcontent._getitem_next(nexthead, nexttail, nextadvanced), nextsize, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) elif isinstance(head, str): @@ -603,7 +604,11 @@ def _getitem_next(self, head, tail, advanced): ) return RegularArray( - down, headlength, self._length, self._parameters, self._nplike + down, + headlength, + self._length, + parameters=self._parameters, + nplike=self._nplike, ) elif isinstance(head, ak.contents.IndexedOptionArray): @@ -632,7 +637,11 @@ def num(self, axis, depth=0): else: next = self._content.num(posaxis, depth + 1) return ak.contents.RegularArray( - next, self._size, self._length, self._parameters, self._nplike + next, + self._size, + self._length, + parameters=self._parameters, + nplike=self._nplike, ) def _offsets_and_flattened(self, axis, depth): @@ -695,7 +704,7 @@ def mergemany(self, others): self._content[: self._length * self._size].mergemany(tail_contents), self._size, zeros_length, - parameters, + parameters=parameters, ) else: @@ -706,8 +715,8 @@ def fill_none(self, value): self._content.fill_none(value), self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _local_index(self, axis, depth): @@ -727,16 +736,16 @@ def _local_index(self, axis, depth): ak.contents.NumpyArray(localindex), self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: return ak.contents.RegularArray( self._content._local_index(posaxis, depth + 1), self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def numbers_to_type(self, name): @@ -744,8 +753,8 @@ def numbers_to_type(self, name): self._content.numbers_to_type(name), self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -775,8 +784,8 @@ def _unique(self, negaxis, starts, parents, outlength): out._content.to_RegularArray(), out._size, out._length, - out._parameters, - self._nplike, + parameters=out._parameters, + nplike=self._nplike, ) return out @@ -812,8 +821,8 @@ def _argsort_next( out._content.to_RegularArray(), out._size, out._length, - out._parameters, - self._nplike, + parameters=out._parameters, + nplike=self._nplike, ) return out @@ -927,8 +936,8 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): recordarray, combinationslen, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: next = self._content._getitem_range( @@ -940,8 +949,8 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): next, self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _reduce_next( @@ -1016,20 +1025,12 @@ def _reduce_next( ) out = ak.contents.RegularArray( - outcontent, - self._size, - outlength, - None, - self._nplike, + outcontent, self._size, outlength, parameters=None, nplike=self._nplike ) if keepdims: out = ak.contents.RegularArray( - out, - 1, - self.length, - None, - self._nplike, + out, 1, self.length, parameters=None, nplike=self._nplike ) return out else: @@ -1186,8 +1187,8 @@ def _pad_none(self, target, axis, depth, clip): next.simplify_optiontype(), target, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: @@ -1195,8 +1196,8 @@ def _pad_none(self, target, axis, depth, clip): self._content._pad_none(target, posaxis, depth + 1, clip), self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_numpy(self, allow_missing): @@ -1295,8 +1296,8 @@ def continuation(): ), self._size, self._length, - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -1340,8 +1341,8 @@ def packed(self): content, self._size, self._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_list(self, behavior, json_conversions): diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index 66ab68ea4b..e9c87c1461 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -393,11 +393,7 @@ def _argsort_next( ).simplify_optiontype() return ak.contents.RegularArray( - tmp, - out._size, - out._length, - None, - self._nplike, + tmp, out._size, out._length, parameters=None, nplike=self._nplike ) else: @@ -428,8 +424,8 @@ def _sort_next( tmp, out._size, out._length, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) else: diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 7d79a51485..3ea23a8956 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -240,7 +240,7 @@ def reconstitute(form, length, container, getkey, nplike): reconstitute(form.content, next_length, container, getkey, nplike), form.size, length, - form.parameters, + parameters=form.parameters, ) elif isinstance(form, ak.forms.RecordForm): From bac2a2985bf3350ce02f10a13004943ecc6b269a Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 11:07:30 +0000 Subject: [PATCH 11/15] refactor(unionarray): make parameters, nplike, keyword arguments --- src/awkward/_util.py | 4 +- src/awkward/contents/content.py | 4 +- src/awkward/contents/unionarray.py | 96 +++++++++++++---------- src/awkward/operations/ak_from_buffers.py | 2 +- 4 files changed, 62 insertions(+), 44 deletions(-) diff --git a/src/awkward/_util.py b/src/awkward/_util.py index 166166443d..2acfaedb6d 100644 --- a/src/awkward/_util.py +++ b/src/awkward/_util.py @@ -480,7 +480,7 @@ def union_to_record(unionarray, anonymous): unionarray.tags, unionarray.index, contents, - unionarray.parameters, + parameters=unionarray.parameters, ) else: @@ -524,7 +524,7 @@ def union_to_record(unionarray, anonymous): unionarray.tags, unionarray.index, union_contents, - unionarray.parameters, + parameters=unionarray.parameters, ).simplify_uniontype() ) diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index 95636459ff..598e6437ca 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -789,7 +789,9 @@ def merge_as_union(self, other: Content) -> ak.contents.UnionArray: ) ) - return ak.contents.UnionArray(tags, index, contents, None, self._nplike) + return ak.contents.UnionArray( + tags, index, contents, parameters=None, nplike=self._nplike + ) def _merging_strategy( self, others: list[Content] diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index 48d3c37ad3..3e9562bb17 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -30,8 +30,8 @@ def copy( self._tags if tags is unset else tags, self._index if index is unset else index, self._contents if contents is unset else contents, - 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): @@ -45,7 +45,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, tags, index, contents, parameters=None, nplike=None): + def __init__(self, tags, index, contents, *, parameters=None, nplike=None): if not (isinstance(tags, Index) and tags.dtype == np.dtype(np.int8)): raise ak._errors.wrap_error( TypeError( @@ -165,8 +165,8 @@ def typetracer(self): ak.index.Index(self._tags.raw(tt)), ak.index.Index(self._index.raw(tt)), [x.typetracer for x in self._contents], - self._parameters, - tt, + parameters=self._parameters, + nplike=tt, ) @property @@ -178,8 +178,8 @@ def _forget_length(self): self._tags.forget_length(), self._index, self._contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -208,8 +208,8 @@ def merge_parameters(self, parameters): self._tags, self._index, self._contents, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def _getitem_nothing(self): @@ -236,8 +236,8 @@ def _getitem_range(self, where): self._tags[start:stop], self._index[start:stop], self._contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): @@ -245,8 +245,8 @@ def _getitem_field(self, where, only_fields=()): self._tags, self._index, [x._getitem_field(where, only_fields) for x in self._contents], - None, - self._nplike, + parameters=None, + nplike=self._nplike, ).simplify_uniontype() def _getitem_fields(self, where, only_fields=()): @@ -254,8 +254,8 @@ def _getitem_fields(self, where, only_fields=()): self._tags, self._index, [x._getitem_fields(where, only_fields) for x in self._contents], - None, - self._nplike, + parameters=None, + nplike=self._nplike, ).simplify_uniontype() def _carry(self, carry, allow_lazy): @@ -271,8 +271,8 @@ def _carry(self, carry, allow_lazy): nexttags, nextindex, self._contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def project(self, index): @@ -439,8 +439,8 @@ def _getitem_next(self, head, tail, advanced): self._tags, outindex, outcontents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out.simplify_uniontype() @@ -650,7 +650,9 @@ def simplify_uniontype(self, merge=True, mergebool=False): return contents[0]._carry(index, True) else: - return UnionArray(tags, index, contents, self._parameters, self._nplike) + return UnionArray( + tags, index, contents, parameters=self._parameters, nplike=self._nplike + ) def num(self, axis, depth=0): posaxis = self.axis_wrap_if_negative(axis) @@ -665,7 +667,11 @@ def num(self, axis, depth=0): for content in self._contents: contents.append(content.num(posaxis, depth)) out = UnionArray( - self._tags, self._index, contents, self._parameters, self._nplike + self._tags, + self._index, + contents, + parameters=self._parameters, + nplike=self._nplike, ) return out.simplify_uniontype(True, False) @@ -751,7 +757,11 @@ def _offsets_and_flattened(self, axis, depth): return ( tooffsets, UnionArray( - totags, toindex, contents, self._parameters, self._nplike + totags, + toindex, + contents, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -763,8 +773,8 @@ def _offsets_and_flattened(self, axis, depth): self._tags, self._index, contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ), ) @@ -861,7 +871,9 @@ def _reverse_merge(self, other): ) parameters = ak._util.merge_parameters(self._parameters, other._parameters) - return ak.contents.UnionArray(tags, index, contents, parameters, self._nplike) + return ak.contents.UnionArray( + tags, index, contents, parameters=parameters, nplike=self._nplike + ) def mergemany(self, others): if len(others) == 0: @@ -956,7 +968,11 @@ def mergemany(self, others): ) next = ak.contents.UnionArray( - nexttags, nextindex, nextcontents, parameters, self._nplike + nexttags, + nextindex, + nextcontents, + parameters=parameters, + nplike=self._nplike, ) # Given UnionArray's merging_strategy, tail is always empty, but just to be formal... @@ -978,8 +994,8 @@ def fill_none(self, value): self._tags, self._index, contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out.simplify_uniontype(True, False) @@ -995,8 +1011,8 @@ def _local_index(self, axis, depth): self._tags, self._index, contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): @@ -1015,8 +1031,8 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): self._tags, self._index, contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def numbers_to_type(self, name): @@ -1027,8 +1043,8 @@ def numbers_to_type(self, name): self._tags, self._index, contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -1193,8 +1209,8 @@ def _pad_none(self, target, axis, depth, clip): self.tags, self.index, contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) return out.simplify_uniontype(True, False) @@ -1330,8 +1346,8 @@ def continuation(): ) for content in self._contents ], - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -1389,8 +1405,8 @@ def packed(self): ak.index.Index8(tags, nplike=self.nplike), ak.index.Index(index, nplike=self.nplike), contents, - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_list(self, behavior, json_conversions): diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 3ea23a8956..3aee83ad10 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -277,7 +277,7 @@ def reconstitute(form, length, container, getkey, nplike): reconstitute(content, lengths[i], container, getkey, nplike) for i, content in enumerate(form.contents) ], - form.parameters, + parameters=form.parameters, ) else: From 6e62e6da7e0d3ff71f936419b7c5695c482a79ee Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 29 Nov 2022 11:10:03 +0000 Subject: [PATCH 12/15] refactor(unmaskedarray): make parameters, nplike, keyword arguments --- src/awkward/contents/unmaskedarray.py | 86 +++++++++++------------ src/awkward/operations/ak_from_buffers.py | 2 +- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index e9c87c1461..39f01990b7 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -21,8 +21,8 @@ def copy( ): return UnmaskedArray( self._content if content is unset else content, - 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): @@ -34,7 +34,7 @@ def __deepcopy__(self, memo): parameters=copy.deepcopy(self._parameters, memo), ) - def __init__(self, content, parameters=None, nplike=None): + def __init__(self, content, *, parameters=None, nplike=None): if not isinstance(content, Content): raise ak._errors.wrap_error( TypeError( @@ -71,9 +71,7 @@ def _to_buffers(self, form, getkey, container, nplike): def typetracer(self): tt = ak._typetracer.TypeTracer.instance() return UnmaskedArray( - self._content.typetracer, - self._parameters, - tt, + self._content.typetracer, parameters=self._parameters, nplike=tt ) @property @@ -83,8 +81,8 @@ def length(self): def _forget_length(self): return UnmaskedArray( self._content._forget_length(), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def __repr__(self): @@ -104,8 +102,8 @@ def _repr(self, indent, pre, post): def merge_parameters(self, parameters): return UnmaskedArray( self._content, - ak._util.merge_parameters(self._parameters, parameters), - self._nplike, + parameters=ak._util.merge_parameters(self._parameters, parameters), + nplike=self._nplike, ) def to_IndexedOptionArray64(self): @@ -171,29 +169,29 @@ def _getitem_range(self, where): assert step == 1 return UnmaskedArray( self._content._getitem_range(slice(start, stop)), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_field(self, where, only_fields=()): return UnmaskedArray( self._content._getitem_field(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _getitem_fields(self, where, only_fields=()): return UnmaskedArray( self._content._getitem_fields(where, only_fields), - None, - self._nplike, + parameters=None, + nplike=self._nplike, ) def _carry(self, carry, allow_lazy): return UnmaskedArray( self._content._carry(carry, allow_lazy), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): @@ -201,8 +199,8 @@ def _getitem_next_jagged(self, slicestarts, slicestops, slicecontent, tail): self._content._getitem_next_jagged( slicestarts, slicestops, slicecontent, tail ), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _getitem_next(self, head, tail, advanced): @@ -214,8 +212,8 @@ def _getitem_next(self, head, tail, advanced): ): return UnmaskedArray( self._content._getitem_next(head, tail, advanced), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ).simplify_optiontype() elif isinstance(head, str): @@ -273,7 +271,9 @@ def num(self, axis, depth=0): return out else: return ak.contents.UnmaskedArray( - self._content.num(posaxis, depth), self._parameters, self._nplike + self._content.num(posaxis, depth), + parameters=self._parameters, + nplike=self._nplike, ) def _offsets_and_flattened(self, axis, depth): @@ -285,7 +285,9 @@ def _offsets_and_flattened(self, axis, depth): if offsets.length == 0: return ( offsets, - UnmaskedArray(flattened, self._parameters, self._nplike), + UnmaskedArray( + flattened, parameters=self._parameters, nplike=self._nplike + ), ) else: @@ -323,8 +325,8 @@ def mergemany(self, others): return UnmaskedArray( self._content.mergemany(tail_contents), - parameters, - self._nplike, + parameters=parameters, + nplike=self._nplike, ) else: @@ -340,15 +342,15 @@ def _local_index(self, axis, depth): else: return UnmaskedArray( self._content._local_index(posaxis, depth), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def numbers_to_type(self, name): return ak.contents.UnmaskedArray( self._content.numbers_to_type(name), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _is_unique(self, negaxis, starts, parents, outlength): @@ -387,9 +389,7 @@ def _argsort_next( if isinstance(out, ak.contents.RegularArray): tmp = ak.contents.UnmaskedArray( - out._content, - None, - self._nplike, + out._content, parameters=None, nplike=self._nplike ).simplify_optiontype() return ak.contents.RegularArray( @@ -415,9 +415,7 @@ def _sort_next( if isinstance(out, ak.contents.RegularArray): tmp = ak.contents.UnmaskedArray( - out._content, - self._parameters, - self._nplike, + out._content, parameters=self._parameters, nplike=self._nplike ).simplify_optiontype() return ak.contents.RegularArray( @@ -440,8 +438,8 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth): self._content._combinations( n, replacement, recordlookup, parameters, posaxis, depth ), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _reduce_next( @@ -495,8 +493,8 @@ def _pad_none(self, target, axis, depth, clip): else: return ak.contents.UnmaskedArray( self._content._pad_none(target, posaxis, depth, clip), - self._parameters, - self._nplike, + parameters=self._parameters, + nplike=self._nplike, ) def _to_arrow(self, pyarrow, mask_node, validbytes, length, options): @@ -531,8 +529,8 @@ def continuation(): lateral_context, options, ), - self._parameters if options["keep_parameters"] else None, - self._nplike, + parameters=self._parameters if options["keep_parameters"] else None, + nplike=self._nplike, ) else: @@ -566,7 +564,9 @@ def continuation(): raise ak._errors.wrap_error(AssertionError(result)) def packed(self): - return UnmaskedArray(self._content.packed(), self._parameters, self._nplike) + return UnmaskedArray( + self._content.packed(), parameters=self._parameters, nplike=self._nplike + ) def _to_list(self, behavior, json_conversions): out = self._to_list_custom(behavior, json_conversions) diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index 3aee83ad10..5df89a85ca 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -149,7 +149,7 @@ def reconstitute(form, length, container, getkey, nplike): elif isinstance(form, ak.forms.UnmaskedForm): content = reconstitute(form.content, length, container, getkey, nplike) - return ak.contents.UnmaskedArray(content, form.parameters) + return ak.contents.UnmaskedArray(content, parameters=form.parameters) elif isinstance(form, ak.forms.BitMaskedForm): raw_array = container[getkey(form, "mask")] From cceb90da745577ad165fa6bdf5c3beca2607b56d Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 29 Nov 2022 13:11:46 -0600 Subject: [PATCH 13/15] Form's parameters and form_key are now keyword-only. --- src/awkward/_connect/pyarrow.py | 4 ++-- src/awkward/forms/bitmaskedform.py | 5 +++-- src/awkward/forms/bytemaskedform.py | 5 +++-- src/awkward/forms/emptyform.py | 4 ++-- src/awkward/forms/form.py | 6 ++++-- src/awkward/forms/indexedform.py | 5 +++-- src/awkward/forms/indexedoptionform.py | 5 +++-- src/awkward/forms/listform.py | 5 +++-- src/awkward/forms/listoffsetform.py | 6 +++--- src/awkward/forms/numpyform.py | 5 +++-- src/awkward/forms/recordform.py | 5 +++-- src/awkward/forms/regularform.py | 6 +++--- src/awkward/forms/unionform.py | 9 ++++++--- src/awkward/forms/unmaskedform.py | 5 +++-- 14 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/awkward/_connect/pyarrow.py b/src/awkward/_connect/pyarrow.py index 18b10bc2bd..1f5f04381c 100644 --- a/src/awkward/_connect/pyarrow.py +++ b/src/awkward/_connect/pyarrow.py @@ -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 diff --git a/src/awkward/forms/bitmaskedform.py b/src/awkward/forms/bitmaskedform.py index 9db4e44b97..6e41abf989 100644 --- a/src/awkward/forms/bitmaskedform.py +++ b/src/awkward/forms/bitmaskedform.py @@ -13,6 +13,7 @@ def __init__( content, valid_when, lsb_order, + *, parameters=None, form_key=None, ): @@ -180,8 +181,8 @@ def _select_columns(self, index, specifier, matches, output): self._content._select_columns(index, specifier, matches, output), self._valid_when, self._lsb_order, - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/bytemaskedform.py b/src/awkward/forms/bytemaskedform.py index 18440f63a7..89755facd2 100644 --- a/src/awkward/forms/bytemaskedform.py +++ b/src/awkward/forms/bytemaskedform.py @@ -12,6 +12,7 @@ def __init__( mask, content, valid_when, + *, parameters=None, form_key=None, ): @@ -162,8 +163,8 @@ def _select_columns(self, index, specifier, matches, output): self._mask, self._content._select_columns(index, specifier, matches, output), self._valid_when, - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/emptyform.py b/src/awkward/forms/emptyform.py index 02d1f77440..e822a0fdec 100644 --- a/src/awkward/forms/emptyform.py +++ b/src/awkward/forms/emptyform.py @@ -8,7 +8,7 @@ class EmptyForm(Form): is_numpy = True is_unknown = True - def __init__(self, parameters=None, form_key=None): + def __init__(self, *, parameters=None, form_key=None): self._init(parameters, form_key) def __repr__(self): @@ -28,7 +28,7 @@ def __eq__(self, other): return isinstance(other, EmptyForm) and self._form_key == other._form_key def to_NumpyForm(self, dtype): - return ak.forms.numpyform.from_dtype(dtype, self._parameters) + return ak.forms.numpyform.from_dtype(dtype, parameters=self._parameters) def purelist_parameter(self, key): if self._parameters is None or key not in self._parameters: diff --git a/src/awkward/forms/form.py b/src/awkward/forms/form.py index 5a5cbedd4c..602dc56511 100644 --- a/src/awkward/forms/form.py +++ b/src/awkward/forms/form.py @@ -25,10 +25,12 @@ def from_dict(input: dict) -> Form: if input["class"] == "NumpyArray": primitive = input["primitive"] inner_shape = input.get("inner_shape", []) - return ak.forms.NumpyForm(primitive, inner_shape, parameters, form_key) + return ak.forms.NumpyForm( + primitive, inner_shape, parameters=parameters, form_key=form_key + ) elif input["class"] == "EmptyArray": - return ak.forms.EmptyForm(parameters, form_key) + return ak.forms.EmptyForm(parameters=parameters, form_key=form_key) elif input["class"] == "RegularArray": return ak.forms.RegularForm( diff --git a/src/awkward/forms/indexedform.py b/src/awkward/forms/indexedform.py index 982a51b3c5..e7b9c098c3 100644 --- a/src/awkward/forms/indexedform.py +++ b/src/awkward/forms/indexedform.py @@ -11,6 +11,7 @@ def __init__( self, index, content=None, + *, parameters=None, form_key=None, ): @@ -139,8 +140,8 @@ def _select_columns(self, index, specifier, matches, output): return IndexedForm( self._index, self._content._select_columns(index, specifier, matches, output), - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/indexedoptionform.py b/src/awkward/forms/indexedoptionform.py index 815ff72f2c..a28dbccf88 100644 --- a/src/awkward/forms/indexedoptionform.py +++ b/src/awkward/forms/indexedoptionform.py @@ -12,6 +12,7 @@ def __init__( self, index, content, + *, parameters=None, form_key=None, ): @@ -149,8 +150,8 @@ def _select_columns(self, index, specifier, matches, output): return IndexedOptionForm( self._index, self._content._select_columns(index, specifier, matches, output), - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/listform.py b/src/awkward/forms/listform.py index b3ddabf890..5456677513 100644 --- a/src/awkward/forms/listform.py +++ b/src/awkward/forms/listform.py @@ -12,6 +12,7 @@ def __init__( starts, stops, content, + *, parameters=None, form_key=None, ): @@ -159,8 +160,8 @@ def _select_columns(self, index, specifier, matches, output): self._starts, self._stops, self._content._select_columns(index, specifier, matches, output), - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/listoffsetform.py b/src/awkward/forms/listoffsetform.py index ec23517a06..45a72eeb5e 100644 --- a/src/awkward/forms/listoffsetform.py +++ b/src/awkward/forms/listoffsetform.py @@ -7,7 +7,7 @@ class ListOffsetForm(Form): is_list = True - def __init__(self, offsets, content, parameters=None, form_key=None): + def __init__(self, offsets, content, *, parameters=None, form_key=None): if not isinstance(offsets, str): raise ak._errors.wrap_error( TypeError( @@ -127,8 +127,8 @@ def _select_columns(self, index, specifier, matches, output): return ListOffsetForm( self._offsets, self._content._select_columns(index, specifier, matches, output), - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/numpyform.py b/src/awkward/forms/numpyform.py index c661599f26..fe50749804 100644 --- a/src/awkward/forms/numpyform.py +++ b/src/awkward/forms/numpyform.py @@ -40,6 +40,7 @@ def __init__( self, primitive, inner_shape=(), + *, parameters=None, form_key=None, ): @@ -124,9 +125,9 @@ def __eq__(self, other): return False def to_RegularForm(self): - out = NumpyForm(self._primitive, (), None, None) + out = NumpyForm(self._primitive, (), parameters=None, form_key=None) for x in self._inner_shape[::-1]: - out = ak.forms.RegularForm(out, x, None, None) + out = ak.forms.RegularForm(out, x, parameters=None, form_key=None) out._parameters = self._parameters return out diff --git a/src/awkward/forms/recordform.py b/src/awkward/forms/recordform.py index 0519e551db..74d5349517 100644 --- a/src/awkward/forms/recordform.py +++ b/src/awkward/forms/recordform.py @@ -14,6 +14,7 @@ def __init__( self, contents, fields, + *, parameters=None, form_key=None, ): @@ -245,8 +246,8 @@ def _select_columns(self, index, specifier, matches, output): return RecordForm( contents, fields, - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/regularform.py b/src/awkward/forms/regularform.py index c83d279a85..d8c9b60f2f 100644 --- a/src/awkward/forms/regularform.py +++ b/src/awkward/forms/regularform.py @@ -8,7 +8,7 @@ class RegularForm(Form): is_list = True is_regular = True - def __init__(self, content, size, parameters=None, form_key=None): + def __init__(self, content, size, *, parameters=None, form_key=None): if not isinstance(content, Form): raise ak._errors.wrap_error( TypeError( @@ -134,8 +134,8 @@ def _select_columns(self, index, specifier, matches, output): return RegularForm( self._content._select_columns(index, specifier, matches, output), self._size, - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/unionform.py b/src/awkward/forms/unionform.py index 7d1d1f7432..94761ec451 100644 --- a/src/awkward/forms/unionform.py +++ b/src/awkward/forms/unionform.py @@ -14,6 +14,7 @@ def __init__( tags, index, contents, + *, parameters=None, form_key=None, ): @@ -203,7 +204,9 @@ def _select_columns(self, index, specifier, matches, output): contents.append(next_content) if len(contents) == 0: - return ak.forms.EmptyForm(self._parameters, self._form_key) + return ak.forms.EmptyForm( + parameters=self._parameters, form_key=self._form_key + ) elif len(contents) == 1: return contents[0] else: @@ -211,8 +214,8 @@ def _select_columns(self, index, specifier, matches, output): self._tags, self._index, contents, - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): diff --git a/src/awkward/forms/unmaskedform.py b/src/awkward/forms/unmaskedform.py index cea910b50c..1644ccf75d 100644 --- a/src/awkward/forms/unmaskedform.py +++ b/src/awkward/forms/unmaskedform.py @@ -10,6 +10,7 @@ class UnmaskedForm(Form): def __init__( self, content, + *, parameters=None, form_key=None, ): @@ -120,8 +121,8 @@ def _columns(self, path, output, list_indicator): def _select_columns(self, index, specifier, matches, output): return UnmaskedForm( self._content._select_columns(index, specifier, matches, output), - self._parameters, - self._form_key, + parameters=self._parameters, + form_key=self._form_key, ) def _column_types(self): From b58475cc8ba14ac571ebe4998bb0af18cb691410 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 29 Nov 2022 13:29:15 -0600 Subject: [PATCH 14/15] Type's parameters and typestr are now keyword-only. --- src/awkward/forms/bitmaskedform.py | 2 +- src/awkward/forms/bytemaskedform.py | 2 +- src/awkward/forms/emptyform.py | 2 +- src/awkward/forms/indexedoptionform.py | 2 +- src/awkward/forms/listform.py | 2 +- src/awkward/forms/listoffsetform.py | 2 +- src/awkward/forms/numpyform.py | 2 +- src/awkward/forms/recordform.py | 2 +- src/awkward/forms/regularform.py | 2 +- src/awkward/forms/unionform.py | 2 +- src/awkward/forms/unmaskedform.py | 2 +- src/awkward/types/listtype.py | 2 +- src/awkward/types/numpytype.py | 2 +- src/awkward/types/optiontype.py | 12 +- src/awkward/types/recordtype.py | 2 +- src/awkward/types/regulartype.py | 2 +- src/awkward/types/type.py | 30 +-- src/awkward/types/uniontype.py | 2 +- src/awkward/types/unknowntype.py | 2 +- tests/test_0773-typeparser.py | 120 ++++++---- tests/test_0914-types-and-forms.py | 297 ++++++++++++++----------- 21 files changed, 287 insertions(+), 206 deletions(-) diff --git a/src/awkward/forms/bitmaskedform.py b/src/awkward/forms/bitmaskedform.py index 6e41abf989..94fa96a4dd 100644 --- a/src/awkward/forms/bitmaskedform.py +++ b/src/awkward/forms/bitmaskedform.py @@ -100,7 +100,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.OptionType( self._content._type(typestrs), - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ).simplify_option_union() diff --git a/src/awkward/forms/bytemaskedform.py b/src/awkward/forms/bytemaskedform.py index 89755facd2..6ff8bf1536 100644 --- a/src/awkward/forms/bytemaskedform.py +++ b/src/awkward/forms/bytemaskedform.py @@ -84,7 +84,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.OptionType( self._content._type(typestrs), - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ).simplify_option_union() diff --git a/src/awkward/forms/emptyform.py b/src/awkward/forms/emptyform.py index e822a0fdec..28d36aaaec 100644 --- a/src/awkward/forms/emptyform.py +++ b/src/awkward/forms/emptyform.py @@ -20,7 +20,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.UnknownType( - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ) diff --git a/src/awkward/forms/indexedoptionform.py b/src/awkward/forms/indexedoptionform.py index a28dbccf88..8ef0f1486c 100644 --- a/src/awkward/forms/indexedoptionform.py +++ b/src/awkward/forms/indexedoptionform.py @@ -69,7 +69,7 @@ def _type(self, typestrs): return ak.types.OptionType( self._content._type(typestrs), - parameters, + parameters=parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ).simplify_option_union() diff --git a/src/awkward/forms/listform.py b/src/awkward/forms/listform.py index 5456677513..444c60833f 100644 --- a/src/awkward/forms/listform.py +++ b/src/awkward/forms/listform.py @@ -80,7 +80,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.ListType( self._content._type(typestrs), - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ) diff --git a/src/awkward/forms/listoffsetform.py b/src/awkward/forms/listoffsetform.py index 45a72eeb5e..bb6fd71af3 100644 --- a/src/awkward/forms/listoffsetform.py +++ b/src/awkward/forms/listoffsetform.py @@ -49,7 +49,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.ListType( self._content._type(typestrs), - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ) diff --git a/src/awkward/forms/numpyform.py b/src/awkward/forms/numpyform.py index fe50749804..b7436c7901 100644 --- a/src/awkward/forms/numpyform.py +++ b/src/awkward/forms/numpyform.py @@ -101,7 +101,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): out = ak.types.NumpyType( self._primitive, - None, + parameters=None, typestr=ak._util.gettypestr(self._parameters, typestrs), ) for x in self._inner_shape[::-1]: diff --git a/src/awkward/forms/recordform.py b/src/awkward/forms/recordform.py index 74d5349517..4bcac5c09b 100644 --- a/src/awkward/forms/recordform.py +++ b/src/awkward/forms/recordform.py @@ -150,7 +150,7 @@ def _type(self, typestrs): return ak.types.RecordType( [x._type(typestrs) for x in self._contents], self._fields, - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ) diff --git a/src/awkward/forms/regularform.py b/src/awkward/forms/regularform.py index d8c9b60f2f..9eaa93f00a 100644 --- a/src/awkward/forms/regularform.py +++ b/src/awkward/forms/regularform.py @@ -56,7 +56,7 @@ def _type(self, typestrs): return ak.types.RegularType( self._content._type(typestrs), self._size, - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ) diff --git a/src/awkward/forms/unionform.py b/src/awkward/forms/unionform.py index 94761ec451..68990a4a96 100644 --- a/src/awkward/forms/unionform.py +++ b/src/awkward/forms/unionform.py @@ -97,7 +97,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.UnionType( [x._type(typestrs) for x in self._contents], - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ) diff --git a/src/awkward/forms/unmaskedform.py b/src/awkward/forms/unmaskedform.py index 1644ccf75d..0d3f0daa4d 100644 --- a/src/awkward/forms/unmaskedform.py +++ b/src/awkward/forms/unmaskedform.py @@ -46,7 +46,7 @@ def _to_dict_part(self, verbose, toplevel): def _type(self, typestrs): return ak.types.OptionType( self._content._type(typestrs), - self._parameters, + parameters=self._parameters, typestr=ak._util.gettypestr(self._parameters, typestrs), ).simplify_option_union() diff --git a/src/awkward/types/listtype.py b/src/awkward/types/listtype.py index 12040b357f..2a29795b01 100644 --- a/src/awkward/types/listtype.py +++ b/src/awkward/types/listtype.py @@ -6,7 +6,7 @@ class ListType(Type): - def __init__(self, content, parameters=None, *, typestr=None): + def __init__(self, content, *, parameters=None, typestr=None): if not isinstance(content, Type): raise ak._errors.wrap_error( TypeError( diff --git a/src/awkward/types/numpytype.py b/src/awkward/types/numpytype.py index 952dd78d15..0c2355198e 100644 --- a/src/awkward/types/numpytype.py +++ b/src/awkward/types/numpytype.py @@ -93,7 +93,7 @@ def dtype_to_primitive(dtype): class NumpyType(Type): - def __init__(self, primitive, parameters=None, *, typestr=None): + def __init__(self, primitive, *, parameters=None, typestr=None): primitive = dtype_to_primitive(primitive_to_dtype(primitive)) if parameters is not None and not isinstance(parameters, dict): raise ak._errors.wrap_error( diff --git a/src/awkward/types/optiontype.py b/src/awkward/types/optiontype.py index d6b43b69aa..9c0daee726 100644 --- a/src/awkward/types/optiontype.py +++ b/src/awkward/types/optiontype.py @@ -9,7 +9,7 @@ class OptionType(Type): - def __init__(self, content, parameters=None, *, typestr=None): + def __init__(self, content, *, parameters=None, typestr=None): if not isinstance(content, Type): raise ak._errors.wrap_error( TypeError( @@ -103,7 +103,7 @@ def simplify_option_union(self): contents.append( OptionType( content.content, - ak._util.merge_parameters( + parameters=ak._util.merge_parameters( self._parameters, content._parameters ), typestr=typestr, @@ -112,11 +112,15 @@ def simplify_option_union(self): else: contents.append( - OptionType(content, self._parameters, typestr=self._typestr) + OptionType( + content, parameters=self._parameters, typestr=self._typestr + ) ) return UnionType( - contents, self._content.parameters, typestr=self._content.typestr + contents, + parameters=self._content.parameters, + typestr=self._content.typestr, ) else: diff --git a/src/awkward/types/recordtype.py b/src/awkward/types/recordtype.py index 873ccdb445..8be623e102 100644 --- a/src/awkward/types/recordtype.py +++ b/src/awkward/types/recordtype.py @@ -10,7 +10,7 @@ class RecordType(Type): - def __init__(self, contents, fields, parameters=None, *, typestr=None): + def __init__(self, contents, fields, *, parameters=None, typestr=None): if not isinstance(contents, Iterable): raise ak._errors.wrap_error( TypeError( diff --git a/src/awkward/types/regulartype.py b/src/awkward/types/regulartype.py index 09bb683149..21aee32000 100644 --- a/src/awkward/types/regulartype.py +++ b/src/awkward/types/regulartype.py @@ -6,7 +6,7 @@ class RegularType(Type): - def __init__(self, content, size, parameters=None, *, typestr=None): + def __init__(self, content, size, *, parameters=None, typestr=None): if not isinstance(content, Type): raise ak._errors.wrap_error( TypeError( diff --git a/src/awkward/types/type.py b/src/awkward/types/type.py index 12c791f36c..a820f538b5 100644 --- a/src/awkward/types/type.py +++ b/src/awkward/types/type.py @@ -101,35 +101,35 @@ def listtype(self, args): def varlen_string(self, args): return ak.types.ListType( - ak.types.NumpyType("uint8", {"__array__": "char"}), - {"__array__": "string"}, + ak.types.NumpyType("uint8", parameters={"__array__": "char"}), + parameters={"__array__": "string"}, ) def varlen_bytestring(self, args): return ak.types.ListType( - ak.types.NumpyType("uint8", {"__array__": "byte"}), - {"__array__": "bytestring"}, + ak.types.NumpyType("uint8", parameters={"__array__": "byte"}), + parameters={"__array__": "bytestring"}, ) def fixedlen_string(self, args): return ak.types.RegularType( - ak.types.NumpyType("uint8", {"__array__": "char"}), + ak.types.NumpyType("uint8", parameters={"__array__": "char"}), int(args[0]), - {"__array__": "string"}, + parameters={"__array__": "string"}, ) def fixedlen_bytestring(self, args): return ak.types.RegularType( - ak.types.NumpyType("uint8", {"__array__": "byte"}), + ak.types.NumpyType("uint8", parameters={"__array__": "byte"}), int(args[0]), - {"__array__": "bytestring"}, + parameters={"__array__": "bytestring"}, ) def char(self, args): - return ak.types.NumpyType("uint8", {"__array__": "char"}) + return ak.types.NumpyType("uint8", parameters={"__array__": "char"}) def byte(self, args): - return ak.types.NumpyType("uint8", {"__array__": "byte"}) + return ak.types.NumpyType("uint8", parameters={"__array__": "byte"}) def option1(self, args): return ak.types.OptionType(args[0]) @@ -158,7 +158,7 @@ def tuple_parameters(self, args): else: parameters = {} - return ak.types.RecordType(types, None, parameters) + return ak.types.RecordType(types, None, parameters=parameters) def record(self, args): if len(args) == 0: @@ -188,13 +188,13 @@ def record_parameters(self, args): else: parameters = {} - return ak.types.RecordType(types, fields, parameters) + return ak.types.RecordType(types, fields, parameters=parameters) def named0(self, args): parameters = {"__record__": str(args[0])} if 1 < len(args): parameters.update(args[1]) - return ak.types.RecordType([], None, parameters) + return ak.types.RecordType([], None, parameters=parameters) def named(self, args): parameters = {"__record__": str(args[0])} @@ -212,7 +212,7 @@ def named(self, args): fields = None contents = arguments - return ak.types.RecordType(contents, fields, parameters) + return ak.types.RecordType(contents, fields, parameters=parameters) def named_types(self, args): if len(args) == 2 and isinstance(args[1], list): @@ -243,7 +243,7 @@ def union(self, args): arguments = args[0] parameters = None - return ak.types.UnionType(arguments, parameters) + return ak.types.UnionType(arguments, parameters=parameters) def list_parameters(self, args): # modify recently created type object diff --git a/src/awkward/types/uniontype.py b/src/awkward/types/uniontype.py index 04d9ea5480..f6be5d2b33 100644 --- a/src/awkward/types/uniontype.py +++ b/src/awkward/types/uniontype.py @@ -8,7 +8,7 @@ class UnionType(Type): - def __init__(self, contents, parameters=None, *, typestr=None): + def __init__(self, contents, *, parameters=None, typestr=None): if not isinstance(contents, Iterable): raise ak._errors.wrap_error( TypeError( diff --git a/src/awkward/types/unknowntype.py b/src/awkward/types/unknowntype.py index 0e3bda269e..8f7a5541a4 100644 --- a/src/awkward/types/unknowntype.py +++ b/src/awkward/types/unknowntype.py @@ -6,7 +6,7 @@ class UnknownType(Type): - def __init__(self, parameters=None, *, typestr=None): + def __init__(self, *, parameters=None, typestr=None): if parameters is not None and not isinstance(parameters, dict): raise ak._errors.wrap_error( TypeError( diff --git a/tests/test_0773-typeparser.py b/tests/test_0773-typeparser.py index 64e751fc41..1bacab2b41 100644 --- a/tests/test_0773-typeparser.py +++ b/tests/test_0773-typeparser.py @@ -455,27 +455,29 @@ def test_numpytype_datetime64_10s(): def test_numpytype_int32_parameter(): - t = NumpyType("int32", {"__array__": "Something"}) + t = NumpyType("int32", parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_numpytype_datetime64_parameter(): - t = NumpyType("datetime64", {"__array__": "Something"}) + t = NumpyType("datetime64", parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_numpytype_datetime64_10s_parameter(): - t = NumpyType("datetime64[10s]", {"__array__": "Something"}) + t = NumpyType("datetime64[10s]", parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_numpytype_int32_categorical(): - t = NumpyType("int32", {"__categorical__": True}) + t = NumpyType("int32", parameters={"__categorical__": True}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_numpytype_int32_parameters_categorical(): - t = NumpyType("int32", {"__array__": "Something", "__categorical__": True}) + t = NumpyType( + "int32", parameters={"__array__": "Something", "__categorical__": True} + ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -485,17 +487,17 @@ def test_unknowntype(): def test_unknowntype_parameter(): - t = UnknownType({"__array__": "Something"}) + t = UnknownType(parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_unknowntype_categorical(): - t = UnknownType({"__categorical__": True}) + t = UnknownType(parameters={"__categorical__": True}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_unknowntype_categorical_parameter(): - t = UnknownType({"__array__": "Something", "__categorical__": True}) + t = UnknownType(parameters={"__array__": "Something", "__categorical__": True}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -505,18 +507,20 @@ def test_regulartype_numpytype(): def test_regulartype_numpytype_parameter(): - t = RegularType(NumpyType("int32"), 5, {"__array__": "Something"}) + t = RegularType(NumpyType("int32"), 5, parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_regulartype_numpytype_categorical(): - t = RegularType(NumpyType("int32"), 5, {"__categorical__": True}) + t = RegularType(NumpyType("int32"), 5, parameters={"__categorical__": True}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_regulartype_numpytype_categorical_parameter(): t = RegularType( - NumpyType("int32"), 5, {"__categorical__": True, "__array__": "Something"} + NumpyType("int32"), + 5, + parameters={"__categorical__": True, "__array__": "Something"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -527,53 +531,64 @@ def test_listtype_numpytype(): def test_listtype_numpytype_parameter(): - t = ListType(NumpyType("int32"), {"__array__": "Something"}) + t = ListType(NumpyType("int32"), parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_listtype_numpytype_categorical(): - t = ListType(NumpyType("int32"), {"__categorical__": True}) + t = ListType(NumpyType("int32"), parameters={"__categorical__": True}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_listtype_numpytype_categorical_parameter(): t = ListType( - NumpyType("int32"), {"__categorical__": True, "__array__": "Something"} + NumpyType("int32"), + parameters={"__categorical__": True, "__array__": "Something"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_varlen_string(): - t = ListType(NumpyType("uint8", {"__array__": "char"}), {"__array__": "string"}) + t = ListType( + NumpyType("uint8", parameters={"__array__": "char"}), + parameters={"__array__": "string"}, + ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_varlen_bytestring(): - t = ListType(NumpyType("uint8", {"__array__": "char"}), {"__array__": "bytestring"}) + t = ListType( + NumpyType("uint8", parameters={"__array__": "char"}), + parameters={"__array__": "bytestring"}, + ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_fixedlen_string(): t = RegularType( - NumpyType("uint8", {"__array__": "char"}), 5, {"__array__": "string"} + NumpyType("uint8", parameters={"__array__": "char"}), + 5, + parameters={"__array__": "string"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_fixedlen_bytestring(): t = RegularType( - NumpyType("uint8", {"__array__": "byte"}), 5, {"__array__": "bytestring"} + NumpyType("uint8", parameters={"__array__": "byte"}), + 5, + parameters={"__array__": "bytestring"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_char(): - t = NumpyType("uint8", {"__array__": "char"}) + t = NumpyType("uint8", parameters={"__array__": "char"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_byte(): - t = NumpyType("uint8", {"__array__": "byte"}) + t = NumpyType("uint8", parameters={"__array__": "byte"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -583,33 +598,40 @@ def test_optiontype_numpytype_int32(): def test_optiontype_numpytype_int32_parameters(): - t = OptionType(NumpyType("int32"), {"__array__": "Something"}) + t = OptionType(NumpyType("int32"), parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_optiontype_numpytype_int32_categorical(): - t = OptionType(NumpyType("int32"), {"__categorical__": True}) + t = OptionType(NumpyType("int32"), parameters={"__categorical__": True}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_optiontype_numpytype_int32_categorical_parameters(): t = OptionType( - NumpyType("int32"), {"__array__": "Something", "__categorical__": True} + NumpyType("int32"), + parameters={"__array__": "Something", "__categorical__": True}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_option_varlen_string(): t = OptionType( - ListType(NumpyType("uint8", {"__array__": "char"}), {"__array__": "string"}) + ListType( + NumpyType("uint8", parameters={"__array__": "char"}), + parameters={"__array__": "string"}, + ) ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_option_varlen_string_parameters(): t = OptionType( - ListType(NumpyType("uint8", {"__array__": "char"}), {"__array__": "string"}), - {"__array__": "Something"}, + ListType( + NumpyType("uint8", parameters={"__array__": "char"}), + parameters={"__array__": "string"}, + ), + parameters={"__array__": "Something"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -645,56 +667,62 @@ def test_record_fields_int32_float64(): def test_record_empty_parameters(): - t = RecordType([], None, {"p": [123]}) + t = RecordType([], None, parameters={"p": [123]}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_record_fields_empty_parameters(): - t = RecordType([], [], {"p": [123]}) + t = RecordType([], [], parameters={"p": [123]}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_record_int32_parameters(): - t = RecordType([NumpyType("int32")], None, {"p": [123]}) + t = RecordType([NumpyType("int32")], None, parameters={"p": [123]}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_record_int32_float64_parameters(): - t = RecordType([NumpyType("int32"), NumpyType("float64")], None, {"p": [123]}) + t = RecordType( + [NumpyType("int32"), NumpyType("float64")], None, parameters={"p": [123]} + ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_record_fields_int32_parameters(): - t = RecordType([NumpyType("int32")], ["one"], {"p": [123]}) + t = RecordType([NumpyType("int32")], ["one"], parameters={"p": [123]}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_record_fields_int32_float64_parameters(): t = RecordType( - [NumpyType("int32"), NumpyType("float64")], ["one", "t w o"], {"p": [123]} + [NumpyType("int32"), NumpyType("float64")], + ["one", "t w o"], + parameters={"p": [123]}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_empty(): - t = RecordType([], None, {"__record__": "Name"}) + t = RecordType([], None, parameters={"__record__": "Name"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_int32(): - t = RecordType([NumpyType("int32")], None, {"__record__": "Name"}) + t = RecordType([NumpyType("int32")], None, parameters={"__record__": "Name"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_int32_float64(): t = RecordType( - [NumpyType("int32"), NumpyType("float64")], None, {"__record__": "Name"} + [NumpyType("int32"), NumpyType("float64")], + None, + parameters={"__record__": "Name"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_fields_int32(): - t = RecordType([NumpyType("int32")], ["one"], {"__record__": "Name"}) + t = RecordType([NumpyType("int32")], ["one"], parameters={"__record__": "Name"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -702,18 +730,20 @@ def test_named_record_fields_int32_float64(): t = RecordType( [NumpyType("int32"), NumpyType("float64")], ["one", "t w o"], - {"__record__": "Name"}, + parameters={"__record__": "Name"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_empty_parameters(): - t = RecordType([], None, {"__record__": "Name", "p": [123]}) + t = RecordType([], None, parameters={"__record__": "Name", "p": [123]}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_int32_parameters(): - t = RecordType([NumpyType("int32")], None, {"__record__": "Name", "p": [123]}) + t = RecordType( + [NumpyType("int32")], None, parameters={"__record__": "Name", "p": [123]} + ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -721,13 +751,15 @@ def test_named_record_int32_float64_parameters(): t = RecordType( [NumpyType("int32"), NumpyType("float64")], None, - {"__record__": "Name", "p": [123]}, + parameters={"__record__": "Name", "p": [123]}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_named_record_fields_int32_parameters(): - t = RecordType([NumpyType("int32")], ["one"], {"__record__": "Name", "p": [123]}) + t = RecordType( + [NumpyType("int32")], ["one"], parameters={"__record__": "Name", "p": [123]} + ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -735,7 +767,7 @@ def test_named_record_fields_int32_float64_parameters(): t = RecordType( [NumpyType("int32"), NumpyType("float64")], ["one", "t w o"], - {"__record__": "Name", "p": [123]}, + parameters={"__record__": "Name", "p": [123]}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) @@ -758,13 +790,13 @@ def test_union_float64_datetime64(): def test_union_float64_parameters(): - t = UnionType([NumpyType("float64")], {"__array__": "Something"}) + t = UnionType([NumpyType("float64")], parameters={"__array__": "Something"}) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) def test_union_float64_datetime64_parameters(): t = UnionType( [NumpyType("float64"), NumpyType("datetime64")], - {"__array__": "Something"}, + parameters={"__array__": "Something"}, ) assert str(ak.types.from_datashape(str(t), highlevel=False)) == str(t) diff --git a/tests/test_0914-types-and-forms.py b/tests/test_0914-types-and-forms.py index 60008b3f3d..74e668b858 100644 --- a/tests/test_0914-types-and-forms.py +++ b/tests/test_0914-types-and-forms.py @@ -9,26 +9,33 @@ def test_UnknownType(): assert str(ak.types.unknowntype.UnknownType()) == "unknown" assert ( - str(ak.types.unknowntype.UnknownType({"x": 123})) + str(ak.types.unknowntype.UnknownType(parameters={"x": 123})) == 'unknown[parameters={"x": 123}]' ) - assert str(ak.types.unknowntype.UnknownType(None, typestr="override")) == "override" assert ( - str(ak.types.unknowntype.UnknownType({"x": 123}, typestr="override")) + str(ak.types.unknowntype.UnknownType(parameters=None, typestr="override")) == "override" ) assert ( - str(ak.types.unknowntype.UnknownType({"__categorical__": True})) + str(ak.types.unknowntype.UnknownType(parameters={"x": 123}, typestr="override")) + == "override" + ) + assert ( + str(ak.types.unknowntype.UnknownType(parameters={"__categorical__": True})) == "categorical[type=unknown]" ) assert ( - str(ak.types.unknowntype.UnknownType({"__categorical__": True, "x": 123})) + str( + ak.types.unknowntype.UnknownType( + parameters={"__categorical__": True, "x": 123} + ) + ) == 'categorical[type=unknown[parameters={"x": 123}]]' ) assert ( str( ak.types.unknowntype.UnknownType( - {"__categorical__": True}, typestr="override" + parameters={"__categorical__": True}, typestr="override" ) ) == "categorical[type=override]" @@ -70,173 +77,195 @@ def test_NumpyType(): if hasattr(np, "complex256"): assert str(ak.types.numpytype.NumpyType("complex256")) == "complex256" assert ( - str(ak.types.numpytype.NumpyType("bool", {"x": 123})) + str(ak.types.numpytype.NumpyType("bool", parameters={"x": 123})) == 'bool[parameters={"x": 123}]' ) assert ( - str(ak.types.numpytype.NumpyType("bool", None, typestr="override")) + str(ak.types.numpytype.NumpyType("bool", parameters=None, typestr="override")) == "override" ) assert ( - str(ak.types.numpytype.NumpyType("bool", {"x": 123}, typestr="override")) + str( + ak.types.numpytype.NumpyType( + "bool", parameters={"x": 123}, typestr="override" + ) + ) == "override" ) assert ( - str(ak.types.numpytype.NumpyType("bool", {"__categorical__": True})) + str(ak.types.numpytype.NumpyType("bool", parameters={"__categorical__": True})) == "categorical[type=bool]" ) assert ( - str(ak.types.numpytype.NumpyType("bool", {"__categorical__": True, "x": 123})) + str( + ak.types.numpytype.NumpyType( + "bool", parameters={"__categorical__": True, "x": 123} + ) + ) == 'categorical[type=bool[parameters={"x": 123}]]' ) assert ( str( ak.types.numpytype.NumpyType( - "bool", {"__categorical__": True}, typestr="override" + "bool", parameters={"__categorical__": True}, typestr="override" ) ) == "categorical[type=override]" ) assert str(ak.types.numpytype.NumpyType("datetime64")) == "datetime64" assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "Y"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "Y"})) == 'datetime64[unit="Y"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "M"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "M"})) == 'datetime64[unit="M"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "W"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "W"})) == 'datetime64[unit="W"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "D"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "D"})) == 'datetime64[unit="D"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "h"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "h"})) == 'datetime64[unit="h"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "m"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "m"})) == 'datetime64[unit="m"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "s"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "s"})) == 'datetime64[unit="s"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "ms"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "ms"})) == 'datetime64[unit="ms"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "us"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "us"})) == 'datetime64[unit="us"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "ns"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "ns"})) == 'datetime64[unit="ns"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "ps"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "ps"})) == 'datetime64[unit="ps"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "fs"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "fs"})) == 'datetime64[unit="fs"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "as"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "as"})) == 'datetime64[unit="as"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "10s"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "10s"})) == 'datetime64[unit="10s"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "1s"})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"__unit__": "1s"})) == 'datetime64[unit="s"]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"__unit__": "s", "x": 123})) + str( + ak.types.numpytype.NumpyType( + "datetime64", parameters={"__unit__": "s", "x": 123} + ) + ) == 'datetime64[unit="s", parameters={"x": 123}]' ) assert ( - str(ak.types.numpytype.NumpyType("datetime64", {"x": 123})) + str(ak.types.numpytype.NumpyType("datetime64", parameters={"x": 123})) == 'datetime64[parameters={"x": 123}]' ) assert str(ak.types.numpytype.NumpyType("timedelta64")) == "timedelta64" assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "Y"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "Y"})) == 'timedelta64[unit="Y"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "M"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "M"})) == 'timedelta64[unit="M"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "W"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "W"})) == 'timedelta64[unit="W"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "D"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "D"})) == 'timedelta64[unit="D"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "h"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "h"})) == 'timedelta64[unit="h"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "m"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "m"})) == 'timedelta64[unit="m"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "s"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "s"})) == 'timedelta64[unit="s"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "ms"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "ms"})) == 'timedelta64[unit="ms"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "us"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "us"})) == 'timedelta64[unit="us"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "ns"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "ns"})) == 'timedelta64[unit="ns"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "ps"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "ps"})) == 'timedelta64[unit="ps"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "fs"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "fs"})) == 'timedelta64[unit="fs"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "as"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "as"})) == 'timedelta64[unit="as"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "10s"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "10s"})) == 'timedelta64[unit="10s"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "1s"})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"__unit__": "1s"})) == 'timedelta64[unit="s"]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"__unit__": "s", "x": 123})) + str( + ak.types.numpytype.NumpyType( + "timedelta64", parameters={"__unit__": "s", "x": 123} + ) + ) == 'timedelta64[unit="s", parameters={"x": 123}]' ) assert ( - str(ak.types.numpytype.NumpyType("timedelta64", {"x": 123})) + str(ak.types.numpytype.NumpyType("timedelta64", parameters={"x": 123})) == 'timedelta64[parameters={"x": 123}]' ) - assert str(ak.types.numpytype.NumpyType("uint8", {"__array__": "char"})) == "char" - assert str(ak.types.numpytype.NumpyType("uint8", {"__array__": "byte"})) == "byte" + assert ( + str(ak.types.numpytype.NumpyType("uint8", parameters={"__array__": "char"})) + == "char" + ) + assert ( + str(ak.types.numpytype.NumpyType("uint8", parameters={"__array__": "byte"})) + == "byte" + ) assert repr(ak.types.numpytype.NumpyType(primitive="bool")) == "NumpyType('bool')" assert ( repr( @@ -288,7 +317,7 @@ def test_RegularType(): assert ( str( ak.types.regulartype.RegularType( - ak.types.unknowntype.UnknownType(), 10, {"x": 123} + ak.types.unknowntype.UnknownType(), 10, parameters={"x": 123} ) ) == '[10 * unknown, parameters={"x": 123}]' @@ -296,7 +325,10 @@ def test_RegularType(): assert ( str( ak.types.regulartype.RegularType( - ak.types.unknowntype.UnknownType(), 10, None, typestr="override" + ak.types.unknowntype.UnknownType(), + 10, + parameters=None, + typestr="override", ) ) == "override" @@ -304,7 +336,10 @@ def test_RegularType(): assert ( str( ak.types.regulartype.RegularType( - ak.types.unknowntype.UnknownType(), 10, {"x": 123}, typestr="override" + ak.types.unknowntype.UnknownType(), + 10, + parameters={"x": 123}, + typestr="override", ) ) == "override" @@ -312,7 +347,9 @@ def test_RegularType(): assert ( str( ak.types.regulartype.RegularType( - ak.types.unknowntype.UnknownType(), 10, {"__categorical__": True} + ak.types.unknowntype.UnknownType(), + 10, + parameters={"__categorical__": True}, ) ) == "categorical[type=10 * unknown]" @@ -322,7 +359,7 @@ def test_RegularType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10, - {"__categorical__": True, "x": 123}, + parameters={"__categorical__": True, "x": 123}, ) ) == 'categorical[type=[10 * unknown, parameters={"x": 123}]]' @@ -332,7 +369,7 @@ def test_RegularType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10, - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -341,9 +378,9 @@ def test_RegularType(): assert ( str( ak.types.regulartype.RegularType( - ak.types.numpytype.NumpyType("uint8", {"__array__": "char"}), + ak.types.numpytype.NumpyType("uint8", parameters={"__array__": "char"}), 10, - {"__array__": "string"}, + parameters={"__array__": "string"}, ) ) == "string[10]" @@ -351,9 +388,9 @@ def test_RegularType(): assert ( str( ak.types.regulartype.RegularType( - ak.types.numpytype.NumpyType("uint8", {"__array__": "byte"}), + ak.types.numpytype.NumpyType("uint8", parameters={"__array__": "byte"}), 10, - {"__array__": "bytestring"}, + parameters={"__array__": "bytestring"}, ) ) == "bytes[10]" @@ -410,13 +447,17 @@ def test_ListType(): == "var * unknown" ) assert ( - str(ak.types.listtype.ListType(ak.types.unknowntype.UnknownType(), {"x": 123})) + str( + ak.types.listtype.ListType( + ak.types.unknowntype.UnknownType(), parameters={"x": 123} + ) + ) == '[var * unknown, parameters={"x": 123}]' ) assert ( str( ak.types.listtype.ListType( - ak.types.unknowntype.UnknownType(), None, typestr="override" + ak.types.unknowntype.UnknownType(), parameters=None, typestr="override" ) ) == "override" @@ -424,7 +465,9 @@ def test_ListType(): assert ( str( ak.types.listtype.ListType( - ak.types.unknowntype.UnknownType(), {"x": 123}, typestr="override" + ak.types.unknowntype.UnknownType(), + parameters={"x": 123}, + typestr="override", ) ) == "override" @@ -432,7 +475,7 @@ def test_ListType(): assert ( str( ak.types.listtype.ListType( - ak.types.unknowntype.UnknownType(), {"__categorical__": True} + ak.types.unknowntype.UnknownType(), parameters={"__categorical__": True} ) ) == "categorical[type=var * unknown]" @@ -441,7 +484,7 @@ def test_ListType(): str( ak.types.listtype.ListType( ak.types.unknowntype.UnknownType(), - {"__categorical__": True, "x": 123}, + parameters={"__categorical__": True, "x": 123}, ) ) == 'categorical[type=[var * unknown, parameters={"x": 123}]]' @@ -450,7 +493,7 @@ def test_ListType(): str( ak.types.listtype.ListType( ak.types.unknowntype.UnknownType(), - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -459,8 +502,8 @@ def test_ListType(): assert ( str( ak.types.listtype.ListType( - ak.types.numpytype.NumpyType("uint8", {"__array__": "char"}), - {"__array__": "string"}, + ak.types.numpytype.NumpyType("uint8", parameters={"__array__": "char"}), + parameters={"__array__": "string"}, ) ) == "string" @@ -468,8 +511,8 @@ def test_ListType(): assert ( str( ak.types.listtype.ListType( - ak.types.numpytype.NumpyType("uint8", {"__array__": "byte"}), - {"__array__": "bytestring"}, + ak.types.numpytype.NumpyType("uint8", parameters={"__array__": "byte"}), + parameters={"__array__": "bytestring"}, ) ) == "bytes" @@ -546,7 +589,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name"}, + parameters={"__record__": "Name"}, ) ) == "Name[unknown, bool]" @@ -559,7 +602,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name"}, + parameters={"__record__": "Name"}, ) ) == "Name[x: unknown, y: bool]" @@ -572,7 +615,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - None, + parameters=None, typestr="override", ) ) @@ -586,7 +629,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - None, + parameters=None, typestr="override", ) ) @@ -600,7 +643,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name"}, + parameters={"__record__": "Name"}, typestr="override", ) ) @@ -614,7 +657,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name"}, + parameters={"__record__": "Name"}, typestr="override", ) ) @@ -628,7 +671,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"x": 123}, + parameters={"x": 123}, ) ) == 'tuple[[unknown, bool], parameters={"x": 123}]' @@ -641,7 +684,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"x": 123}, + parameters={"x": 123}, ) ) == 'struct[{x: unknown, y: bool}, parameters={"x": 123}]' @@ -654,7 +697,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name", "x": 123}, + parameters={"__record__": "Name", "x": 123}, ) ) == 'Name[unknown, bool, parameters={"x": 123}]' @@ -667,7 +710,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name", "x": 123}, + parameters={"__record__": "Name", "x": 123}, ) ) == 'Name[x: unknown, y: bool, parameters={"x": 123}]' @@ -680,7 +723,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"x": 123}, + parameters={"x": 123}, typestr="override", ) ) @@ -694,7 +737,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"x": 123}, + parameters={"x": 123}, typestr="override", ) ) @@ -708,7 +751,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name", "x": 123}, + parameters={"__record__": "Name", "x": 123}, typestr="override", ) ) @@ -722,7 +765,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name", "x": 123}, + parameters={"__record__": "Name", "x": 123}, typestr="override", ) ) @@ -736,7 +779,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__categorical__": True}, + parameters={"__categorical__": True}, ) ) == "categorical[type=(unknown, bool)]" @@ -749,7 +792,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__categorical__": True}, + parameters={"__categorical__": True}, ) ) == "categorical[type={x: unknown, y: bool}]" @@ -762,7 +805,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name", "__categorical__": True}, + parameters={"__record__": "Name", "__categorical__": True}, ) ) == "categorical[type=Name[unknown, bool]]" @@ -775,7 +818,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name", "__categorical__": True}, + parameters={"__record__": "Name", "__categorical__": True}, ) ) == "categorical[type=Name[x: unknown, y: bool]]" @@ -788,7 +831,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -802,7 +845,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -816,7 +859,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name", "__categorical__": True}, + parameters={"__record__": "Name", "__categorical__": True}, typestr="override", ) ) @@ -830,7 +873,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name", "__categorical__": True}, + parameters={"__record__": "Name", "__categorical__": True}, typestr="override", ) ) @@ -844,7 +887,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, ) ) == 'categorical[type=tuple[[unknown, bool], parameters={"x": 123}]]' @@ -857,7 +900,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, ) ) == 'categorical[type=struct[{x: unknown, y: bool}, parameters={"x": 123}]]' @@ -870,7 +913,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name", "x": 123, "__categorical__": True}, + parameters={"__record__": "Name", "x": 123, "__categorical__": True}, ) ) == 'categorical[type=Name[unknown, bool, parameters={"x": 123}]]' @@ -883,7 +926,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name", "x": 123, "__categorical__": True}, + parameters={"__record__": "Name", "x": 123, "__categorical__": True}, ) ) == 'categorical[type=Name[x: unknown, y: bool, parameters={"x": 123}]]' @@ -896,7 +939,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, typestr="override", ) ) @@ -910,7 +953,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, typestr="override", ) ) @@ -924,7 +967,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], None, - {"__record__": "Name", "x": 123, "__categorical__": True}, + parameters={"__record__": "Name", "x": 123, "__categorical__": True}, typestr="override", ) ) @@ -938,7 +981,7 @@ def test_RecordType(): ak.types.numpytype.NumpyType("bool"), ], ["x", "y"], - {"__record__": "Name", "x": 123, "__categorical__": True}, + parameters={"__record__": "Name", "x": 123, "__categorical__": True}, typestr="override", ) ) @@ -1036,7 +1079,7 @@ def test_OptionType(): assert ( str( ak.types.optiontype.OptionType( - ak.types.unknowntype.UnknownType(), {"x": 123} + ak.types.unknowntype.UnknownType(), parameters={"x": 123} ) ) == 'option[unknown, parameters={"x": 123}]' @@ -1045,7 +1088,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - {"x": 123}, + parameters={"x": 123}, ) ) == 'option[var * unknown, parameters={"x": 123}]' @@ -1056,7 +1099,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - {"x": 123}, + parameters={"x": 123}, ) ) == 'option[10 * unknown, parameters={"x": 123}]' @@ -1064,7 +1107,7 @@ def test_OptionType(): assert ( str( ak.types.optiontype.OptionType( - ak.types.unknowntype.UnknownType(), None, typestr="override" + ak.types.unknowntype.UnknownType(), parameters=None, typestr="override" ) ) == "override" @@ -1073,7 +1116,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - None, + parameters=None, typestr="override", ) ) @@ -1085,7 +1128,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - None, + parameters=None, typestr="override", ) ) @@ -1094,7 +1137,9 @@ def test_OptionType(): assert ( str( ak.types.optiontype.OptionType( - ak.types.unknowntype.UnknownType(), {"x": 123}, typestr="override" + ak.types.unknowntype.UnknownType(), + parameters={"x": 123}, + typestr="override", ) ) == "override" @@ -1103,7 +1148,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - {"x": 123}, + parameters={"x": 123}, typestr="override", ) ) @@ -1115,7 +1160,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - {"x": 123}, + parameters={"x": 123}, typestr="override", ) ) @@ -1124,7 +1169,7 @@ def test_OptionType(): assert ( str( ak.types.optiontype.OptionType( - ak.types.unknowntype.UnknownType(), {"__categorical__": True} + ak.types.unknowntype.UnknownType(), parameters={"__categorical__": True} ) ) == "?categorical[type=unknown]" @@ -1133,7 +1178,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - {"__categorical__": True}, + parameters={"__categorical__": True}, ) ) == "option[categorical[type=var * unknown]]" @@ -1144,7 +1189,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - {"__categorical__": True}, + parameters={"__categorical__": True}, ) ) == "option[categorical[type=10 * unknown]]" @@ -1153,7 +1198,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.unknowntype.UnknownType(), - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, ) ) == 'option[categorical[type=unknown], parameters={"x": 123}]' @@ -1162,7 +1207,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, ) ) == 'option[categorical[type=var * unknown], parameters={"x": 123}]' @@ -1173,7 +1218,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, ) ) == 'option[categorical[type=10 * unknown], parameters={"x": 123}]' @@ -1182,7 +1227,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.unknowntype.UnknownType(), - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -1192,7 +1237,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -1204,7 +1249,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -1214,7 +1259,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.unknowntype.UnknownType(), - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, typestr="override", ) ) @@ -1224,7 +1269,7 @@ def test_OptionType(): str( ak.types.optiontype.OptionType( ak.types.listtype.ListType(ak.types.unknowntype.UnknownType()), - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, typestr="override", ) ) @@ -1236,7 +1281,7 @@ def test_OptionType(): ak.types.regulartype.RegularType( ak.types.unknowntype.UnknownType(), 10 ), - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, typestr="override", ) ) @@ -1288,7 +1333,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - {"x": 123}, + parameters={"x": 123}, ) ) == 'union[unknown, bool, parameters={"x": 123}]' @@ -1300,7 +1345,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - None, + parameters=None, typestr="override", ) ) @@ -1313,7 +1358,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - {"x": 123}, + parameters={"x": 123}, typestr="override", ) ) @@ -1326,7 +1371,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - {"__categorical__": True}, + parameters={"__categorical__": True}, ) ) == "categorical[type=union[unknown, bool]]" @@ -1338,7 +1383,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, ) ) == 'categorical[type=union[unknown, bool, parameters={"x": 123}]]' @@ -1350,7 +1395,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - {"__categorical__": True}, + parameters={"__categorical__": True}, typestr="override", ) ) @@ -1363,7 +1408,7 @@ def test_UnionType(): ak.types.unknowntype.UnknownType(), ak.types.numpytype.NumpyType("bool"), ], - {"x": 123, "__categorical__": True}, + parameters={"x": 123, "__categorical__": True}, typestr="override", ) ) From b3cd3996d1e65218af5c4ba93a5c2412541b5c14 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 29 Nov 2022 13:36:04 -0600 Subject: [PATCH 15/15] Also the copy method, which has the same arguments as __init__. --- src/awkward/contents/bitmaskedarray.py | 1 + src/awkward/contents/bytemaskedarray.py | 1 + src/awkward/contents/emptyarray.py | 1 + src/awkward/contents/indexedarray.py | 1 + src/awkward/contents/indexedoptionarray.py | 1 + src/awkward/contents/listarray.py | 1 + src/awkward/contents/listoffsetarray.py | 1 + src/awkward/contents/numpyarray.py | 1 + src/awkward/contents/recordarray.py | 1 + src/awkward/contents/regulararray.py | 1 + src/awkward/contents/unionarray.py | 1 + src/awkward/contents/unmaskedarray.py | 1 + 12 files changed, 12 insertions(+) diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index 0286521fab..7e5fa761b9 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -24,6 +24,7 @@ def copy( valid_when=unset, length=unset, lsb_order=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/bytemaskedarray.py b/src/awkward/contents/bytemaskedarray.py index 666dfa3716..78a192d565 100644 --- a/src/awkward/contents/bytemaskedarray.py +++ b/src/awkward/contents/bytemaskedarray.py @@ -21,6 +21,7 @@ def copy( mask=unset, content=unset, valid_when=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/emptyarray.py b/src/awkward/contents/emptyarray.py index 4daeb2c62f..948c053d3d 100644 --- a/src/awkward/contents/emptyarray.py +++ b/src/awkward/contents/emptyarray.py @@ -16,6 +16,7 @@ class EmptyArray(Content): def copy( self, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index acf9e338db..06e9ac3347 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -18,6 +18,7 @@ def copy( self, index=unset, content=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index f90457499a..c3c98e1e83 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -19,6 +19,7 @@ def copy( self, index=unset, content=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 01858672a5..e7a554b203 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -19,6 +19,7 @@ def copy( starts=unset, stops=unset, content=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index e4065aa469..600e381263 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -18,6 +18,7 @@ def copy( self, offsets=unset, content=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index 0b6be68809..3e383018fc 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -17,6 +17,7 @@ class NumpyArray(Content): def copy( self, data=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 1d9cf232b4..3fcf2d3131 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -21,6 +21,7 @@ def copy( contents=unset, fields=unset, length=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/regulararray.py b/src/awkward/contents/regulararray.py index b054207bf7..bdc7ca4542 100644 --- a/src/awkward/contents/regulararray.py +++ b/src/awkward/contents/regulararray.py @@ -19,6 +19,7 @@ def copy( content=unset, size=unset, zeros_length=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index 3e9562bb17..89c2c3656a 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -23,6 +23,7 @@ def copy( tags=unset, index=unset, contents=unset, + *, parameters=unset, nplike=unset, ): diff --git a/src/awkward/contents/unmaskedarray.py b/src/awkward/contents/unmaskedarray.py index 39f01990b7..df40acee81 100644 --- a/src/awkward/contents/unmaskedarray.py +++ b/src/awkward/contents/unmaskedarray.py @@ -16,6 +16,7 @@ class UnmaskedArray(Content): def copy( self, content=unset, + *, parameters=unset, nplike=unset, ):