
x\c           @   s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z m Z m Z d d l j Z d d l m Z d d l m Z d d l m Z d d l m Z m Z m Z d d	 l m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( d d
 l) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 d d l1 m2 Z2 m3 Z3 d d l4 Z5 d d l6 j7 j8 Z9 d d l: j7 j; Z; d   Z< d   Z= d   Z> d   Z? d   Z@ d   ZA d   ZB d   ZC d   ZD d   ZE d   ZF d   ZG d   ZH d   ZI d   ZJ d   ZK d   ZL d   ZM d   ZN d   ZO d    ZP i i d! d" 6d# d$ 6d% d& 6d' 6i d( d" 6d) d$ 6d* d& 6d+ 6i d, d" 6d- d$ 6d. d& 6d d/ 6d0 6i d1 d" 6d2 d$ 6d3 d& 6d4 6i d5 d" 6d6 d$ 6d7 d& 6d d/ 6d8 6i d9 d" 6d: d$ 6d; d& 6d d/ 6d< 6i d= d" 6d> d$ 6d? d& 6d d/ 6d@ 6i dA d" 6dB d$ 6dC d& 6d d/ 6dA 6i dD d" 6dE d$ 6d d& 6dF 6i dG d" 6dH d$ 6d d& 6dI 6i dJ d" 6dK d$ 6d d& 6dL 6i dM d" 6dN d$ 6d d& 6dO 6i dP d" 6dQ d$ 6d d& 6dR 6i dS d" 6dT d$ 6d d& 6dU 6ZR eS eR jT    ZU xi eU D]a ZV eW eR eV dV <eR eV d& ZX eX d k	 r(eR eV jY   eR eX <eZ eR eX dV <eV eR eX d& <q(q(WdW Z[ dX Z\ dY Z] dZ Z^ d[ Z_ d\ Z` d]   Za d^   Zb d_   Zc d`   Zd da   Ze db   Zf d d dc  Zg dd   Zh de   Zi df   Zj dg   Zk dh   Zl di   Zm dj   Zn eW dk  Zo d dl  Zp d dm  Zq dn   Zr do   Zs dp   Zt dq   Zu dr   Zv d d d ds  Zw dt   Zx du   Zy dv   Zz dw   Z{ dx   Z| dy   Z} dz   Z~ d{   Z d|   Z d}   Z d~   Z d S(   sD   
Arithmetic operations for PandasObjects

This is not a public API.
i(   t   divisionN(   t   algost   libt   ops(   t   bind_method(   t   NullFrequencyError(   t   Appender(   t'   construct_1d_object_array_from_listliket   find_common_typet   maybe_upcast_putmask(   t   ensure_objectt   is_bool_dtypet   is_categorical_dtypet   is_datetime64_dtypet   is_datetime64tz_dtypet   is_datetimelike_v_numerict   is_extension_array_dtypet   is_integer_dtypet   is_list_liket   is_object_dtypet   is_period_dtypet	   is_scalart   is_timedelta64_dtypet   needs_i8_conversion(   t   ABCDataFramet   ABCIndext   ABCIndexClasst   ABCPanelt	   ABCSeriest   ABCSparseArrayt   ABCSparseSeries(   t   isnat   notnac         C   s7   t  | t t j f  r* t |  |  } n	 |  j } | S(   s  
    Find the appropriate name to pin to an operation result.  This result
    should always be either an Index or a Series.

    Parameters
    ----------
    left : {Series, Index}
    right : object

    Returns
    -------
    name : object
        Usually a string
    (   t
   isinstanceR   t   pdt   Indext   _maybe_match_namet   name(   t   leftt   rightR%   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   get_op_result_name+   s    	c         C   sh   t  |  d  } t  | d  } | rJ | rJ |  j | j k rC |  j Sd Sn | rW |  j S| rd | j Sd S(   s  
    Try to find a name to attach to the result of an operation between
    a and b.  If only one of these has a `name` attribute, return that
    name.  Otherwise return a consensus name if they match of None if
    they have different names.

    Parameters
    ----------
    a : object
    b : object

    Returns
    -------
    name : str or None

    See Also
    --------
    pandas.core.common.consensus_name_attr
    R%   N(   t   hasattrR%   t   None(   t   at   bt   a_hast   b_has(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR$   B   s    c         C   s}   t  |   t j k r" t j |   St |  t j  rN t |   rN t j |   St |  t j	  ry t
 |   ry t j |   S|  S(   sa  
    Cast non-pandas objects to pandas types to unify behavior of arithmetic
    and comparison operations.

    Parameters
    ----------
    obj: object

    Returns
    -------
    out : object

    Notes
    -----
    Be careful to call this *after* determining the `name` attribute to be
    attached to the result of the arithmetic operation.
    (   t   typet   datetimet	   timedeltaR"   t	   TimedeltaR!   t   npt   timedelta64R   t   ndarrayR   t   TimedeltaIndex(   t   obj(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   maybe_upcast_for_ope   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   radd   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rsub   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rmul   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rdiv   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rtruediv   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt	   rfloordiv   s    c         C   s>   t  | t j  r6 t d j d t |   j    n  | |  S(   Ns&   {typ} cannot perform the operation modt   typ(   R!   t   compatt   string_typest	   TypeErrort   formatR/   t   __name__(   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rmod   s    c         C   s   t  | |   S(   N(   t   divmod(   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rdivmod   s    c         C   s   | |  S(   N(    (   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rpow   s    c         C   s   t  j | |   S(   N(   t   operatort   and_(   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rand_   s    c         C   s   t  j | |   S(   N(   RI   t   or_(   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   ror_   s    c         C   s   t  j | |   S(   N(   RI   t   xor(   R&   R'   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   rxor   s    c            s   d   f d  }   | _ | S(   s   
    Return a binary method that always raises a TypeError.

    Parameters
    ----------
    name : str

    Returns
    -------
    invalid_op : function
    c            s+   t  d j d   d t |   j    d  S(   Ns1   cannot perform {name} with this index type: {typ}R%   R?   (   RB   RC   R/   RD   (   t   selft   other(   R%   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt
   invalid_op   s    N(   R*   RD   (   R%   RR   (    (   R%   s.   lib/python2.7/site-packages/pandas/core/ops.pyt   make_invalid_op   s    	c         C   sy   i  } |  j  d d  }  |  j d  rC |  d k rC t | d <qC n  |  d k r\ t | d	 <n  |  d k ru t | d <n  | S(   sB  
    Find the keyword arguments to pass to numexpr for the given operation.

    Parameters
    ----------
    name : str

    Returns
    -------
    eval_kwargs : dict

    Examples
    --------
    >>> _gen_eval_kwargs("__add__")
    {}

    >>> _gen_eval_kwargs("rtruediv")
    {'reversed': True, 'truediv': True}
    t   __t    t   rR9   t   randt   rorRO   t   reversedt   truedivR=   t   net   masker(   R9   RW   RX   RO   (   RZ   R=   (   R[   (   t   replacet
   startswitht   True(   R%   t   kwargs(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _gen_eval_kwargs   s    c         C   sI   |  j  d  }  d |  k r' t j } n d |  k r? t j } n d } | S(   s#  
    Find the appropriate fill value to use when filling in undefined values
    in the results of the given operation caused by operating on
    (generally dividing by) zero.

    Parameters
    ----------
    name : str

    Returns
    -------
    fill_value : {None, np.nan, np.inf}
    RT   t   divt   modN(   t   stripR3   t   inft   nanR*   (   R%   t
   fill_value(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _gen_fill_zeros  s    c         C   s7   |  j  d d  d k r d S|  j d  r/ d Sd Sd S(	   s  
    Only DataFrame cares about default_axis, specifically:
    special methods have default_axis=None and flex methods
    have default_axis='columns'.

    Parameters
    ----------
    name : str

    Returns
    -------
    default_axis: str or None
    t   __rRT   t   __and__t   __or__t   __xor__t   columnsN(   Rj   Rk   Rl   (   R]   R^   R*   (   R%   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _get_frame_op_default_axis  s
    c         C   s$  t  | d d  } d | k } | s( d Si d t j 6d t 6d t j 6d t 6d t j 6d t 6d t j	 6d t
 6d t j 6d t 6d t j 6d	 t 6d
 t j 6d
 t 6d t j 6d t j 6d t j 6d t j 6d t j 6d t j 6d t j 6d t 6d t j 6d t 6d t j 6d t 6d t 6d t 6|  S(   s   
    Find the operation string, if any, to pass to numexpr for this
    operation.

    Parameters
    ----------
    op : binary operator
    cls : class

    Returns
    -------
    op_str : string or None
    t   _subtypRU   t   sparset   +t   *t   -t   /s   //t   %s   **s   ==s   !=s   <=t   <s   >=t   >t   &t   |t   ^N(   t   getattrR*   RI   t   addR9   t   mulR;   t   subR:   RZ   R=   t   floordivR>   Rc   RE   t   powRH   t   eqR[   t   let   ltt   get   gtRJ   RK   RL   RM   RN   RO   RF   RG   (   t   opt   clst   subtypt   use_numexpr(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt
   _get_opstr8  s@    














c         C   s1   |  j  j d  } | r- d j d |  } n  | S(   s   
    Find the name to attach to this method according to conventions
    for special and non-special methods.

    Parameters
    ----------
    op : binary operator
    special : bool

    Returns
    -------
    op_name : str
    t   _s   __{opname}__t   opname(   RD   Rd   RC   (   R   t   specialR   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _get_op_namel  s    Rq   R   t   Additiont   descR9   t   reverseR|   Rs   t   SubtractionR:   R~   Rr   t   MultiplicationR;   t   df_examplesR}   Ru   t   ModuloRE   Rc   s   **s   Exponential powerRH   R   Rt   s   Floating divisionR=   RZ   s   //s   Integer divisionR>   R   RF   s   Integer division and moduloRG   s   ==s   Equal toR   s   !=s   Not equal toR[   Rv   s	   Less thanR   s   <=s   Less than or equal toR   Rw   s   Greater thanR   s   >=s   Greater than or equal toR   RY   s  
{desc} of series and other, element-wise (binary operator `{op_name}`).

Equivalent to ``{equiv}``, but with support to substitute a fill_value for
missing data in one of the inputs.

Parameters
----------
other : Series or scalar value
fill_value : None or float value, default None (NaN)
    Fill existing missing (NaN) values, and any new element needed for
    successful Series alignment, with this value before computation.
    If data in both corresponding Series locations is missing
    the result will be missing
level : int or name
    Broadcast across a level, matching Index values on the
    passed MultiIndex level

Returns
-------
result : Series

See Also
--------
Series.{reverse}

Examples
--------
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
>>> a
a    1.0
b    1.0
c    1.0
d    NaN
dtype: float64
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
>>> b
a    1.0
b    NaN
d    1.0
e    NaN
dtype: float64
>>> a.add(b, fill_value=0)
a    2.0
b    1.0
c    1.0
d    1.0
e    NaN
dtype: float64
s  
Binary operator %s with support to substitute a fill_value for missing data in
one of the inputs

Parameters
----------
other : Series, DataFrame, or constant
axis : {0, 1, 'index', 'columns'}
    For Series input, axis to match Series index on
fill_value : None or float value, default None
    Fill existing missing (NaN) values, and any new element needed for
    successful DataFrame alignment, with this value before computation.
    If data in both corresponding DataFrame locations is missing
    the result will be missing
level : int or name
    Broadcast across a level, matching Index values on the
    passed MultiIndex level

Returns
-------
result : DataFrame

Notes
-----
Mismatched indices will be unioned together
sM  
{desc} of dataframe and other, element-wise (binary operator `{op_name}`).

Equivalent to ``{equiv}``, but with support to substitute a fill_value
for missing data in one of the inputs. With reverse version, `{reverse}`.

Among flexible wrappers (`add`, `sub`, `mul`, `div`, `mod`, `pow`) to
arithmetic operators: `+`, `-`, `*`, `/`, `//`, `%`, `**`.

Parameters
----------
other : scalar, sequence, Series, or DataFrame
    Any single or multiple element data structure, or list-like object.
axis :  {{0 or 'index', 1 or 'columns'}}
    Whether to compare by the index (0 or 'index') or columns
    (1 or 'columns'). For Series input, axis to match Series index on.
level : int or label
    Broadcast across a level, matching Index values on the
    passed MultiIndex level.
fill_value : float or None, default None
    Fill existing missing (NaN) values, and any new element needed for
    successful DataFrame alignment, with this value before computation.
    If data in both corresponding DataFrame locations is missing
    the result will be missing.

Returns
-------
DataFrame
    Result of the arithmetic operation.

See Also
--------
DataFrame.add : Add DataFrames.
DataFrame.sub : Subtract DataFrames.
DataFrame.mul : Multiply DataFrames.
DataFrame.div : Divide DataFrames (float division).
DataFrame.truediv : Divide DataFrames (float division).
DataFrame.floordiv : Divide DataFrames (integer division).
DataFrame.mod : Calculate modulo (remainder after division).
DataFrame.pow : Calculate exponential power.

Notes
-----
Mismatched indices will be unioned together.

Examples
--------
>>> df = pd.DataFrame({{'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]}},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df
           angles  degrees
circle          0      360
triangle        3      180
rectangle       4      360

Add a scalar with operator version which return the same
results.

>>> df + 1
           angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361

>>> df.add(1)
           angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361

Divide by constant with reverse version.

>>> df.div(10)
           angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0

>>> df.rdiv(10)
             angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778

Subtract a list and Series by axis with operator version.

>>> df - [1, 2]
           angles  degrees
circle         -1      358
triangle        2      178
rectangle       3      358

>>> df.sub([1, 2], axis='columns')
           angles  degrees
circle         -1      358
triangle        2      178
rectangle       3      358

>>> df.sub(pd.Series([1, 1, 1], index=['circle', 'triangle', 'rectangle']),
...        axis='index')
           angles  degrees
circle         -1      359
triangle        2      179
rectangle       3      359

Multiply a DataFrame of different shape with operator version.

>>> other = pd.DataFrame({{'angles': [0, 3, 4]}},
...                      index=['circle', 'triangle', 'rectangle'])
>>> other
           angles
circle          0
triangle        3
rectangle       4

>>> df * other
           angles  degrees
circle          0      NaN
triangle        9      NaN
rectangle      16      NaN

>>> df.mul(other, fill_value=0)
           angles  degrees
circle          0      0.0
triangle        9      0.0
rectangle      16      0.0

Divide by a MultiIndex by level.

>>> df_multindex = pd.DataFrame({{'angles': [0, 3, 4, 4, 5, 6],
...                              'degrees': [360, 180, 360, 360, 540, 720]}},
...                             index=[['A', 'A', 'A', 'B', 'B', 'B'],
...                                    ['circle', 'triangle', 'rectangle',
...                                     'square', 'pentagon', 'hexagon']])
>>> df_multindex
             angles  degrees
A circle          0      360
  triangle        3      180
  rectangle       4      360
B square          4      360
  pentagon        5      540
  hexagon         6      720

>>> df.div(df_multindex, level=1, fill_value=0)
             angles  degrees
A circle        NaN      1.0
  triangle      1.0      1.0
  rectangle     1.0      1.0
B square        0.0      0.0
  pentagon      0.0      0.0
  hexagon       0.0      0.0
s<  
{desc} of dataframe and other, element-wise (binary operator `{op_name}`).

Among flexible wrappers (`eq`, `ne`, `le`, `lt`, `ge`, `gt`) to comparison
operators.

Equivalent to `==`, `=!`, `<=`, `<`, `>=`, `>` with support to choose axis
(rows or columns) and level for comparison.

Parameters
----------
other : scalar, sequence, Series, or DataFrame
    Any single or multiple element data structure, or list-like object.
axis :  {{0 or 'index', 1 or 'columns'}}, default 'columns'
    Whether to compare by the index (0 or 'index') or columns
    (1 or 'columns').
level : int or label
    Broadcast across a level, matching Index values on the passed
    MultiIndex level.

Returns
-------
DataFrame of bool
    Result of the comparison.

See Also
--------
DataFrame.eq : Compare DataFrames for equality elementwise.
DataFrame.ne : Compare DataFrames for inequality elementwise.
DataFrame.le : Compare DataFrames for less than inequality
    or equality elementwise.
DataFrame.lt : Compare DataFrames for strictly less than
    inequality elementwise.
DataFrame.ge : Compare DataFrames for greater than inequality
    or equality elementwise.
DataFrame.gt : Compare DataFrames for strictly greater than
    inequality elementwise.

Notes
--------
Mismatched indices will be unioned together.
`NaN` values are considered different (i.e. `NaN` != `NaN`).

Examples
--------
>>> df = pd.DataFrame({{'cost': [250, 150, 100],
...                    'revenue': [100, 250, 300]}},
...                   index=['A', 'B', 'C'])
>>> df
   cost  revenue
A   250      100
B   150      250
C   100      300

Comparison with a scalar, using either the operator or method:

>>> df == 100
    cost  revenue
A  False     True
B  False    False
C   True    False

>>> df.eq(100)
    cost  revenue
A  False     True
B  False    False
C   True    False

When `other` is a :class:`Series`, the columns of a DataFrame are aligned
with the index of `other` and broadcast:

>>> df != pd.Series([100, 250], index=["cost", "revenue"])
    cost  revenue
A   True     True
B   True    False
C  False     True

Use the method to control the broadcast axis:

>>> df.ne(pd.Series([100, 300], index=["A", "D"]), axis='index')
   cost  revenue
A  True    False
B  True     True
C  True     True
D  True     True

When comparing to an arbitrary sequence, the number of columns must
match the number elements in `other`:

>>> df == [250, 100]
    cost  revenue
A   True     True
B  False    False
C  False    False

Use the method to control the axis:

>>> df.eq([250, 250, 100], axis='index')
    cost  revenue
A   True    False
B  False     True
C   True    False

Compare to a DataFrame of different shape.

>>> other = pd.DataFrame({{'revenue': [300, 250, 100, 150]}},
...                      index=['A', 'B', 'C', 'D'])
>>> other
   revenue
A      300
B      250
C      100
D      150

>>> df.gt(other)
    cost  revenue
A  False    False
B  False    False
C  False     True
D  False    False

Compare to a MultiIndex by level.

>>> df_multindex = pd.DataFrame({{'cost': [250, 150, 100, 150, 300, 220],
...                              'revenue': [100, 250, 300, 200, 175, 225]}},
...                             index=[['Q1', 'Q1', 'Q1', 'Q2', 'Q2', 'Q2'],
...                                    ['A', 'B', 'C', 'A', 'B', 'C']])
>>> df_multindex
      cost  revenue
Q1 A   250      100
   B   150      250
   C   100      300
Q2 A   150      200
   B   300      175
   C   220      225

>>> df.le(df_multindex, level=1)
       cost  revenue
Q1 A   True     True
   B   True     True
   C   True     True
Q2 A  False     True
   B   True    False
   C   True    False
s  
{desc} of series and other, element-wise (binary operator `{op_name}`).
Equivalent to ``{equiv}``.

Parameters
----------
other : DataFrame or Panel
axis : {{items, major_axis, minor_axis}}
    Axis to broadcast over

Returns
-------
Panel

See Also
--------
Panel.{reverse}
s   
Wrapper method for {op_name}

Parameters
----------
other : DataFrame or Panel
axis : {{items, major_axis, minor_axis}}
    Axis to broadcast over

Returns
-------
Panel
c      
   C   s(  |  j  d d  }  t |  } | d r? d | d d | } n | d | d d } | d k r t } | j d	 | d	 d
 |  d | d | d  } n | d k r t } | j d	 | d	 d
 |  d | d | d  } nM | d k rt } | j d	 | d	 d
 |  d | d | d  } n t d   | S(   st  
    Make the appropriate substitutions for the given operation and class-typ
    into either _flex_doc_SERIES or _flex_doc_FRAME to return the docstring
    to attach to a generated method.

    Parameters
    ----------
    op_name : str {'__add__', '__sub__', ... '__eq__', '__ne__', ...}
    typ : str {series, 'dataframe']}

    Returns
    -------
    doc : str
    RT   RU   RY   s   other R   t    s    othert   seriesR   t   op_namet   equivR   t	   dataframet   panels   Invalid typ argument.(   R]   t   _op_descriptionst   _flex_doc_SERIESRC   t   _flex_doc_FRAMEt   _flex_doc_PANELt   AssertionError(   R   R?   t   op_descR   t   base_doct   doc(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _make_flex_doc^  s&    

c         C   so   | d k	 re t |   } t |  } |  j   }  | j   } | | A} | |  | | @<| | | | @<n  |  | f S(   s  
    If a non-None fill_value is given, replace null entries in left and right
    with this value, but only in positions where _one_ of left/right is null,
    not both.

    Parameters
    ----------
    left : array-like
    right : array-like
    fill_value : object

    Returns
    -------
    left : array-like
    right : array-like

    Notes
    -----
    Makes copies if fill_value is not None
    N(   R*   R   t   copy(   R&   R'   Rg   t	   left_maskt
   right_maskt   mask(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt
   fill_binop  s    
c         C   s  |  j    } t j |  j d t } t | |  r | j    } t |  t |  @} | t j t | |   t j t | |    | | <n2 t |  } | t j t | |   |  | | <| t	 j
 k r t j | | t  n t j | | t  | j |  j  } | S(   s  
    Apply the function `op` to only non-null points in x and y.

    Parameters
    ----------
    x : array-like
    y : array-like
    op : binary operation
    allowed_types : class or tuple of classes

    Returns
    -------
    result : ndarray[bool]
    t   dtype(   t   ravelR3   t   emptyt   sizet   boolR!   R    t   arrayt   listRI   R[   t   putmaskR_   t   Falset   reshapet   shape(   t   xt   yR   t   allowed_typest   xravt   resultt   yravR   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   mask_cmp_op  s    #&c   	   	   C   sS  |  j    } t |  t j t f  s6 t t |     t | t j t t f  r%t |  j	 | j	 g  } t j
 |  j d | } t |  r | n	 | j    } t |  t |  @} | j | j k r t d   n  | j   r!t j d d  ) | | | t j | |   | | <Wd QXq!n t |  sCt t |    t |  t j  sgt t |     t j
 |  j d |  j	 } t |  } | t k rt j |  d k t |  } n* | t k rt j | d k t |  } n  | j   r!t j d d   | | | |  | | <Wd QXn  t | | t j  \ } } | j |  j  } | S(   s   
    If the given arithmetic operation fails, attempt it again on
    only the non-null elements of the input array(s).

    Parameters
    ----------
    x : np.ndarray
    y : np.ndarray, Series, Index
    op : binary operator
    R   s#   Cannot broadcast operands together.t   allt   ignoreNi   (   R   R!   R3   R5   R   R   R/   R   R   R   R   R   R   R    R   t
   ValueErrort   anyt   errstatet   comt   values_from_objectR   R   t   whereR   RH   R	   Rf   R   (	   R   R   R   R   R   R   R   R   t   changed(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   masked_arith_op  s6    *
&$ c         C   s   | t  j k r* t j |  j d t } nT | t  j k rT t j |  j d t } n* t d j	 d |  j
 d t |  j    | S(   s  
    If a comparison has mismatched types and is not necessarily meaningful,
    follow python3 conventions by:

        - returning all-False for equality
        - returning all-True for inequality
        - raising TypeError otherwise

    Parameters
    ----------
    left : array-like
    right : scalar, array-like
    op : operator.{eq, ne, lt, le, gt}

    Raises
    ------
    TypeError : on inequality comparisons
    R   s2   Invalid comparison between dtype={dtype} and {typ}R?   (   RI   R   R3   t   zerosR   R   R[   t   onesRB   RC   R   R/   RD   (   R&   R'   R   t
   res_values(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   invalid_comparison	  s    c         C   s   |  j  s | j  r t St |  j  s6 t | j  r: t S|  j j d } | j j d } t |  rr t |  s t |  r t |  r t St	 |  r t
 |  r t St S(   s   
    Identify cases where a DataFrame operation should dispatch to its
    Series counterpart.

    Parameters
    ----------
    left : DataFrame
    right : DataFrame
    op : binary operator

    Returns
    -------
    override : bool
    i    (   t   _is_mixed_typeR_   t   lenRm   R   t   dtypest   ilocR   R   R   R   (   R&   R'   R   t   ldtypet   rdtype(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   should_series_dispatch)  s     c   	         sf  d d l  j j j } t j |  } t j |  sH t j |  d k rZ   f d   } n t	 | t
  r | j |   s~ t    f d   } n t	 | t  r | d k r | j j |  j  s t    f d   } nH t	 | t  r| j j |  j  st    f d   } n t |   | j | | |  |  } |  j | d	 |  j d
 t } |  j | _ | S(   s  
    Evaluate the frame operation func(left, right) by evaluating
    column-by-column, dispatching to the Series implementation.

    Parameters
    ----------
    left : DataFrame
    right : scalar or DataFrame
    func : arithmetic or comparison operator
    str_rep : str or None, default None
    axis : {None, 0, 1, "index", "columns"}

    Returns
    -------
    DataFrame
    iNi    c            s)       f d   t  t   j   D S(   Nc            s5   i  |  ]+ }    j  d  d   | f   |  q S(   N(   R   (   t   .0t   i(   R+   R,   t   func(    s.   lib/python2.7/site-packages/pandas/core/ops.pys
   <dictcomp>g  s   	(   t   rangeR   Rm   (   R+   R,   (   R   (   R+   R,   s.   lib/python2.7/site-packages/pandas/core/ops.pyt	   column_opf  s    c            s)       f d   t  t   j   D S(   Nc            sH   i  |  ]> }    j  d  d   | f  j  d  d   | f  |  q S(   N(   R   (   R   R   (   R+   R,   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pys
   <dictcomp>n  s   	(   R   R   Rm   (   R+   R,   (   R   (   R+   R,   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   m  s    Rm   c            s)       f d   t  t   j   D S(   Nc            s<   i  |  ]2 }    j  d  d   | f  j  |  |  q S(   N(   R   (   R   R   (   R+   R,   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pys
   <dictcomp>w  s   	(   R   R   Rm   (   R+   R,   (   R   (   R+   R,   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   v  s    c            s)       f d   t  t   j   D S(   Nc            s5   i  |  ]+ }    j  d  d   | f   |  q S(   N(   R   (   R   R   (   R+   R,   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pys
   <dictcomp>~  s   	(   R   R   Rm   (   R+   R,   (   R   (   R+   R,   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   }  s    t   indexR   (   t#   pandas.core.computation.expressionst   coret   computationt   expressionsR   t   item_from_zerodimR   R3   t   ndimR!   R   t   _indexed_sameR   R   R   t   equalsRm   t   NotImplementedErrort   evaluatet   _constructorR   (	   R&   R'   R   t   str_rept   axisR   R   t   new_dataR   (    (   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyt   dispatch_to_seriesN  s$    $c         C   s   | |  } t  | d d  d k	 r9 | j d d  } n  y |  | |  } Wn, t k
 rz t d j d |  j    n X| S(   s  
    Wrap Series left in the given index_class to delegate the operation op
    to the index implementation.  DatetimeIndex and TimedeltaIndex perform
    type checking, timezone handling, overflow checks, etc.

    Parameters
    ----------
    op : binary operator (operator.add, operator.sub, ...)
    left : Series
    right : object
    index_class : DatetimeIndex or TimedeltaIndex

    Returns
    -------
    result : object, usually DatetimeIndex, TimedeltaIndex, or Series
    t   freqs=   incompatible type for a datetime/timedelta operation [{name}]R%   N(   R{   R*   t   _shallow_copyR   RB   RC   RD   (   R   R&   R'   t   index_classt   left_idxR   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   dispatch_to_index_op  s    c         C   s   t  | t t f  r! | j } n | } t  | t t f  rH | j } n | } |  | |  } t | |  } |  j d k r t | | | j |  St | | | j |  S(   sr   
    Assume that left or right is a Series backed by an ExtensionArray,
    apply the operator defined by op.
    RF   RG   (   RF   RG   (	   R!   R   R   t   _valuesR(   RD   t   _construct_divmod_resultR   t   _construct_result(   R   R&   R'   t   new_leftt	   new_rightR   t   res_name(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   dispatch_to_extension_op  s    
c         C   s  t  |  t  r0 t } t } t } t } t } n t  |  t  r` t } t } t } t } t } n t  |  t  r d } d } t
 } t
 } t
 } n` t  |  t  r t } t } t } t } t } n0 t  |  t  r t } t } t } t } t } n  | | | | | f S(   s  
    Find the appropriate operation-wrappers to use when defining flex/special
    arithmetic, boolean, and comparison operations with the given class.

    Parameters
    ----------
    cls : class

    Returns
    -------
    arith_flex : function or None
    comp_flex : function or None
    arith_special : function
    comp_special : function
    bool_special : function

    Notes
    -----
    None is only returned for SparseArray
    N(   t
   issubclassR   t   _flex_method_SERIESt   _arith_method_SPARSE_SERIESt   _bool_method_SERIESR   t   _arith_method_SERIESt   _comp_method_SERIESR   R*   t   _arith_method_SPARSE_ARRAYR   t   _flex_method_PANELt   _comp_method_PANELt   _arith_method_PANELR   t   _arith_method_FRAMEt   _flex_comp_method_FRAMEt   _comp_method_FRAME(   R   t
   arith_flext	   comp_flext   arith_specialt   comp_specialt   bool_special(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _get_method_wrappers  s>    					c             s  t  |  t  } t d | |  t j |  d | |  t |  d | |  t j |  d | |  t j |  d | |  t j |  d | |  t j	 |  d | |  t j
 |  d | |  t j |  d	 | |  t |  d
 | |  t |  d | |  t |  d | |  t |  d | |  t |  d | |  t |   } | d | d <| d | d <| rz| |  t |  | d <| |  t |  | d <n  | j t d | |  t j |  d | |  t j |  d | |  t j |  d | |  t j |  d | |  t j |  d | |  t j |    | r| j t d | |  t j |  d | |  t j |  d | |  t j |  d | |  t |  d | |  t |  d | |  t  |    n  | rd     n	 d        f d!   | j!   D } | S("   NR|   R9   R~   R}   RZ   R   Rc   R   R;   R:   R=   R>   RH   RE   Rb   R<   RF   RG   R   R[   R   R   R   R   RJ   RL   RN   RK   RM   RO   c         S   s   d j  d |  j d   S(   Ns
   __{name}__R%   R   (   RC   Rd   (   R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   <lambda>C  s    c         S   s   |  S(   N(    (   R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR  E  s    c            s%   i  |  ] \ } } |   |   q S(    (    (   R   t   kt   v(   t	   dunderize(    s.   lib/python2.7/site-packages/pandas/core/ops.pys
   <dictcomp>F  s   	 ("   R   R   t   dictRI   R|   R9   R~   R}   RZ   R   Rc   R   R;   R:   R=   R>   RH   RE   RF   RG   t   updateR   R[   R   R   R   R   RJ   RL   RN   RK   RM   RO   t   items(   R   t   arith_methodt   comp_methodt   bool_methodR   t   have_divmodt   new_methods(    (   R  s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _create_methods  sR    	c         C   sh   xa | j    D]S \ } } t |  t  o4 | j d  } | sM | |  j k r t |  | |  q q Wd  S(   Nt   __i(   R  R   R   R^   t   __dict__R   (   R   R  R%   t   methodt   force(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   add_methodsJ  s
    c         C   s3  t  |   \ } } } } } t |  | | | d t } d   } | j t d | | d  d | | d  d | | d  d	 | | d
  d | | d  d | | d  d | | d    t j s | | d  | d <n  | j t d | | d  d | | d  d | | d    t |  d | d S(   s   
    Adds the full suite of special arithmetic methods (``__add__``,
    ``__sub__``, etc.) to the class.

    Parameters
    ----------
    cls : class
        special methods will be defined and pinned to this class
    R   c            s4     f d   } d j  d   j j d   | _ | S(   s;   
        return an inplace wrapper for this method
        c            s8     |  |  } |  j  | j |  d t j d t |  S(   NR   t   verify_is_copy(   t   _update_inplacet   reindex_likeR   t   _data(   RP   RQ   R   (   R  (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   fm  s    s   __i{name}__R%   RT   (   RC   RD   Rd   (   R  R  (    (   R  s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _wrap_inplace_methodh  s    
!t   __iadd__t   __add__t   __isub__t   __sub__t   __imul__t   __mul__t   __itruediv__t   __truediv__t   __ifloordiv__t   __floordiv__t   __imod__t   __mod__t   __ipow__t   __pow__t   __div__t   __idiv__t   __iand__Rj   t   __ior__Rk   t   __ixor__Rl   R  N(   R  R  R_   R
  R	  R@   t   PY3R  (   R   R   R  R  R  R  R  (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   add_special_arithmetic_methodsX  s&    
			c      	      s   t  |   \ } } } } } t |  | | d d d t     j t d   d d   d d   d   t   f d	   d D  s t  t |  d   d S(   s   
    Adds the full suite of flex arithmetic methods (``pow``, ``mul``, ``add``)
    to the class.

    Parameters
    ----------
    cls : class
        flex methods will be defined and pinned to this class
    R  R   t   multiplyR}   t   subtractR~   t   divideRb   c         3   s   |  ] } |   k Vq d  S(   N(    (   R   t   kname(   R  (    s.   lib/python2.7/site-packages/pandas/core/ops.pys	   <genexpr>  s    RM   RO   RK   R  N(   RM   RO   RK   (	   R  R  R*   R   R
  R	  R   R   R  (   R   t   flex_arith_methodt   flex_comp_methodR   (    (   R  s.   lib/python2.7/site-packages/pandas/core/ops.pyt   add_flex_arithmetic_methods  s    
		
#c         C   sv   t  | t  rl |  j j | j  sl | rK |  j t  }  | j t  } n  |  j | d t \ }  } ql n  |  | f S(   s    align lhs and rhs Series R   (   R!   R   R   R   t   astypet   objectt   alignR   (   R&   R'   t   align_asobject(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _align_method_SERIES  s    !c         C   s(   |  j  | d | d | } | | _ | S(   s   
    If the raw op result has a non-None name (e.g. it is an Index object) and
    the name argument is None, then passing name to the constructor will
    not be enough; we still need to override the name attribute.
    R   R   (   R   R%   (   R&   R   R   R%   R   t   out(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    	c      	   C   sK   |  j  } | | d d | d | d | | | d d | d | d | f S(   sN   divmod returns a tuple of like indexed series instead of a single series.
    i    R   R%   R   i   (   R   (   R&   R   R   R%   R   t   constructor(    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    	c            s   t   |    t  |   t    t     t t g k rN t n t        f d      f d         f d   }  | _ | S(   s[   
    Wrapper function for Series arithmetic operations, to avoid
    code duplication.
    c            sy   d d  l  j j j } y | j   |  |    } Wn# t k
 rY t |  |   } n Xt j | |  |    } | S(   Ni(	   R   R   R   R   R   RB   R   t   missingt
   fill_zeros(   R   R   R   R   (   t   eval_kwargsRA  R   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   na_op  s    c            sm   y* t  j d d    |     SWd QXWn< t k
 rh t |   rb t j |     f d    S  n Xd S(   s@  
        return the result of evaluating na_op on the passed in values

        try coercion to object type if the native types are not compatible

        Parameters
        ----------
        lvalues : array-like
        rvalues : array-like

        Raises
        ------
        TypeError: invalid operation
        R   R   Nc            s     |    S(   N(    (   R   (   R   t   rvalues(    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    (   R3   R   t	   ExceptionR   t   libalgost   arrmap_object(   t   lvaluesRD  (   RC  R   (   RD  s.   lib/python2.7/site-packages/pandas/core/ops.pyt
   safe_na_op  s    	c      	      s  t  | t  r t St |  |  \ }  } t |  |  } t |  } t |   ry t d j d t	 |   j
 d     nt |   s t |   r t  |  | t j  }   |  | d |  j d | d | j St |   s t |  rt |  rt  |  |  St |   rCt  |  | t j  }   |  | d |  j d | St |  r t j |   |  }   |  | d |  j d | d | j S|  j } | } t  | t  r| j } n   | |  }   |  | d |  j d | d d  S(   Ns'   {typ} cannot perform the operation {op}R?   R   R   R%   R   (   R!   R   t   NotImplementedR=  R(   R8   R   RB   RC   R/   RD   R   R   R   R"   t   DatetimeIndexR   R   R   R   R   R   R6   R#   t   valuesR   R*   (   R&   R'   R   R   RH  RD  (   t   construct_resultR   RI  R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   wrapper   s@    

	(	   R   R   Ra   Rh   RF   RG   R   R   RD   (   R   R   R   RN  (    (   RM  RB  RA  RC  R   R   RI  R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    
3	c         C   s   t  | t  r t |  } n  t  | t j t t f  r t | j  s] | j	 t j
  } n  t  | t t f  r~ | j } n  t j | | |   } n t j | | |   } | S(   N(   R!   R   R   R3   R5   R   R   R   R   R9  t   object_RL  t   libopst   vec_comparet   scalar_compare(   R   R   R   R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _comp_method_OBJECT_ARRAY7  s    c            s^   t   |   t   j d t        f d    d   f d  }  | _ | S(   s[   
    Wrapper function for Series arithmetic operations, to avoid
    code duplication.
    R\   c            sf  t  |  o t |  s  t  t |  j  rD t  |  |  } nt |  |  rc t |  |   St |   sv t  d  } t |  r t |  r t
 |   t
 |  B} | j d  } |  j d  }  n  t |   d   } | d  k	 r.t j d d   | |  } Wd  QX| t k r=t |  |   Sn  |  |  } | d  k	 rb| j   rb  | | <n  | S(   Nt   i8R   R   (   R   R   R   R   R   RS  R   R   R   R*   R   t   viewR{   R3   R   RJ  R   (   R   R   R   R   R  (   R\   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRC  O  s*     c   
   	      s3  | d  k	 r |  j |  n  t |  |  } t | t  rL t j |  } n  t | t  r_ t St | t	  r |  j
 |  r t d   nt |   r t  |  | t j  } |  j | d |  j d | St |   s t |   rt | t j  rt | t j  rd }  t j t j t j t j h k r=d } n d } d j t j | j d |    } t j  | t! d	 d
 t j" |  } n  t  |  | t j#  } |  j | d |  j d | St$ |   rt  |  | t j%  } |  j | d |  j d | St& |   s(t& |  r8t' |  r8t(  |  |  St | t	  r  |  j) | j)  } |  j | d |  j d | j* |  St | t j+ t j, f  r| j- d k rt. |   t. |  k rt d   n    |  j) t j |   } |  j | d |  j } | j/ |   j* |  St' |  rt0 |  r t j1 k r`t j2 t. |   d t3 } n t j4 t. |   d t3 } |  j | d |  j d | d d S|  j5   } t j6 d d     | |  }	 Wd  QXt' |	  rt7 d j d t8 |     n  t9 j: |	  } |  j | d |  j d | d d Sd  S(   Ns3   Can only compare identically-labeled Series objectsR   R%   s   Comparing Series of datetimes with 'datetime.date'.  Currently, the 'datetime.date' is coerced to a datetime. In the future pandas will not coerce, and {future}. To retain the current behavior, convert the 'datetime.date' to a datetime with 'pd.Timestamp'.s   a TypeError will be raiseds9   'the values will not compare equal to the 'datetime.date's   
t   futuret
   stackleveli   i    s   Lengths must match to compareR   R   R   R   s(   Could not compare {typ} type with SeriesR?   (;   R*   t   _get_axis_numberR(   R!   R   R3   t   asarrayR   RJ  R   R   R   R   R   R"   t   CategoricalR   R   R   R   R0   t   dateRI   R   R   R   R   t   joint   textwrapt   wrapRC   t   warningst   warnt   FutureWarningt	   TimestampRK  R   R6   R   R   R   RL  t   renameR5   R#   R   R   t   __finalize__R   R[   R   R   R   t
   get_valuesR   RB   R/   R   R   (
   RP   RQ   R   R   R   t   msgRV  R   RL  t   res(   RC  R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRN  |  sx    	$	$'N(   R   Ra   t   getR   R*   RD   (   R   R   R   RN  (    (   R\   RC  R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   G  s    -t	c            sR   t   |  }  f d    d    d         f d   } | | _ | S(   s[   
    Wrapper function for Series arithmetic operations, to avoid
    code duplication.
    c      	      sA  y   |  |  } Wn't  k
 r<t | t t t f  sB t  t | t j  r t |   oi t |  ss t  t	 |   }  t	 |  } t
 j |  |    } q=t j |  s t  t |  s t |  } n  y t
 j |  |    } Wq=t  t t t t f k
 r8t  d j d |  j d t |  j    q=Xn X| S(   NsE   cannot compare a dtyped [{dtype}] array with a scalar of type [{typ}]R   R?   (   RB   R!   R   R   R   R   R3   R5   R   R
   RP  t	   vec_binopR   R   R   R   t   scalar_binopR   t   AttributeErrort   OverflowErrorR   RC   R   R/   RD   (   R   R   R   (   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRC    s(    
	c         S   s   |  j  d  S(   Ni    (   t   fillna(   R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    c         S   s   |  j  t  j t  S(   N(   Rm  R   R9  R   (   R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    c            sY  t    j  } t   | d t \   } t   |  } t | t  rL t St | t t	 f  r t  | j  } | r  |  n	  |  } | j
 } d   } nX t  t j |   } t |  r t | t j  r t |  } n  | }   f d   } | r| r n  }    j
 |  }   j | d   j d | }	 | |	  }
 | |
  S(   NR<  c         S   s   |  S(   N(    (   R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR  (  s    c            s   |  j     S(   N(   Rd  (   R   (   RP   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR  4  s    R   R%   (   R   R   R=  R_   R(   R!   R   RJ  R   R   RL  R3   RY  R   R5   R   R   R   (   RP   RQ   t   is_self_int_dtypeR   t   is_other_int_dtypet   ovaluest	   finalizert   fillerR   t   unfilledt   filled(   t	   fill_boolt   fill_intRC  (   RP   s.   lib/python2.7/site-packages/pandas/core/ops.pyRN    s,    	(   R   RD   (   R   R   R   R   RN  (    (   Ru  Rv  RC  R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    		'	c            sO   t    |  } t | d  } t |  d  d  d   f d   } | | _ | S(   NR   i    c            s  | d  k	 r |  j |  n  t | t  rG |  j |   d | d | St | t j t t f  r t	 |  t	 |   k r t
 d   n  |  j | |  j  } |  j |   d | d | S| d  k	 r |  j |  }  n  |  j   |  |  |  j  j |   Sd  S(   Nt   levelRg   s   Lengths must be equal(   R*   RX  R!   R   t   _binopR3   R5   R   t   tupleR   R   R   R   Rm  Rd  (   RP   RQ   Rw  Rg   R   (   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   flex_wrapperH  s    (   R   R   R   R*   RD   (   R   R   R   R%   R   Rz  (    (   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   D  s    		c         C   s   | d k	 r' t d j d |    n  | d k	 r} |  j |  } | d k rd |  j | | d | S|  j | | d | Sn^ t |  s |  t j St |   s |  j	 d |  j
 d |  j d |  j  S|  j | | d | Sd S(	   s  
    Apply binary operator `func` to self, other using alignment and fill
    conventions determined by the fill_value, axis, and level kwargs.

    Parameters
    ----------
    self : DataFrame
    other : Series
    func : binary operator
    fill_value : object, default None
    axis : {0, 1, 'columns', 'index', None}, default None
    level : int or None, default None

    Returns
    -------
    result : DataFrame
    s    fill_value {fill} not supported.t   filli    Rw  t   dataR   Rm   N(   R*   R   RC   RX  t   _combine_match_indext   _combine_match_columnsR   R3   Rf   R   t   _seriesR   Rm   (   RP   RQ   R   Rg   R   Rw  (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _combine_series_framec  s    
c            s     f d   } t  | t j  r| j d k rB | |  } q| j d k r`| j  j k r  j | d  j d  j } q| j d  j d k r | j d d k r t j |  j  }  j | d  j d  j } q| j d  j d k r9| j d d k r9| | d d d  f  } qt	 d j
 d	  j d
 | j    q| j d k rt	 d j
 d | j    qn1 t |  rt  | t t f  r| |  } n  | S(   sD    convert rhs to meet lhs dims if input is list, tuple or np.ndarray c            s   d }   d  k	 r  j    d k r t  j  t |   k rr t | j d t  j  d t |      n   j |  d  j }  nc t  j  t |   k r t | j d t  j  d t |      n   j |  d  j }  |  S(   NsG   Unable to coerce to Series, length must be {req_len}: given {given_len}R   t   req_lent	   given_len(   R*   t   _get_axis_nameR   R   R   RC   t   _constructor_slicedRm   (   R'   Rf  (   R   R&   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt	   to_series  s    !i   i   R   Rm   i    NsM   Unable to coerce to DataFrame, shape must be {req_shape}: given {given_shape}t	   req_shapet   given_shapes=   Unable to coerce to Series/DataFrame, dim must be <= 2: {dim}t   dim(   R!   R3   R5   R   R   R   R   Rm   t   broadcast_toR   RC   R   R   R   (   R&   R'   R   R  (    (   R   R&   s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _align_method_FRAME  s2    -	-	c            s   t   |    t  |   t     t    t   }       f d     t k r{ t  d  } n
 t  } t |  | d  d    f d   }  | _
 | S(   Nc            sy   d d  l  j j j } y | j   |  |    } Wn# t k
 rY t |  |   } n Xt j | |  |    } | S(   Ni(	   R   R   R   R   R   RB   R   R@  RA  (   R   R   R   R   (   RB  RA  R   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRC    s    R   c      
      s   t  |  | |  } t | t  rU t |  |   r9  n   } |  j | | | |  St | t  r | d k rv  n   } t |  | | d | d | d | S| d  k	 r |  j |  }  n  t	 j
 |  d k s t  |  j |   Sd  S(   Ni    Rm   Rg   R   Rw  (   i    Rm   N(   R  R!   R   R   t   _combine_frameR   R*   R  Rm  R3   R   R   t   _combine_const(   RP   RQ   R   Rw  Rg   t   pass_op(   RC  R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    (   R   R   Ra   Rh   Rn   R   R   t   _arith_doc_FRAMER   R*   RD   (   R   R   R   t   default_axisR   R  (    (   RB  RA  RC  R   R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    
		c            s   t   |    t  |  } t |  }  f d     t j d | d t | d  } t |  | d     f d   } | | _ | S(   Nc            sb   y, t  j d d     |  |  } Wd  QXWn/ t k
 r] t |  |   t  j t f  } n X| S(   Nt   invalidR   (   R3   R   RB   R   R5   R   (   R   R   R   (   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRC     s    "R   R   c      
      s   t  |  | |  } t | t  rj |  j |  sW |  j | d d | d t \ }  } n  t |  |     St | t  r t |  |   d d  d | d | St
 j |  d k s t |   |  j |    Sd  S(   Nt   outerRw  R   Rg   R   i    (   R  R!   R   R   R;  R   R   R   R  R*   R3   R   R   R  (   RP   RQ   R   Rw  (   RC  R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    !(	   R   R   Rn   t   _flex_comp_doc_FRAMERC   R   R   R*   RD   (   R   R   R   R   R  R   R  (    (   RC  R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    		c            sU   t    |    t   |  } t d j d |      f d    } | | _ | S(   Ns$   Wrapper for comparison method {name}R%   c      
      s   t  |  | d d  } t | t  rU |  j |  sB t d   n  t |  |     St | t  r t |  |   d d  d d  d d  S|  j	 |    } | j
 t  j t  Sd  S(   NR   s6   Can only compare identically-labeled DataFrame objectsRg   Rw  (   R  R*   R!   R   R   R   R   R   R  R  Rm  R_   R9  R   (   RP   RQ   Rg  (   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR  (  s    (   R   R   R   RC   RD   (   R   R   R   R   R  (    (   R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   $  s
    *	c            s+   t    |  }   f d   } | | _ | S(   Nc            s=   t  |  s- t d j d |  j j    n  |  j |    S(   NsA   Simple arithmetic with {name} can only be done with scalar valuesR%   (   R   R   RC   R   RD   t   _combine(   RP   RQ   (   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR  K  s    (   R   RD   (   R   R   R   R   R  (    (   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   G  s    	c            sg   t   |    t  |  }   f d     t d j d |   d    f d   } | | _ | S(   Nc            sa   d d  l  j j j } y | j    |  |  } Wn) t k
 r\ t |  |   t j  } n X| S(   Ni(	   R   R   R   R   R   RB   R   R3   R5   (   R   R   R   R   (   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRC  [  s    s$   Wrapper for comparison method {name}R%   c            s   | d  k	 r |  j |  n  t | |  j  r> |  j |    St | |  j t t f  rw t d j	 d |  j    n |  j
 |    Sd  S(   Ns0   input needs alignment for this object [{object}]R:  (   R*   RX  R!   R   t   _compare_constructorR  R   R   RE  RC   R  (   RP   RQ   R   (   RC  (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR  d  s    (   R   R   R   RC   R*   RD   (   R   R   R   R   R  (    (   RC  R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   W  s    		c            s   t   |    t  |   t     t          f d     t k ro t  d  } n t j d   } t |  d  f d   }  | _	 | S(   Nc            s|   d d  l  j j j } y% | j   |  | d d   } Wn  t k
 r\  |  |  } n Xt j | |  |    } | S(   Nit   errorst   raise(   R   R   R   R   R   RB   R@  RA  (   R   R   R   R   (   RB  RA  R   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRC  ~  s    R   R   i    c            s   |  j  |   d | S(   NR   (   R  (   RP   RQ   R   (   RC  (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    (
   R   R   Ra   Rh   R   R   t   _agg_doc_PANELRC   R   RD   (   R   R   R   R   R  (    (   RB  RA  RC  R   R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR   x  s    		c         C   s  d d l  m } | j d  } t |   r t |  r | d	 k r | j d k j   r |  j | t j |  j	   }  | j | t j | j	   } q | d
 k r |  j d k j   r |  j | t j |  j	   }  | j | t j | j	   } q n  |  | f S(   s  
    For SparseSeries operation, coerce to float64 if the result is expected
    to have NaN or inf values

    Parameters
    ----------
    left : SparseArray
    right : SparseArray
    opname : str

    Returns
    -------
    left : SparseArray
    right : SparseArray
    i(   t   SparseDtypeR   R   Rc   i    R>   RE   (   R   Rc   (   R>   RE   (
   t   pandas.core.sparse.apiR  Rd   R   RL  R   R9  R3   t   float64Rg   (   R&   R'   R   R  (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   _cast_sparse_series_op  s    !!!$c            s.   t    |      f d   }  | _ | S(   s[   
    Wrapper function for Series arithmetic operations, to avoid
    code duplication.
    c            s   t  | t  r t St  | t  r\ t  | t  sI | j d |  j  } n  t |  |     St |  r t	 j
 d d     |  j |  } Wd  QX|  j | d |  j d |  j St d j d t |     d  S(   NRg   R   R   R   R%   s$   operation with {other} not supportedRQ   (   R!   R   RJ  R   R   t	   to_sparseRg   t   _sparse_series_opR   R3   R   RL  R   R   R%   RB   RC   R/   (   RP   RQ   t
   new_values(   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRN    s    	
(   R   RD   (   R   R   R   RN  (    (   R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    	c   
      C   s   |  j  | d d d t \ }  } |  j } t |  |  } d d l m } t |  j | j |  \ } } | | | | |  }	 |  j |	 d | d | S(   NR\  R  R   i(   t   _sparse_array_opR   R%   (	   R;  R   R   R(   t   pandas.core.arrays.sparseR  R  RL  R   (
   R&   R'   R   R%   t	   new_indext   new_nameR  RH  RD  R   (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyR    s    !	c            s.   t    |      f d   }  | _ | S(   s[   
    Wrapper function for Series arithmetic operations, to avoid
    code duplication.
    c   	         sX  d d l  m } m } m } m } t | t j  r t |   t |  k ry t	 d j
 d t |   d t |     n  t | |  s t | d d   } | | d |  j d | } n  | |  |     St |  r6t j d d	  5   | |   t j |   }   |  j |  } Wd  QX|  | |  j |  St d
 j
 d t |     d  S(   Ni(   t   SparseArrayR  t   _wrap_resultt	   _get_fills#   length mismatch: {self} vs. {other}RP   RQ   R   Rg   R   R   s$   operation with {other} not supported(   t   pandas.core.arrays.sparse.arrayR  R  R  R  R!   R3   R5   R   R   RC   R{   R*   Rg   R   R   RY  t	   sp_valuest   sp_indexRB   R/   (	   RP   RQ   R  R  R  R  R   R{  R   (   R   R   (    s.   lib/python2.7/site-packages/pandas/core/ops.pyRN    s"    "!(   R   RD   (   R   R   R   RN  (    (   R   R   s.   lib/python2.7/site-packages/pandas/core/ops.pyR     s    	(   t   __doc__t
   __future__R    R0   RI   R]  R_  t   numpyR3   t   pandas._libsR   RF  R   R   RP  t   pandas.compatR@   R   t   pandas.errorsR   t   pandas.util._decoratorsR   t   pandas.core.dtypes.castR   R   R	   t   pandas.core.dtypes.commonR
   R   R   R   R   R   R   R   R   R   R   R   R   R   t   pandas.core.dtypes.genericR   R   R   R   R   R   R   t   pandas.core.dtypes.missingR   R    t   pandasR"   t   pandas.core.commonR   t   commonR   t   pandas.core.missingR@  R(   R$   R8   R9   R:   R;   R<   R=   R>   RE   RG   RH   RK   RM   RO   RS   Ra   Rh   Rn   R   R   R*   R   R   t   keyst	   _op_namest   keyR   t
   reverse_opR   R_   R   R  R   R  R   R  R   R   R   R   R   R   R   R   R   R  R  R  R1  R8  R=  R   R   R   RS  R   R   R   R  R  R   R   R   R   R   R   R  R   R  R   (    (    (    s.   lib/python2.7/site-packages/pandas/core/ops.pyt   <module>   s  ^4		#	*														)			4	













3	+	#	#	:	 	%@	"	"	;	=		5	
	e			P	)	9	5	)	#		!	'	!		