zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
U
¬ý°d¥ã@s¬dZddlmZddlZddlZddlmZmZddlZ    ddl
m Z m Z m Z ddlmZmZmZddlmZdd    dd
œd d „Zd dddd dœdd„Zd ddddœdd„ZdS)z4
Methods used by Block.replace and related methods.
é)Ú annotationsN)ÚAnyÚPattern)Ú    ArrayLikeÚScalarÚnpt)Úis_reÚis_re_compilableÚ    is_scalar)ÚisnaÚboolr)ÚregexÚ
to_replaceÚreturncCs0t|ƒr d}|ot|ƒ}|o*t |¡jdk}|S)zG
    Decide whether to treat `to_replace` as a regular expression.
    TÚ)rr    ÚreÚcompileÚpattern)r r©rúVd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/array_algos/replace.pyÚshould_use_regexs
 rrúScalar | Patternznpt.NDArray[np.bool_])ÚaÚbr Úmaskrcs²tˆƒr|Sddddœdd„}|r.t|ˆƒs<‡fdd„}nt ‡fd    d„¡}t|tjƒrb||}||ƒ}t|tjƒr¢|d
k    r¢tj|jtjd }t     |||¡|}|||ˆƒ|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
    zArrayLike | boolrr)ÚresultrrcSsbt|ƒr^t|tjƒr^t|ƒjt|ƒjg}d|j›d|d<tdt|dƒ›dt|dƒ›ƒ‚dS)z‹
        Raises an error if the two arrays (a,b) cannot be compared.
        Otherwise, returns the comparison result as expected.
        zndarray(dtype=ú)rzCannot compare types z and éN)    r
Ú
isinstanceÚnpÚndarrayÚtypeÚ__name__ÚdtypeÚ    TypeErrorÚrepr)rrrÚ
type_namesrrrÚ_check_comparison_typesBs ÿz8compare_or_regex_search.<locals>._check_comparison_typescs t |ˆ¡S©N)ÚoperatorÚeq©Úx©rrrÚ<lambda>Tóz)compare_or_regex_search.<locals>.<lambda>cs,t|tƒr(tˆttfƒr(tt ˆ|¡ƒSdS)NF)rÚstrrr rÚsearchr+r-rrr.Ws
ÿ ÿN)r#)
r rrÚ    vectorizerr ÚzerosÚshapeZbool_Zplace)rrr rr'ÚoprÚtmprr-rÚcompare_or_regex_search+s"
ÿ  r7z
re.Patternznpt.NDArray[np.bool_] | NoneÚNone)ÚvaluesÚrxrrcsptˆƒstˆtƒs"‡‡fdd„}n‡‡fdd„}tj|tjgd}|dkr\||ƒ|dd…<n|||ƒ||<dS)zË
    Parameters
    ----------
    values : ArrayLike
        Object dtype.
    rx : re.Pattern
    value : Any
    mask : np.ndarray[bool], optional
 
    Notes
    -----
    Alters values in-place.
    cs0tˆƒr(t|tƒr(ˆ |¡dk    r$ˆS|S|SdSr()rrr0r1©Ús©r:ÚvaluerrÚ re_replacer‚sz"replace_regex.<locals>.re_replacercs&tˆƒrt|tƒrˆ ˆ|¡S|SdSr()rrr0Úsubr;r=rrr?‹s )ZotypesN)r rr0rr2Zobject_)r9r:r>rr?Úfrr=rÚ replace_regexms    rB)Ú__doc__Ú
__future__rr)rÚtypingrrÚnumpyrZpandas._typingrrrZpandas.core.dtypes.commonrr    r
Zpandas.core.dtypes.missingr rr7rBrrrrÚ<module>s  B