zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
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
U
¬ý°d*ã@sØddlmZddlmZddlZddlmZddlm    Z    m
Z
m Z ddl m Z ddlmZddlmZmZmZmZmZmZmZmZmZmZdd    lmZmZddlZdd
l m!Z!dd l"m#Z#d dej$fd dddœdd„Z%dS)é)Ú annotations)ÚLiteralN)Úlib)ÚDateTimeErrorChoicesÚ DtypeBackendÚnpt)Úcheck_dtype_backend)Úmaybe_downcast_numeric)
Ú ensure_objectÚ is_bool_dtypeÚis_datetime_or_timedelta_dtypeÚ
is_decimalÚis_integer_dtypeÚ    is_numberÚis_numeric_dtypeÚ    is_scalarÚis_string_dtypeÚneeds_i8_conversion)ÚABCIndexÚ    ABCSeries)ÚBaseMaskedArray)Ú StringDtypeÚraiserz:Literal[('integer', 'signed', 'unsigned', 'float')] | NonezDtypeBackend | lib.NoDefault)ÚerrorsÚdowncastÚ dtype_backendc    Cs2|dkrtdƒ‚|dkr tdƒ‚t|ƒd}d}d}t|tƒrJd}|j}n¢t|tƒrvd}t|jƒrn| d¡}qì|j}nvt|t    t
fƒr”t j |dd    }nXt |ƒrÎt|ƒr¬t|ƒSt|ƒr¸|Sd}t j |gdd    }nt|d
d ƒd krètd ƒ‚n|}|}d }    t|tƒr|j}    |j|    }t|dd ƒ}
t|
tjƒr@| ¡}    | ¡ ¡}d } t|
ƒrPn‚t|
ƒrh| t j¡}njt|ƒ}|dk} z.tj |t!ƒ| |tj"k    pšt|
t#ƒd\}} Wn*ttfk
rÐ|dkrȂ|}YnX| d k    rè|| }n4|tj"k    rþ| d ks
t|
t#ƒrt j$|j%t j&d    } |d k    rt|jƒrd } |dkrLt j'd} nh|dkr|t(|ƒrpt  )|¡dkr|t j'd} n8|dkr´t j'd} t  t j*¡j+}|  ,|¡}| |d …} | d k    r| D]<}t  |¡}|j-|jj-krÂt.||ƒ}|j|krqqÂ|    d k    s| d k    rìt/|jƒsì|    d ksB| d k    rH| j%|    j%krH| }    n|     0¡}    t|    t j1ƒsbt2‚t j$|    j%|jd    }|||    <ddl3m4}m5}m6}m7}t8|jƒr¨|}nt9|jƒrº|}n|}|||    ƒ}|dksàt|
tjƒrì|| :¡ƒ}|r|j;||j,|j<dS|rtj=||j<dS|r*|dS|Sd S)aÑ
    Convert argument to a numeric type.
 
    The default return dtype is `float64` or `int64`
    depending on the data supplied. Use the `downcast` parameter
    to obtain other dtypes.
 
    Please note that precision loss may occur if really large numbers
    are passed in. Due to the internal limitations of `ndarray`, if
    numbers smaller than `-9223372036854775808` (np.iinfo(np.int64).min)
    or larger than `18446744073709551615` (np.iinfo(np.uint64).max) are
    passed in, it is very likely they will be converted to float so that
    they can be stored in an `ndarray`. These warnings apply similarly to
    `Series` since it internally leverages `ndarray`.
 
    Parameters
    ----------
    arg : scalar, list, tuple, 1-d array, or Series
        Argument to be converted.
    errors : {'ignore', 'raise', 'coerce'}, default 'raise'
        - If 'raise', then invalid parsing will raise an exception.
        - If 'coerce', then invalid parsing will be set as NaN.
        - If 'ignore', then invalid parsing will return the input.
    downcast : str, default None
        Can be 'integer', 'signed', 'unsigned', or 'float'.
        If not None, and if the data has been successfully cast to a
        numerical dtype (or if the data was numeric to begin with),
        downcast that resulting data to the smallest numerical dtype
        possible according to the following rules:
 
        - 'integer' or 'signed': smallest signed int dtype (min.: np.int8)
        - 'unsigned': smallest unsigned int dtype (min.: np.uint8)
        - 'float': smallest float dtype (min.: np.float32)
 
        As this behaviour is separate from the core conversion to
        numeric values, any errors raised during the downcasting
        will be surfaced regardless of the value of the 'errors' input.
 
        In addition, downcasting will only occur if the size
        of the resulting data's dtype is strictly larger than
        the dtype it is to be cast to, so if none of the dtypes
        checked satisfy that specification, no downcasting will be
        performed on the data.
    dtype_backend : {"numpy_nullable", "pyarrow"}, defaults to NumPy backed DataFrames
        Which dtype_backend to use, e.g. whether a DataFrame should have NumPy
        arrays, nullable dtypes are used for all dtypes that have a nullable
        implementation when "numpy_nullable" is set, pyarrow is used for all
        dtypes if "pyarrow" is set.
 
        The dtype_backends are still experimential.
 
        .. versionadded:: 2.0
 
    Returns
    -------
    ret
        Numeric if parsing succeeded.
        Return type depends on input.  Series if Series, otherwise ndarray.
 
    See Also
    --------
    DataFrame.astype : Cast argument to a specified dtype.
    to_datetime : Convert argument to datetime.
    to_timedelta : Convert argument to timedelta.
    numpy.ndarray.astype : Cast a numpy array to a specified type.
    DataFrame.convert_dtypes : Convert dtypes.
 
    Examples
    --------
    Take separate series and convert to numeric, coercing when told to
 
    >>> s = pd.Series(['1.0', '2', -3])
    >>> pd.to_numeric(s)
    0    1.0
    1    2.0
    2   -3.0
    dtype: float64
    >>> pd.to_numeric(s, downcast='float')
    0    1.0
    1    2.0
    2   -3.0
    dtype: float32
    >>> pd.to_numeric(s, downcast='signed')
    0    1
    1    2
    2   -3
    dtype: int8
    >>> s = pd.Series(['apple', '1.0', '2', -3])
    >>> pd.to_numeric(s, errors='ignore')
    0    apple
    1      1.0
    2        2
    3       -3
    dtype: object
    >>> pd.to_numeric(s, errors='coerce')
    0    NaN
    1    1.0
    2    2.0
    3   -3.0
    dtype: float64
 
    Downcasting of nullable integer and floating dtypes is supported:
 
    >>> s = pd.Series([1, 2, 3], dtype="Int64")
    >>> pd.to_numeric(s, downcast="integer")
    0    1
    1    2
    2    3
    dtype: Int8
    >>> s = pd.Series([1.0, 2.1, 3.0], dtype="Float64")
    >>> pd.to_numeric(s, downcast="float")
    0    1.0
    1    2.1
    2    3.0
    dtype: Float32
    )NÚintegerÚsignedÚunsignedÚfloatz#invalid downcasting method provided)ÚignorerZcoercezinvalid error value specifiedFTÚi8ÚO)ÚdtypeÚndiméz/arg must be a list, tuple, 1-d array, or SeriesNr#)r r)Úcoerce_numericZconvert_to_masked_nullabler)rrZIntegerrrZUnsignedIntegerrZFloat)ÚArrowExtensionArrayÚ BooleanArrayÚ FloatingArrayÚ IntegerArrayZpyarrow)ÚindexÚname)r,)>Ú
ValueErrorrÚ
isinstancerÚvaluesrrr#ÚviewÚlistÚtupleÚnpÚarrayrr rrÚgetattrÚ    TypeErrorrZ_maskÚ_dataÚpdZ
ArrowDtypeZisnaZdropnaZto_numpyrr Úint64r
rZmaybe_convert_numericÚsetÚ
no_defaultrÚzerosÚshapeZbool_Ú    typecodesÚlenÚminÚfloat32Úcharr+Úitemsizer    rÚcopyZndarrayÚAssertionErrorÚpandas.core.arraysr'r(r)r*rr Z__arrow_array__Z _constructorr,ZIndex)ÚargrrrZ    is_seriesZis_indexZ
is_scalarsr/Z orig_valuesÚmaskZ values_dtypeZnew_maskr&r>Z float_32_charZ float_32_indÚtypecoder#Údatar'r(r)r*Úklass©rLúPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/tools/numeric.pyÚ
to_numeric&sÔz
 
 
 
 
 
 û
 
 
 ÿþý
 $ 
 
 
 
 
 
 
 "
 
 rN)&Ú
__future__rÚtypingrÚnumpyr3Z pandas._libsrZpandas._typingrrrZpandas.util._validatorsrZpandas.core.dtypes.castr    Zpandas.core.dtypes.commonr
r r r rrrrrrZpandas.core.dtypes.genericrrZpandasr8rFrZpandas.core.arrays.string_rr;rNrLrLrLrMÚ<module>s     0   ü