code: def _create_delegating_mixin(
      mixin_name,
      docstring,
      category_name,
      base_operation_name,
      supported_operations,
  ):
      """Factory for mixins defining collections of delegated operations.
  
      This function generates mixins based on two common paradigms in cuDF:
  
      1. libcudf groups many operations into categories using a common API. These
         APIs usually accept an enum to delineate the specific operation to
         perform, e.g. binary operations use the `binary_operator` enum when
         calling the `binary_operation` function. cuDF Python mimics this
         structure by having operations within a category delegate to a common
         internal function (e.g. DataFrame.__add__ calls DataFrame._binaryop).
      2. Many cuDF classes implement similar operations (e.g. `sum`) via
         delegation to lower-level APIs before reaching a libcudf C++ function
         call. As a result, many API function calls actually involve multiple
         delegations to lower-level APIs that can look essentially identical. An
         example of such a sequence would be DataFrame.sum -> DataFrame._reduce
         -> Column.sum -> Column._reduce -> libcudf.
  
      This factory creates mixins for a category of operations implemented by via
      this delegator pattern. The resulting mixins make it easy to share common
      functions across various classes while also providing a common entrypoint
      for implementing the centralized logic for a given category of operations.
      Its usage is best demonstrated by example below.
  
      Parameters
      ----------
      mixin_name : str
          The name of the class. This argument should be the same as the object
          that this function's output is assigned to, e.g.
          :code:`Baz = _create_delegating_mixin("Baz", ...)`.
      docstring : str
          The documentation string for the mixin class.
      category_name : str
          The category of operations for which a mixin is being created. This
          name will be used to define or access the following attributes as shown
          in the example below:
              - f'_{category_name}_DOCSTRINGS'
              - f'_VALID_{category_name}S'  # The subset of ops a subclass allows
              - f'_SUPPORTED_{category_name}S'  # The ops supported by the mixin
      base_operation_name : str
          The name given to the core function implementing this category of
          operations.  The corresponding function is the entrypoint for child
          classes.
      supported_ops : List[str]
          The list of valid operations that subclasses of the resulting mixin may
          request to be implemented.
  
      Examples
      --------
      >>> # The class below:
      >>> class Person:
      ...     def _greet(self, op):
      ...         print(op)
      ...
      ...     def hello(self):
      ...         self._greet("hello")
      ...
      ...     def goodbye(self):
      ...         self._greet("goodbye")
      >>> # can  be rewritten using a delegating mixin as follows:
      >>> Greeter = _create_delegating_mixin(
      ...     "Greeter", "", "GREETING", "_greet", {"hello", "goodbye", "hey"}
      ... )
      >>> # The `hello` and `goodbye` methods will now be automatically generated
      >>> # for the Person class below.
      >>> class Person(Greeter):
      ...     _VALID_GREETINGS = {"hello", "goodbye"}
      ...
      ...     def _greet(self, op: str):
      ...         '''Say {op}.'''
      ...         print(op)
      >>> mom = Person()
      >>> mom.hello()
      hello
      >>> # The Greeter class could also enable the `hey` method, but Person did
      >>> # not include it in the _VALID_GREETINGS set so it will not exist.
      >>> mom.hey()
      Traceback (most recent call last):
          ...
      AttributeError: 'Person' object has no attribute 'hey'
      >>> # The docstrings for each method are generated by formatting the _greet
      >>> # docstring with the operation name as well as any additional keys
      >>> # provided via the _GREETING_DOCSTRINGS parameter.
      >>> print(mom.hello.__doc__)
      Say hello.
      """
      # The first two attributes may be defined on subclasses of the generated
      # OperationMixin to indicate valid attributes and parameters to use when
      # formatting docstrings. The supported_attr will be defined on the
      # OperationMixin itself to indicate what operations its subclass may
      # inherit from it.
      validity_attr = f"_VALID_{category_name}S"
      docstring_attr = f"_{category_name}_DOCSTRINGS"
      supported_attr = f"_SUPPORTED_{category_name}S"
  
      class OperationMixin:
          @classmethod
          def __init_subclass__(cls):
              # Support composition of various OperationMixins. Note that since
              # this __init_subclass__ is defined on mixins, it does not prohibit
              # classes that inherit it from implementing this method as well as
              # long as those implementations also include this super call.
              super().__init_subclass__()
  
              # Only add the valid set of operations for a particular class.
              valid_operations = set()
              for base_cls in cls.__mro__:
                  # Check for sentinel indicating that all operations are valid.
                  valid_operations |= getattr(
                      base_cls, validity_attr, set()
                  )
  
              invalid_operations = (
                  valid_operations - supported_operations
              )
              assert (
                  len(invalid_operations) == 0
              ), f"Invalid requested operations: {invalid_operations}"
  
              base_operation = getattr(cls, base_operation_name)
              for operation in valid_operations:
                  if _should_define_operation(
                      cls, operation, base_operation_name
                  ):
                      docstring_format_args = getattr(
                          cls, docstring_attr, {}
                      ).get(operation, {})
                      op_attr = Operation(
                          operation,
                          docstring_format_args,
                          base_operation,
                      )
                      setattr(cls, operation, op_attr)
  
      OperationMixin.__name__ = mixin_name
      OperationMixin.__qualname__ = mixin_name
      OperationMixin.__doc__ = docstring
  
      def _operation(self, op: str, *args, **kwargs):
          raise NotImplementedError
  
      _operation.__name__ = base_operation_name
      _operation.__qualname__ = ".".join(
          [mixin_name, base_operation_name]
      )
      _operation.__doc__ = (
          f"The core {category_name.lower()} function. Must be overridden by "
          "subclasses, the default implementation raises a NotImplementedError."
      )
  
      setattr(OperationMixin, base_operation_name, _operation)
      # Making this attribute available makes it easy for subclasses to indicate
      # that all supported operations for this mixin are valid.
      setattr(OperationMixin, supported_attr, supported_operations)
  
      return OperationMixin
  
imports: import inspect
label_desc: Use image node_id 3 for calling a global function with example usage: _create_delegating_mixin(mixin_name, docstring, category_name, base_operation_name, supported_operations) and returns: OperationMixin