
     jN                        d Z ddlmZ ddlZddlZddlmZ ddlmZmZ ddl	Z
ddlmZmZmZ ddlmZ er
ddlmZmZmZ ddZddZddZdS )z4
Methods used by Block.replace and related methods.
    )annotationsN)Pattern)TYPE_CHECKINGAny)is_boolis_reis_re_compilable)isna)	ArrayLikeScalarnptregexbool
to_replacer   returnc                    t          |          rd} | ot          |          } | ot          j        |          j        dk    } | S )zG
    Decide whether to treat `to_replace` as a regular expression.
    T )r   r	   recompilepattern)r   r   s     sC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pandas/core/array_algos/replace.pyshould_use_regexr      sO     Z 2&z22E :bj,,4:EL    ar   bScalar | Patternmasknpt.NDArray[np.bool_]c                   t                    r| S dd}|rt          |          sfd}nt          j        fd	          }t	          | t          j                  r| |         }  ||           }t	          |t          j                  r?|=t          j        |j        t          j                  }t          j	        |||           |} |||            |S )a  
    Compare two array-like inputs of the same shape or two scalar values

    Calls operator.eq or re.search, depending on regex argument. If regex is
    True, perform an element-wise regex matching.

    Parameters
    ----------
    a : array-like
    b : scalar or regex pattern
    regex : bool
    mask : np.ndarray[bool]

    Returns
    -------
    mask : array-like of bool
    resultArrayLike | boolr   r   r   r   c           	     >   t          |           rt          |t          j                  rst	          |          j        t	          |          j        g}d|j         d|d<   t          dt          |d                    dt          |d                              dS dS )z
        Raises an error if the two arrays (a,b) cannot be compared.
        Otherwise, returns the comparison result as expected.
        zndarray(dtype=)r   zCannot compare types z and    N)	r   
isinstancenpndarraytype__name__dtype	TypeErrorrepr)r    r   r   
type_namess       r   _check_comparison_typesz8compare_or_regex_search.<locals>._check_comparison_typesD   s     6?? 	z!RZ88 	q''*DGG,<=J7QW777JqMWZ](;(;WW$zRS}BUBUWW  	 	 	 	r   c                .    t          j        |           S N)operatoreqxr   s    r   <lambda>z)compare_or_regex_search.<locals>.<lambda>V   s    x{1a(( r   c                    t          | t                    r>t          t          t          f          r"t          t	          j        |                     ndS )NF)r%   strr   r   r   searchr3   s    r   r5   z)compare_or_regex_search.<locals>.<lambda>Y   sJ    !S!!&0S'N&C&Cd29Q??+++ r   N)r*   )r    r!   r   r   r   r   )
r
   r   r&   	vectorizer%   r'   zerosshapebool_place)r   r   r   r   r.   opr    tmps    `      r   compare_or_regex_searchr@   -   s   ( Aww u      
(22 
((((\   
 
 !RZ   dGRUUF&"*%% $  htz222
dF###FAq)))Mr   valuesrx
re.Patternnpt.NDArray[np.bool_] | NoneNonec                    t                    st          t                    sfd}nfd}t          j        |t          j        g          }| ||           | dd<   dS  || |                   | |<   dS )z
    Parameters
    ----------
    values : ArrayLike
        Object dtype.
    rx : re.Pattern
    value : Any
    mask : np.ndarray[bool], optional

    Notes
    -----
    Alters values in-place.
    c                    t                    r.t          | t                    r                    |           n| S | S r0   )r   r%   r7   r8   srB   values    r   re_replacerz"replace_regex.<locals>.re_replacer   s@    Ryy Z3//  "		!?uua?r   c                |    t                    r+t          | t                    r                    |           S | S r0   )r   r%   r7   subrH   s    r   rK   z"replace_regex.<locals>.re_replacer   s;    Ryy Z3// vveQ'''r   )otypesN)r
   r%   r7   r&   r9   object_)rA   rB   rJ   r   rK   fs    ``   r   replace_regexrQ   o   s    & E{{ *UC00 	 	 	 	 	 	 		 	 	 	 	 	 	["*666A 'AfIIqqq			qtr   )r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   )rA   r   rB   rC   r   rD   r   rE   )__doc__
__future__r   r1   r   r   typingr   r   numpyr&   pandas.core.dtypes.commonr   r   r	   pandas.core.dtypes.missingr
   pandas._typingr   r   r   r   r@   rQ    r   r   <module>rZ      sD    # " " " " "  				             
             
 , + + + + +             ? ? ? ?D)' )' )' )' )' )'r   