zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
U
¬ý°daFã@sÌdZddlmZddlZddlmZddlZddlmZddl    Z
ddl m Z m Z mZmZmZddlmZmZmZmZmZmZddlmZmZdd    lmZmZdd
lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dd l'm(Z(m)Z)m*Z*dd l+m,Z,m-Z-dd l.m/Z/ddl0m1Z1ddl2m3Z3m4Z4ddl5m6Z6ddl7m8Z8dd„Z9ddœdd„Z:d1dddœdd„Z;dddœd d!„Z<dddd"œd#d$„Z=ddœd%d&„Z>dddd"œd'd(„Z?d)d*„Z@d+d,œd-d.„ZAejBe4jCejDe4jEejFe4jGhZHd/d0„ZIdS)2zY
Functions for arithmetic and comparison operations on NumPy arrays and
ExtensionArrays.
é)Ú annotationsN)Úpartial)ÚAny)ÚNaTÚ    TimedeltaÚ    TimestampÚlibÚops)Ú
BaseOffsetÚget_supported_resoÚget_unit_from_dtypeÚis_supported_unitÚ is_unitlessÚnpy_unit_to_abbrev)Ú    ArrayLikeÚShape)Ú'construct_1d_object_array_from_listlikeÚfind_common_type)Ú ensure_objectÚ is_bool_dtypeÚis_integer_dtypeÚ is_list_likeÚis_numeric_v_string_likeÚis_object_dtypeÚ    is_scalar)ÚABCExtensionArrayÚABCIndexÚ    ABCSeries)ÚisnaÚnotna)Ú expressions)Úensure_wrapped_if_datetimelike)ÚmissingÚ    roperator)Úshould_extension_dispatch)Úinvalid_comparisoncCs t|tƒrt|ƒ}t|tjttfƒr‚t|jƒs:|     tj
¡}t|ttfƒrN|j }|j |j krjt d|j |j ƒ‚t | ¡| ¡|¡}nt | ¡||¡}| |j ¡S)NzShapes must match)Ú
isinstanceÚlistrÚnpÚndarrayrrrÚdtypeÚastypeZobject_Z_valuesÚshapeÚ
ValueErrorÚlibopsZ vec_compareÚravelZscalar_compareÚreshape)ÚopÚxÚyÚresult©r5úPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/ops/array_ops.pyÚcomp_method_OBJECT_ARRAYCs
 
  r7z
np.ndarray©r2c    CsV| ¡}t|tjƒs tt|ƒƒ‚t|tjƒrªt|j|jgƒ}tj|j    |d}t
|ƒt
|ƒkrjt |j |j ƒ‚t |ƒ}| ¡}t |ƒ| ¡@}| ¡r¨|||||ƒ||<nŠt|ƒsÄtdt|ƒ›ƒ‚tj|j    |jd}t |ƒ}|tkrút |dkd|¡}n|tjkrt |dkd|¡}| ¡r4||||ƒ||<t ||tj¡| |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
    ©r*z1Cannot broadcast np.ndarray with operand of type éF)r/r&r(r)ÚAssertionErrorÚtyperr*ÚemptyÚsizeÚlenr-r,rÚanyrÚ    TypeErrorÚpowÚwherer#ÚrpowZputmaskÚnanr0)    r2r3r1Zxravr*r4ZymaskZyravÚmaskr5r5r6Ú_masked_arith_opVs6   ÿ 
 rGFÚbool)ÚleftÚis_cmpcCs–t|tƒr|}n ttj|ƒ}z|||ƒ}Wn:tk
rd|s^t|jƒsPt|ƒr^t|||ƒ}n‚YnX|r†t    |ƒsz|t
kr†t |||ƒSt   ||||¡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
    )r&Ústrrr ÚevaluaterArr*rGrÚNotImplementedr%r"Zdispatch_fill_zeros)rIÚrightr1rJÚfuncr4r5r5r6Ú_na_arithmetic_opŽs
  rPrr)rIrNcCsJt||ƒs"t|tttfƒs"|tkr.|||ƒ}nt|||ƒ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$r&rr
rrÚ_bool_arith_checkrP)rIrNr1Ú
res_valuesr5r5r6Ú arithmetic_op¿sÿþý   rS)rIrNÚreturncCs$t|ƒ}t|ƒ}t |¡}t|tƒr.t |¡}t|tjtfƒr^t    |ƒt    |ƒkr^t
d|j |j ƒ‚t ||ƒsŠt|t ttfƒs€|tkr–t|jƒs–|||ƒ}nŠt|ƒrÔt|ƒrÔ|tjkrÂtj|j td}ntj|j td}nLt||ƒrêt|||ƒSt|jƒst|tƒrt|||ƒ}nt|||dd}|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
    zLengths must match to comparer9T)rJ)r!rÚitem_from_zerodimr&r'r(Zasarrayr)rr?r-r,r$rr
rrrr*rrÚoperatorÚneZonesrHÚzerosrr%rKr7rP)rIrNr1ÚlvaluesÚrvaluesrRr5r5r6Ú comparison_opís<
 
 
ÿ
ÿÿþ 
 
 r[cCsz|||ƒ}Wnêtk
røt|tjƒrjt|jƒrBt|jƒrBt‚t|ƒ}t|ƒ}t     | 
¡| 
¡|¡}nŠt   |¡sxt‚t |ƒsˆt|ƒ}zt |||¡}WnXtttttfk
rò}z0t|ƒj}td|j›d|j›d|›dƒ|‚W5d}~XYnXYnX| |j¡S)NzCannot perform 'z' with a dtyped [z] array and scalar of type [ú])rAr&r(r)rr*r;rr.Z    vec_binopr/rrrrHZ scalar_binopr-ÚAttributeErrorÚ OverflowErrorÚNotImplementedErrorr<Ú__name__r0r,)r2r3r1r4ÚerrÚtypr5r5r6Ú na_logical_op-s6     û
ÿýrcc Cs¾dd„}ddd„}t|jƒ}t |¡}t|ƒr@t|dƒs@t|ƒ}t|ƒ}|}t||ƒrb|||ƒ}nXt    |t
j ƒrŒt|jƒ}    |    r€|n|||ƒ}n
t  |¡}    |r¢|    r¢|n|}
t |||ƒ}|
|ƒ}|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
    cSs|S)Nr5r8r5r5r6Ú<lambda>fózlogical_op.<locals>.<lambda>NcSsN|jjdkr.t|ƒ}| ¡r.| t¡}d||<|dks@t|jƒrJ| t¡}|S)N)ÚcÚfÚOF)r*Úkindrr@r+ÚobjectrrH)r2rIrFr5r5r6Ú    fill_boolhs 
 
zlogical_op.<locals>.fill_boolr*)N)rr*rrUrÚhasattrrr!r$r&r(r)Ú
is_integerrc) rIrNr1Zfill_intrkZis_self_int_dtyperYrZrRZis_other_int_dtypeZfillerr5r5r6Ú
logical_opVs$
 
 
 
 
 
 rncCstt|tƒr|S|j d¡ d¡}|dkr,|S|dkr@tt|dS|dkrTtt|dS|dkrhtt|dSt|ƒ‚dS)    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
    Ú_ÚrZarith_op>ÚleÚltrWÚgeÚgtÚeq)r1>ÚxorÚrandÚrxorÚorÚrorÚand>ÚaddÚtruedivÚdivmodÚfloordivÚmodÚsubrBÚmulN)    r&rr`ÚstripÚlstripr[rnrSr_)r1Úop_namer5r5r6Ú get_array_op˜s
 
r†r)r,cCsFt|ƒtjkrt|ƒSt|ƒtjkr,t|ƒSt|tjƒr´t|ƒr¬ddl    m
}t |j ƒrb|  d¡}n6tt|j ƒƒs˜t|j ƒ}tt|ƒƒ}|  d|›d¡}t ||¡}||ƒSt|ƒSt|tjƒrBt|ƒr:ddl    m}t |j ƒrî|  d¡}n8tt|j ƒƒs&t|j ƒ}tt|ƒƒ}|  d|›d¡}t ||¡}||ƒSt|ƒ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)Ú DatetimeArrayzdatetime64[ns]z datetime64[r\)ÚTimedeltaArrayztimedelta64[ns]z timedelta64[)r<ÚdatetimeÚ    timedeltarrr&r(Z
datetime64rZpandas.core.arraysr‡rr*r+r r rr Z broadcast_toZ timedelta64rˆ)Úobjr,r‡ÚunitZ closest_unitrNrˆr5r5r6Úmaybe_prepare_scalar_for_opÃs:  
 
 
 
 
  rcCsP|tkrLt|jƒrLt|ƒs*t|ttjfƒrL|j d¡     d¡}t
d|›dƒ‚dS)z`
    In contrast to numpy, pandas raises an error for certain operations
    with booleans.
    rorpz
operator 'z!' not implemented for bool dtypesN) Ú_BOOL_OP_NOT_ALLOWEDrr*r&rHr(Zbool_r`rƒr„r_)r1ÚaÚbr…r5r5r6rQs
ÿÿ
ÿrQ)F)JÚ__doc__Ú
__future__rr‰Ú    functoolsrrVÚtypingrÚnumpyr(Z pandas._libsrrrrr    r.Zpandas._libs.tslibsr
r r r rrZpandas._typingrrZpandas.core.dtypes.castrrZpandas.core.dtypes.commonrrrrrrrZpandas.core.dtypes.genericrrrZpandas.core.dtypes.missingrrZpandas.core.computationr Zpandas.core.constructionr!Zpandas.core.opsr"r#Zpandas.core.ops.dispatchr$Zpandas.core.ops.invalidr%r7rGrPrSr[rcrnr†rr}ZrtruedivrZ    rfloordivrBrDrŽrQr5r5r5r6Ú<module>sF    $        81.@)B+Hú