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

Removed bytemask() in favour of mask_as_bool() #1410

Merged
merged 6 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/awkward/_v2/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ def _impl(array):
elif isinstance(array, ak._v2.contents.IndexedOptionArray):
content = _impl(array.project())

mask0 = module.asarray(array.bytemask()).view(np.bool_)
mask0 = array.mask_as_bool(valid_when=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last case illustrates why we want to avoid having both bytemask and mask_as_bool. You didn't see it, @ioanaif, because it was added by @swishdiff, and @swishdiff didn't know that bytemask was being removed.

if mask0.any():
raise ak._v2._util.error(
ValueError(f"{module.__name__} does not support masked arrays")
Expand Down
22 changes: 1 addition & 21 deletions src/awkward/_v2/contents/bytemaskedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,32 +878,12 @@ def _nbytes_part(self):
result = result + self.identifier._nbytes_part()
return result

def bytemask(self):
if not self._valid_when:
return self._mask
else:
out = ak._v2.index.Index64.empty(self.length, self._nplike)
assert out.nplike is self._nplike and self._mask.nplike is self._nplike
self._handle_error(
self._nplike[
"awkward_ByteMaskedArray_mask",
out.dtype.type,
self._mask.dtype.type,
](
out.data,
self._mask.data,
self._mask.length,
self._valid_when,
)
)
return out

def _rpad(self, target, axis, depth, clip):
posaxis = self.axis_wrap_if_negative(axis)
if posaxis == depth:
return self.rpad_axis0(target, clip)
elif posaxis == depth + 1:
mask = self.bytemask()
mask = ak._v2.index.Index8(self.mask_as_bool(valid_when=False))
index = ak._v2.index.Index64.empty(mask.length, self._nplike)
assert index.nplike is self._nplike and self._mask.nplike is self._nplike
self._handle_error(
Expand Down
16 changes: 3 additions & 13 deletions src/awkward/_v2/contents/indexedoptionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def fillna(self, value):
)

contents = [self._content, value]
tags = self.bytemask()
tags = ak._v2.index.Index8(self.mask_as_bool(valid_when=False))
index = ak._v2.index.Index64.empty(tags.length, self._nplike)

assert index.nplike is self._nplike and self._index.nplike is self._nplike
Expand Down Expand Up @@ -1463,22 +1463,12 @@ def _nbytes_part(self):
result = result + self.identifier._nbytes_part()
return result

def bytemask(self):
out = ak._v2.index.Index8.empty(self.index.length, self._nplike)
assert out.nplike is self._nplike and self._index.nplike is self._nplike
self._handle_error(
self._nplike[
"awkward_IndexedArray_mask", out.dtype.type, self._index.dtype.type
](out.data, self._index.data, self._index.length)
)
return out

def _rpad(self, target, axis, depth, clip):
posaxis = self.axis_wrap_if_negative(axis)
if posaxis == depth:
return self.rpad_axis0(target, clip)
elif posaxis == depth + 1:
mask = self.bytemask()
mask = ak._v2.index.Index8(self.mask_as_bool(valid_when=False))
index = ak._v2.index.Index64.empty(mask.length, self._nplike)
assert index.nplike is self._nplike and mask.nplike is self._nplike
self._handle_error(
Expand Down Expand Up @@ -1540,7 +1530,7 @@ def _to_numpy(self, allow_missing):
shape = list(content.shape)
shape[0] = self.length
data = numpy.empty(shape, dtype=content.dtype)
mask0 = numpy.asarray(self.bytemask()).view(np.bool_)
mask0 = numpy.asarray(self.mask_as_bool(valid_when=False)).view(np.bool_)
if mask0.any():
if allow_missing:
mask = numpy.broadcast_to(
Expand Down
6 changes: 3 additions & 3 deletions src/awkward/_v2/operations/structure/ak_flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def apply(layout):
content, ak._v2.contents.UnmaskedArray
):
bigmask[:] = False
bigmask[tags == tag] = nplike.asarray(content.bytemask()).view(
np.bool_
)
bigmask[tags == tag] = nplike.asarray(
content.mask_as_bool(valid_when=False)
).view(np.bool_)
index[bigmask] = -1

good = index >= 0
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_v2/operations/structure/ak_is_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def getfunction_inner(layout, depth, **kwargs):

# Convert the option type into a union, using the mask
# as a tag.
tag = nplike.asarray(layout.bytemask())
tag = nplike.asarray(layout.mask_as_bool(valid_when=False))
index = nplike.where(tag, 0, nplike.asarray(layout.index))

return ak._v2.contents.UnionArray(
Expand Down