class_docstr: A mixin for defining  ops on an ExtensionArray.
  
  It is assumed that the underlying scalar objects have the operators
  already defined.
  
  Notes
  -----
  If you have defined a subclass MyExtensionArray(ExtensionArray), then
  use MyExtensionArray(ExtensionArray, ExtensionScalarOpsMixin) to
  get the arithmetic operators.  After the definition of MyExtensionArray,
  insert the lines
  
  MyExtensionArray._add_arithmetic_ops()
  MyExtensionArray._add_comparison_ops()
  
  to link the operators to your class.
  
  .. note::
  
     You may want to set ``__array_priority__`` if you want your
     implementation to be called when involved in binary operations
     with NumPy arrays.
class_docstr_tok: ["A","mixin","for","defining","ops","on","an","ExtensionArray",".","It","is","assumed","that","the","underlying","scalar","objects","have","the","operators","already","defined",".","Notes","--","--","-","If","you","have","defined","a","subclass","MyExtensionArray","(","ExtensionArray",")",",","then","use","MyExtensionArray","(","ExtensionArray",",","ExtensionScalarOpsMixin",")","to","get","the","arithmetic","operators",".","After","the","definition","of","MyExtensionArray",",","insert","the","lines","MyExtensionArray._add_arithmetic_ops","(",")","MyExtensionArray._add_comparison_ops","(",")","to","link","the","operators","to","your","class",".","..","note",":",":","You","may","want","to","set","``","__array_priority__","``","if","you","want","your","implementation","to","be","called","when","involved","in","binary","operations","with","NumPy","arrays","."]
docstr: A class method that returns a method that will correspond to an
  operator for an ExtensionArray subclass, by dispatching to the
  relevant operator defined on the individual elements of the
  ExtensionArray.
  
  Parameters
  ----------
  op : function
      An operator that takes arguments op(a, b)
  coerce_to_dtype :  bool, default True
      boolean indicating whether to attempt to convert
      the result to the underlying ExtensionArray dtype.
      If it's not possible to create a new ExtensionArray with the
      values, an ndarray is returned instead.
  
  Returns
  -------
  Callable[[Any, Any], Union[ndarray, ExtensionArray]]
      A method that can be bound to a class. When used, the method
      receives the two arguments, one of which is the instance of
      this class, and should return an ExtensionArray or an ndarray.
  
      Returning an ndarray may be necessary when the result of the
      `op` cannot be stored in the ExtensionArray. The dtype of the
      ndarray uses NumPy's normal inference rules.
  
  Example
  -------
  Given an ExtensionArray subclass called MyExtensionArray, use
  
  >>> __add__ = cls._create_method(operator.add)
  
  in the class definition of MyExtensionArray to create the operator
  for addition, that will be based on the operator implementation
  of the underlying elements of the ExtensionArray
docstr_tok: ["A","class","method","that","returns","a","method","that","will","correspond","to","an","operator","for","an","ExtensionArray","subclass",",","by","dispatching","to","the","relevant","operator","defined","on","the","individual","elements","of","the","ExtensionArray",".","Parameters","--","--","--","--","--","op",":","function","An","operator","that","takes","arguments","op","(","a",",","b",")","coerce_to_dtype",":","bool",",","default","True","boolean","indicating","whether","to","attempt","to","convert","the","result","to","the","underlying","ExtensionArray","dtype",".","If","it","'s","not","possible","to","create","a","new","ExtensionArray","with","the","values",",","an","ndarray","is","returned","instead",".","Returns","--","--","--","-","Callable","[","[","Any",",","Any","]",",","Union","[","ndarray",",","ExtensionArray","]","]","A","method","that","can","be","bound","to","a","class",".","When","used",",","the","method","receives","the","two","arguments",",","one","of","which","is","the","instance","of","this","class",",","and","should","return","an","ExtensionArray","or","an","ndarray",".","Returning","an","ndarray","may","be","necessary","when","the","result","of","the","`","op","`","can","not","be","stored","in","the","ExtensionArray",".","The","dtype","of","the","ndarray","uses","NumPy","'s","normal","inference","rules",".","Example","--","--","--","-","Given","an","ExtensionArray","subclass","called","MyExtensionArray",",","use",">",">",">","__add__","=","cls._create_method","(","operator.add",")","in","the","class","definition","of","MyExtensionArray","to","create","the","operator","for","addition",",","that","will","be","based","on","the","operator","implementation","of","the","underlying","elements","of","the","ExtensionArray"]
code: def _create_method(cls, op, coerce_to_dtype=True):
      """
      A class method that returns a method that will correspond to an
      operator for an ExtensionArray subclass, by dispatching to the
      relevant operator defined on the individual elements of the
      ExtensionArray.
  
      Parameters
      ----------
      op : function
          An operator that takes arguments op(a, b)
      coerce_to_dtype :  bool, default True
          boolean indicating whether to attempt to convert
          the result to the underlying ExtensionArray dtype.
          If it's not possible to create a new ExtensionArray with the
          values, an ndarray is returned instead.
  
      Returns
      -------
      Callable[[Any, Any], Union[ndarray, ExtensionArray]]
          A method that can be bound to a class. When used, the method
          receives the two arguments, one of which is the instance of
          this class, and should return an ExtensionArray or an ndarray.
  
          Returning an ndarray may be necessary when the result of the
          `op` cannot be stored in the ExtensionArray. The dtype of the
          ndarray uses NumPy's normal inference rules.
  
      Example
      -------
      Given an ExtensionArray subclass called MyExtensionArray, use
  
      >>> __add__ = cls._create_method(operator.add)
  
      in the class definition of MyExtensionArray to create the operator
      for addition, that will be based on the operator implementation
      of the underlying elements of the ExtensionArray
      """
  
      def _binop(self, other):
          def convert_values(param):
              if isinstance(param, ExtensionArray) or is_list_like(
                  param
              ):
                  ovalues = param
              else:  # Assume its an object
                  ovalues = [param] * len(self)
              return ovalues
  
          if isinstance(other, (ABCSeries, ABCIndexClass)):
              # rely on pandas to unbox and dispatch to us
              return NotImplemented
  
          lvalues = self
          rvalues = convert_values(other)
  
          # If the operator is not defined for the underlying objects,
          # a TypeError should be raised
          res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
  
          def _maybe_convert(arr):
              if coerce_to_dtype:
                  # https://github.com/pandas-dev/pandas/issues/22850
                  # We catch all regular exceptions here, and fall back
                  # to an ndarray.
                  try:
                      res = self._from_sequence(arr)
                  except Exception:
                      res = np.asarray(arr)
              else:
                  res = np.asarray(arr)
              return res
  
          if op.__name__ in {"divmod", "rdivmod"}:
              a, b = zip(*res)
              res = _maybe_convert(a), _maybe_convert(b)
          else:
              res = _maybe_convert(res)
          return res
  
      op_name = ops._get_op_name(op, True)
      return set_function_name(_binop, op_name, cls)
  
imports: import operator
  import numpy
  from pandas.compat import PY3, set_function_name
  from pandas.compat.numpy import function
  from pandas.errors import AbstractMethodError
  from pandas.util._decorators import Appender, Substitution
  from pandas.core.dtypes.common import is_list_like
  from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
  from pandas.core.dtypes.missing import isna
  from pandas.core import ops
label_desc: Use image node_id 1 for calling the ExtensionScalarOpsMixin obj's underlying member method code with example usage: obj._create_method(cls, op, coerce_to_dtype) and returns: set_function_name, res, ovalues, NotImplemented, res