
     jJ                       d Z ddlmZ ddlZddlmZ ddlZddlmZm	Z	 ddl
Z
ddlZddlmZmZmZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZmZ dd
lmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 erddl8m9Z9m:Z: d Z;d Z<d,dZ=d-d.dZ>d/d!Z?d0d#Z@d,d$ZAd0d%ZBd& ZCd1d)ZDejE        e-jF        ejG        e-jH        ejI        e-jJ        hZKd2d+ZLdS )3zY
Functions for arithmetic and comparison operations on NumPy arrays and
ExtensionArrays.
    )annotationsN)partial)TYPE_CHECKINGAny)NaT	Timedelta	Timestamplibops)
BaseOffsetget_supported_dtypeis_supported_dtypeis_unitless)find_stack_level)'construct_1d_object_array_from_listlikefind_common_type)ensure_objectis_bool_dtypeis_list_likeis_numeric_v_string_likeis_object_dtype	is_scalar)ABCExtensionArrayABCIndex	ABCSeries)isnanotna)	roperator)expressions)ensure_wrapped_if_datetimelike)missing)should_extension_dispatch)invalid_comparison)	ArrayLikeShapec                   |t          |           }t          |          }||z  }|                                r|                                 } || ||z  <   |                                r|                                }||||z  <   | |fS )a  
    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 and NAs are present.
    )r   anycopy)leftright
fill_value	left_mask
right_maskmasks         mC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pandas/core/ops/array_ops.py
fill_binopr0   H   s    *  2JJ	%[[
 :%==?? 	099;;D%/DT!">> 	2JJLLE'1E*t#$;    c                   t          |t                    rt          |          }t          |t          j        t
          t          f          rt          |j                  s|	                    t          j
                  }t          |t
          t          f          r|j        }|j        |j        k    rt          d|j        |j                  t          j        |                                |                                |           }n(t          j        |                                ||           }|                    |j                  S )NzShapes must match)
isinstancelistr   npndarrayr   r   r   dtypeastypeobject__valuesshape
ValueErrorlibopsvec_compareravelscalar_comparereshape)opxyresults       r/   comp_method_OBJECT_ARRAYrF   q   s    !T 73A66!bj)X677 9qw'' 	%$$Aa)X.// 		A7ag 	D0!'17CCC#AGGIIqwwyy"==&qwwyy!R88>>!'"""r1   rC   
np.ndarrayc                J   |                                  }t          |t          j                  rt	          | j        |j        g          }t          j        | j        |          }t          |           t          |          k    rt          | j
        |j
                  t          |          }|                                 }t          |          |                                 z  }|                                r |||         ||                   ||<   nt          |          st          dt          |                     t          j        | j        | j                  }t          |          }|t           u rt          j        | dk    d|          }n(|t$          j        u rt          j        |dk    d|          }|                                r |||         |          ||<   t          j        || t          j                   |                    | j
                  }|S )z
    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
    r7   z1Cannot broadcast np.ndarray with operand of type    F)r?   r3   r5   r6   r   r7   emptysizelenr<   r;   r   r'   r   	TypeErrortypepowwherer   rpowputmasknanrA   )	rC   rD   rB   xravr7   rE   ymaskyravr.   s	            r/   _masked_arith_oprX      s    7799D!RZ   "- !'17!344!&...q66SVV 	/QWag...a wwyyT{{U[[]]* 88:: 	62d4j$t*55F4L || 	OT!WWOO  
 !&000T{{ 9 	18AFE400DD9>! 	18AFE400D88:: 	-2d4j!,,F4LJvubf%%%^^AG$$FMr1   Fr)   is_cmpboolc                   t          |t                    r|}nt          t          j        |          }	  || |          }nO# t
          $ rB |s<| j        t          k    st          |dd          t          k    rt          | ||          }n Y nw xY w|r)t          |          s	|t          u rt          | ||          S t          j        || ||          S )a  
    Return the result of evaluating op on the passed in values.

    If native types are not compatible, try coercion to object dtype.

    Parameters
    ----------
    left : np.ndarray
    right : np.ndarray or scalar
        Excludes DataFrame, Series, Index, ExtensionArray.
    is_cmp : bool, default False
        If this a comparison operation.

    Returns
    -------
    array-like

    Raises
    ------
    TypeError : invalid operation
    r7   N)r3   strr   r   evaluaterN   r7   objectgetattrrX   r   NotImplementedr#   r!   dispatch_fill_zeros)r)   r*   rB   rY   funcrE   s         r/   _na_arithmetic_oprc      s   , % 1{+R00dE"" 
 
 
 		J& 		$+E7D$A$AV$K		 &dE266FF F
  39V$$ 3.(@ 3 "$r222&r4???s   A A	BBr$   r*   r   c                    t          | |          s+t          |t          t          t          f          s	|t
          u r || |          }n"t          || |           t          | ||          }|S )aO  
    Evaluate an arithmetic operation `+`, `-`, `*`, `/`, `//`, `%`, `**`, ...

    Note: the caller is responsible for ensuring that numpy warnings are
    suppressed (with np.errstate(all="ignore")) if needed.

    Parameters
    ----------
    left : np.ndarray or ExtensionArray
    right : object
        Cannot be a DataFrame or Index.  Series is *not* excluded.
    op : {operator.add, operator.sub, ...}
        Or one of the reversed variants from roperator.

    Returns
    -------
    ndarray or ExtensionArray
        Or a 2-tuple of these in the case of divmod or rdivmod.
    )r"   r3   r   r   r	   r   _bool_arith_checkrc   )r)   r*   rB   
res_valuess       r/   arithmetic_oprg      s}    6 	"$..8eiY?@@8 C<8 Re__

 	"dE*** 'tUB77
r1   returnc                   t          |           }t          |          }t          j        |          }t          |t                    rt          j        |          }t          |t
          j        t          f          r;t          |          t          |          k    rt          d|j        |j                  t          ||          s;t          |t          t          t          f          s	|t           u r|j        t$          k    r |||          }nt'          |          r_t)          |          rP|t*          j        u r!t          j        |j        t0                    }nt          j        |j        t0                    }nkt5          ||          rt7          |||          S |j        t$          k    st          |t8                    rt;          |||          }nt=          |||d          }|S )a  
    Evaluate a comparison operation `=`, `!=`, `>=`, `>`, `<=`, or `<`.

    Note: the caller is responsible for ensuring that numpy warnings are
    suppressed (with np.errstate(all="ignore")) if needed.

    Parameters
    ----------
    left : np.ndarray or ExtensionArray
    right : object
        Cannot be a DataFrame, Series, or Index.
    op : {operator.eq, operator.ne, operator.gt, operator.ge, operator.lt, operator.le}

    Returns
    -------
    ndarray or ExtensionArray
    zLengths must match to comparerI   T)rY   )r    r
   item_from_zerodimr3   r4   r5   asarrayr6   r   rM   r<   r;   r"   r   r   r	   r   r7   r^   r   r   operatorneonesrZ   zerosr   r#   r\   rF   rc   )r)   r*   rB   lvaluesrvaluesrf   s         r/   comparison_oprr      s   & -T22G,U33G#G,,G'4   & *W%%'BJ(9:;;  w<<3w<<' 	/   !'22 J	GiY?	@	@JDISLJMV#J
 R))

	7		 JW J 	=d;;;JJ'-t<<<JJ	!'7	3	3 J!'7B777	&	  JJw$<$< J-b'7CC

 'wDIII
r1   c                   	  || |          }nU# t           $ rG t          |t          j                  r{| j        j        dk    r|j        j        dk    rJ t          |           } t          |          }t          j        | 	                                |	                                |          }nt          j        |          sJ t          |          st          |          }	 t          j        | ||          }nc# t           t          t           t"          t$          f$ r=}t'          |          j        }t          d|j         d| j         d| d          |d }~ww xY wY nw xY w|                    | j                  S )NbzCannot perform 'z' with a dtyped [z] array and scalar of type [])rN   r3   r5   r6   r7   kindr   r=   	vec_binopr?   r
   r   r   rZ   scalar_binopr<   AttributeErrorOverflowErrorNotImplementedErrorrO   __name__rA   r;   )rC   rD   rB   rE   errtyps         r/   na_logical_opr   `  s   # Aq   a$$ 	+D0CDDDa  Aa  A%aggiiB??FF =#####77 GG,Q266#    1gg&2r{ 2 2QW 2 2+.2 2 2  6 >>!'"""s4    CE"%C<;E"<#E8EEE"!E"c                ,   dd}t          j        |          }t          |          rGt          |d          s7t	          j        dt          t                                 t          |          }t          |           }|}t          ||          r |||          }nwt          |t          j                  r|j        j        dv }|s |||          }nt          j        |          }t#          |||          }| j        j        dv r|s ||          }|S )ag  
    Evaluate a logical operation `|`, `&`, or `^`.

    Parameters
    ----------
    left : np.ndarray or ExtensionArray
    right : object
        Cannot be a DataFrame, Series, or Index.
    op : {operator.and_, operator.or_, operator.xor}
        Or one of the reversed variants from roperator.

    Returns
    -------
    ndarray or ExtensionArray
    Nc                    | j         j        dv rBt          |           }|                                r|                     t
                    } d| |<   ||j         j        dk    r|                     t                    } | S )NcfOFrt   )r7   rv   r   r'   r8   r^   rZ   )rC   r)   r.   s      r/   	fill_boolzlogical_op.<locals>.fill_bool  st    7<5  	 77Dxxzz  HHV$$$ 	4:?c1 	Ar1   r7   zLogical ops (and, or, xor) between Pandas objects and dtype-less sequences (e.g. list, tuple) are deprecated and will raise in a future version. Wrap the object in a Series, Index, or np.array before operating instead.)
stackleveliu)N)r
   rj   r   hasattrwarningswarnFutureWarningr   r   r    r"   r3   r5   r6   r7   rv   
is_integerr   )r)   r*   rB   r   rp   rq   rf   is_other_int_dtypes           r/   
logical_opr     sP   "    !%((EE 
?75'#:#: 
?( '))	
 	
 	
 	
 8>> -T22GG '22 /R))

 grz** 	9!(!3t!;% 6#)GW55 "%!8!8"7GR88
 
4' 	/,> 	/":..Jr1   c                T   t          | t                    r| S | j                            d                              d          }|dk    r| S |dv rt          t
          |           S |dv rt          t          |           S |dv rt          t          |           S t          |          )z
    Return a binary array operation corresponding to the given operator op.

    Parameters
    ----------
    op : function
        Binary operator from operator or roperator module.

    Returns
    -------
    functools.partial
    _rarith_op>   eqgegtleltrm   )rB   >   orandrorxorrandrxor>   addmodmulrP   subdivmodtruedivfloordiv)	r3   r   r|   striplstriprr   r   rg   r{   )rB   op_names     r/   get_array_opr     s     "g  	k$$++C00G*  	66 +},,,,	?	? +zb))))	 	 	
 + },,,,!'***r1   r;   r%   c                   t          |           t          j        u rt          |           S t          |           t          j        u rt	          |           S t          | t          j                  rt          |           rddl	m
} t          | j                  r|                     d          } n=t          | j                  s)t          | j                  }|                     |          } t          j        | |          }|                    ||j                  S t	          |           S t          | t          j                  rt          |           rddl	m} t          | j                  r|                     d          } n=t          | j                  s)t          | j                  }|                     |          } t          j        | |          }|                    ||j                  S t          |           S t          | t          j                  rt+          |           S t          | t          j                  rt/          |           S | S )ax  
    Cast non-pandas objects to pandas types to unify behavior of arithmetic
    and comparison operations.

    Parameters
    ----------
    obj: object
    shape : tuple[int]

    Returns
    -------
    out : object

    Notes
    -----
    Be careful to call this *after* determining the `name` attribute to be
    attached to the result of the arithmetic operation.
    r   )DatetimeArrayzdatetime64[ns]rI   )TimedeltaArrayztimedelta64[ns])rO   datetime	timedeltar   r	   r3   r5   
datetime64r   pandas.core.arraysr   r   r7   r8   r   r   broadcast_to_simple_newtimedelta64r   integerintfloatingfloat)objr;   r   	new_dtyper*   r   s         r/   maybe_prepare_scalar_for_opr     s"   & CyyH&& 5 ~~	ch'	' 0~~	C	'	' - 99 	G888888 39%% ,jj!122'	22 ,/	::	jj++OC//E ,,U%+,FFF~~	C	(	( 99 	H999999 39%% ,jj!233'	22 ,/	::	jj++OC//E!--e5;-GGG
 ~~ 
C	$	$ 3xx	C	%	% SzzJr1   ac                   | t           v rs|j        j        dk    ret          |          st	          j        |          rD| j                            d                              d          }t          d| d          dS dS dS )z`
    In contrast to numpy, pandas raises an error for certain operations
    with booleans.
    rt   r   r   z
operator 'z!' not implemented for bool dtypesN)
_BOOL_OP_NOT_ALLOWEDr7   rv   r   r
   is_boolr|   r   r   r{   )rB   r   rt   r   s       r/   re   re   R  s    
 
!! 7<3 	M!$4$4 	A 	k'',,33C88G%GWGGG   	 	 	 	r1   )rC   rG   )F)r)   rG   rY   rZ   )r)   r$   r*   r   )r)   r$   r*   r   rh   r$   )r;   r%   )r   rG   )M__doc__
__future__r   r   	functoolsr   rl   typingr   r   r   numpyr5   pandas._libsr   r   r	   r
   r   r=   pandas._libs.tslibsr   r   r   r   pandas.util._exceptionsr   pandas.core.dtypes.castr   r   pandas.core.dtypes.commonr   r   r   r   r   r   pandas.core.dtypes.genericr   r   r   pandas.core.dtypes.missingr   r   pandas.corer   pandas.core.computationr   pandas.core.constructionr    pandas.core.opsr!   pandas.core.ops.dispatchr"   pandas.core.ops.invalidr#   pandas._typingr$   r%   r0   rF   rX   rc   rg   rr   r   r   r   r   r   rtruedivr   	rfloordivrP   rR   r   re    r1   r/   <module>r      s    # " " " " "                                             5 4 4 4 4 4                               
       
 " ! ! ! ! ! / / / / / / C C C C C C # # # # # # > > > > > > 6 6 6 6 6 6        & & &R# # #(5 5 5 5p0@ 0@ 0@ 0@ 0@f- - - -`= = = =@&# &# &# &#RD D D DN(+ (+ (+VJ J J J\ LN 
 
 
 
 
 
r1   