Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: refactor '_nextcarry-outindex' to have the same signature everywhere #1911

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/awkward/contents/bytemaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def _carry(self, carry, allow_lazy):
self._nplike,
)

def _nextcarry_outindex(self, numnull):
def _nextcarry_outindex(self, nplike):
numnull = ak.index.Index64.empty(1, nplike)

assert numnull.nplike is self._nplike and self._mask.nplike is self._nplike
self._handle_error(
self._nplike[
Expand Down Expand Up @@ -347,7 +349,7 @@ def _nextcarry_outindex(self, numnull):
self._valid_when,
)
)
return nextcarry, outindex
return numnull[0], nextcarry, outindex

def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, tail):
if (
Expand All @@ -365,11 +367,10 @@ def _getitem_next_jagged_generic(self, slicestarts, slicestops, slicecontent, ta
),
)

numnull = ak.index.Index64.empty(1, self._nplike)
nextcarry, outindex = self._nextcarry_outindex(numnull)
numnull, nextcarry, outindex = self._nextcarry_outindex(self._nplike)

reducedstarts = ak.index.Index64.empty(self.length - numnull[0], self._nplike)
reducedstops = ak.index.Index64.empty(self.length - numnull[0], self._nplike)
reducedstarts = ak.index.Index64.empty(self.length - numnull, self._nplike)
reducedstops = ak.index.Index64.empty(self.length - numnull, self._nplike)

assert (
outindex.nplike is self._nplike
Expand Down Expand Up @@ -418,8 +419,7 @@ def _getitem_next(self, head, tail, advanced):
head, (int, slice, ak.index.Index64, ak.contents.ListOffsetArray)
):
nexthead, nexttail = ak._slicing.headtail(tail)
numnull = ak.index.Index64.empty(1, self._nplike)
nextcarry, outindex = self._nextcarry_outindex(numnull)
_, nextcarry, outindex = self._nextcarry_outindex(self._nplike)

next = self._content._carry(nextcarry, True)
out = next._getitem_next(head, tail, advanced)
Expand Down Expand Up @@ -550,8 +550,7 @@ def num(self, axis, depth=0):
else:
return out
else:
numnull = ak.index.Index64.empty(1, self._nplike, dtype=np.int64)
nextcarry, outindex = self._nextcarry_outindex(numnull)
_, nextcarry, outindex = self._nextcarry_outindex(self._nplike)

next = self._content._carry(nextcarry, False)
out = next.num(posaxis, depth)
Expand All @@ -566,8 +565,7 @@ def _offsets_and_flattened(self, axis, depth):
if posaxis == depth:
raise ak._errors.wrap_error(np.AxisError("axis=0 not allowed for flatten"))
else:
numnull = ak.index.Index64.empty(1, self._nplike)
nextcarry, outindex = self._nextcarry_outindex(numnull)
numnull, nextcarry, outindex = self._nextcarry_outindex(self._nplike)

next = self._content._carry(nextcarry, False)

Expand All @@ -583,7 +581,7 @@ def _offsets_and_flattened(self, axis, depth):

else:
outoffsets = ak.index.Index64.empty(
offsets.length + numnull[0], self._nplike, dtype=np.int64
offsets.length + numnull, self._nplike, dtype=np.int64
)

assert (
Expand Down Expand Up @@ -663,8 +661,7 @@ def _local_index(self, axis, depth):
if posaxis == depth:
return self._local_index_axis0()
else:
numnull = ak.index.Index64.empty(1, self._nplike)
nextcarry, outindex = self._nextcarry_outindex(numnull)
_, nextcarry, outindex = self._nextcarry_outindex(self._nplike)

next = self._content._carry(nextcarry, False)
out = next._local_index(posaxis, depth)
Expand Down Expand Up @@ -746,8 +743,7 @@ def _combinations(self, n, replacement, recordlookup, parameters, axis, depth):
if posaxis == depth:
return self._combinations_axis0(n, replacement, recordlookup, parameters)
else:
numnull = ak.index.Index64.empty(1, self._nplike, dtype=np.int64)
nextcarry, outindex = self._nextcarry_outindex(numnull)
_, nextcarry, outindex = self._nextcarry_outindex(self._nplike)

next = self._content._carry(nextcarry, True)
out = next._combinations(
Expand Down