def METHOD_NAME(array, highlevel, behavior):
    deprecate(
        "The general purpose `ak.to_categorical` has been replaced by `ak.str.to_categorical`",
        "2.5.0",
    )
    def action(layout, **kwargs):
        if layout.purelist_depth == 1:
            if layout.is_indexed and layout.is_option:
                content = layout.content
                cls = ak.contents.IndexedOptionArray
            elif layout.is_indexed:
                content = layout.content
                cls = ak.contents.IndexedArray
            elif layout.is_option:
                content = layout.content
                cls = ak.contents.IndexedOptionArray
            else:
                content = layout
                cls = ak.contents.IndexedArray
            content_list = ak.operations.to_list(content)
            hashable = [as_hashable(x) for x in content_list]
            lookup = {}
            is_first = numpy.empty(len(hashable), dtype=np.bool_)
            mapping = numpy.empty(len(hashable), dtype=np.int64)
            for i, x in enumerate(hashable):
                if x in lookup:
                    is_first[i] = False
                    mapping[i] = lookup[x]
                else:
                    is_first[i] = True
                    lookup[x] = j = len(lookup)
                    mapping[i] = j
            if layout.is_indexed and layout.is_option:
                original_index = numpy.asarray(layout.index)
                index = mapping[original_index]
                index[original_index < 0] = -1
                index = ak.index.Index64(index)
            elif layout.is_indexed:
                original_index = numpy.asarray(layout.index)
                index = ak.index.Index64(mapping[original_index])
            elif layout.is_option:
                mask = numpy.asarray(layout.mask_as_bool(valid_when=False))
                mapping[mask.view(np.bool_)] = -1
                index = ak.index.Index64(mapping)
            else:
                index = ak.index.Index64(mapping)
            out = cls(index, content[is_first], parameters={"__array__": "categorical"})
            return out
        else:
            return None
    layout = ak.operations.to_layout(array, allow_record=False, allow_other=False)
    behavior = behavior_of(array, behavior=behavior)
    out = ak._do.recursively_apply(layout, action, behavior)
    return wrap_layout(out, behavior, highlevel)