-
-
Save agoose77/a1bbdf6ac20fce483c1ce6e0550e929d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import awkward as ak | |
def simplify_option(array: ak.Array, highlevel=True, behavior=None) -> ak.Array: | |
"""Return the result of removing superfluous option-types from the given array | |
:param array: `None`-containing Array | |
""" | |
# Pack array layout to ensure no nested options | |
layout = ak.packed(array, highlevel=False) | |
nplike = ak.nplike.of(layout) | |
def transform(layout, depth, user=None): | |
if isinstance(layout, ak._util.optiontypes): | |
mask = nplike.asarray(layout.bytemask()).view(np.bool_) | |
if not np.any(mask): | |
layout = layout.project() | |
# We are above the child layout with None's | |
return ak._util.transform_child_layouts(transform, layout, depth) | |
out = transform(layout, 1) | |
return ak._util.maybe_wrap_like(out, array, behavior, highlevel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment