pandas/core/arrays/base.py
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
            boolean indicating whether to attempt to convert
            the result to the underlying ExtensionArray dtype
            (default True)

        Returns
        -------
        A method that can be bound to a method of a class

        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
            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)]

            if coerce_to_dtype:
                try:
                    res = self._from_sequence(res)
                except TypeError:
                    pass

            return res

        op_name = ops._get_op_name(op, True)
        return set_function_name(_binop, op_name, cls)

        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
            boolean indicating whether to attempt to convert
            the result to the underlying ExtensionArray dtype
            (default True)

        Returns
        -------
        A method that can be bound to a method of a class

        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

        
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
boolean indicating whether to attempt to convert
the result to the underlying ExtensionArray dtype
(default True)

Returns

A method that can be bound to a method of a class

Example

Given an ExtensionArray subclass called MyExtensionArray, use



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
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 boolean indicating whether to attempt to convert the result to the underlying ExtensionArray dtype ( default True ) Returns A method that can be bound to a method of a class Example Given an ExtensionArray subclass called MyExtensionArray use 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 _create_method(cls, op, coerce_to_dtype=True):
        def _binop(self, other):
            def convert_values(param):
                if isinstance(param, ExtensionArray) or is_list_like(param):
                    ovalues = param
                else:  
                    ovalues = [param] * len(self)
                return ovalues
            lvalues = self
            rvalues = convert_values(other)
            res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
            if coerce_to_dtype:
                try:
                    res = self._from_sequence(res)
                except TypeError:
                    pass
            return res
        op_name = ops._get_op_name(op, True)
        return set_function_name(_binop, op_name, cls)
def _create_method ( cls , op , coerce_to_dtype = True ) : def _binop ( self , other ) : def convert_values ( param ) : if isinstance ( param , ExtensionArray ) or is_list_like ( param ) : ovalues = param else : ovalues = [ param ] * len ( self ) return ovalues lvalues = self rvalues = convert_values ( other ) res = [ op ( a , b ) for ( a , b ) in zip ( lvalues , rvalues ) ] if coerce_to_dtype : try : res = self . _from_sequence ( res ) except TypeError : pass return res op_name = ops . _get_op_name ( op , True ) return set_function_name ( _binop , op_name , cls )
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.
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 .
"""
        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
            boolean indicating whether to attempt to convert
            the result to the underlying ExtensionArray dtype
            (default True)

        Returns
        -------
        A method that can be bound to a method of a class

        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

        """ # Assume its an object # If the operator is not defined for the underlying objects, # a TypeError should be raised
cls
op
coerce_to_dtype