ak.str.distinct_counts#
Defined in awkward.operations.str.akstr_distinct_counts on line 95.
- ak.str.distinct_counts(array, *, highlevel=True, behavior=None, attrs=None)#
- Parameters:
array – Array-like data (anything
ak.to_layoutrecognizes).highlevel (bool) – If True, return an
ak.Array; otherwise, return a low-levelak.contents.Contentsubclass.behavior (None or dict) – Custom
ak.behaviorfor the output array, if high-level.attrs (None or dict) – Custom attributes for the output array, if high-level.
Returns records containing each distinct value (
"values") and its frequency ("counts") in an array of strings or bytestrings, applying the operation independently at the final string-list axis and preserving outer nesting.If
arraycontains no string or bytestring data, this function returns it unchanged.Requires the pyarrow library and calls pyarrow.compute.value_counts.
- Traversal strategy:
ak.transformwalks the Awkward layout tree and calls_actionat each node. When_actionfinds a list whose content is a string or bytestring layout, it applies the Arrow kernel to slices defined by that list’s offsets and returns a replacement layout, which stops recursion into that subtree. Other nodes return None, allowingak.transformto continue. This follows Awkward’s public traversal API and uses_apply_through_arrowfor Arrow conversion rather than manually rebuilding the surrounding nesting withrecursively_apply.