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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
U
¬ý°dkaã@sJdZddlmZddlmZmZmZmZmZm    Z    ddl
Z ddl
m Z ddl mZddlmZddlmZmZmZmZmZdd    lmZmZdd
lmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd l+m,Z,dd l-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3ddl4m5Z5ddl6m7m8Z9er<ddl:m;Z;m<Z<ddl=m>Z>dHdddddœdd„Z?e    dIdddddœdd„ƒZ@e    dJdddd dœd!d„ƒZ@dKdddd dœd#d„Z@d$d%„ZAd&d'd(œd)d*„ZBdLd"d+œd,d-dddd.œd/d0„ZCd1d'd2œd3d4„ZDd5d6œd7d8„ZEd"d+œdd-d,ddd9œd:d;„ZFd'd<dd'd=œd>d?„ZGdd,dd@œdAdB„ZHdCdDdddEœdFdG„ZIdS)MzŠ
Constructor functions intended to be shared by pd.array, Series.__init__,
and Index.__new__.
 
These should not depend on core.internals.
é)Ú annotations)Ú TYPE_CHECKINGÚOptionalÚSequenceÚUnionÚcastÚoverloadN)Úma)Úlib)ÚPeriod)Ú AnyArrayLikeÚ    ArrayLikeÚDtypeÚDtypeObjÚT)ÚExtensionDtypeÚ    _registry)Ú"construct_1d_arraylike_from_scalarÚ'construct_1d_object_array_from_listlikeÚmaybe_cast_to_datetimeÚmaybe_cast_to_integer_arrayÚmaybe_convert_platformÚmaybe_infer_to_datetimelikeÚ maybe_promote)Úis_datetime64_ns_dtypeÚis_dtype_equalÚis_extension_array_dtypeÚis_integer_dtypeÚ is_list_likeÚis_object_dtypeÚis_timedelta64_ns_dtype)Ú PandasDtype)Ú ABCDataFrameÚABCExtensionArrayÚABCIndexÚABCPandasArrayÚ ABCRangeIndexÚ    ABCSeries)Úisna)ÚIndexÚSeries)ÚExtensionArrayTzSequence[object] | AnyArrayLikez Dtype | NoneÚboolr+)ÚdataÚdtypeÚcopyÚreturncCspddlm}m}m}m}m}m}m}    m}
m    } ddl
m } t   |¡rXd|›d} t| ƒ‚nt|tƒrjtdƒ‚|dkrˆt|tt|fƒrˆ|j}t|dd    }t|tƒr¬t |¡pª|}t||ƒrÚ|dksÊt||jƒrÚ|rÖ| ¡S|St|ƒrtt|ƒ ¡}|j|||d
S|dkr,t j |dd }|d krLtt!t"t#t$t%f|ƒ}|
j||d S|dkrb|||d S| &d¡r˜z|j||d WStk
r”YnXn”| &d¡r²| j||d S|dkrÐ| ƒ ¡j||d S|dkrè|j||d S|dkrt'|ddƒt(j)kr|j||d S|dkr,|j||d St*|ƒrF|j|||d
St+|ƒr`| j|||d
S|    j|||d
S)a 
    Create an array.
 
    Parameters
    ----------
    data : Sequence of objects
        The scalars inside `data` should be instances of the
        scalar type for `dtype`. It's expected that `data`
        represents a 1-dimensional array of data.
 
        When `data` is an Index or Series, the underlying array
        will be extracted from `data`.
 
    dtype : str, np.dtype, or ExtensionDtype, optional
        The dtype to use for the array. This may be a NumPy
        dtype or an extension type registered with pandas using
        :meth:`pandas.api.extensions.register_extension_dtype`.
 
        If not specified, there are two possibilities:
 
        1. When `data` is a :class:`Series`, :class:`Index`, or
           :class:`ExtensionArray`, the `dtype` will be taken
           from the data.
        2. Otherwise, pandas will attempt to infer the `dtype`
           from the data.
 
        Note that when `data` is a NumPy array, ``data.dtype`` is
        *not* used for inferring the array type. This is because
        NumPy cannot represent all the types of data that can be
        held in extension arrays.
 
        Currently, pandas will infer an extension dtype for sequences of
 
        ============================== =======================================
        Scalar Type                    Array Type
        ============================== =======================================
        :class:`pandas.Interval`       :class:`pandas.arrays.IntervalArray`
        :class:`pandas.Period`         :class:`pandas.arrays.PeriodArray`
        :class:`datetime.datetime`     :class:`pandas.arrays.DatetimeArray`
        :class:`datetime.timedelta`    :class:`pandas.arrays.TimedeltaArray`
        :class:`int`                   :class:`pandas.arrays.IntegerArray`
        :class:`float`                 :class:`pandas.arrays.FloatingArray`
        :class:`str`                   :class:`pandas.arrays.StringArray` or
                                       :class:`pandas.arrays.ArrowStringArray`
        :class:`bool`                  :class:`pandas.arrays.BooleanArray`
        ============================== =======================================
 
        The ExtensionArray created when the scalar type is :class:`str` is determined by
        ``pd.options.mode.string_storage`` if the dtype is not explicitly given.
 
        For all other cases, NumPy's usual inference rules will be used.
 
        .. versionchanged:: 1.2.0
 
            Pandas now also infers nullable-floating dtype for float-like
            input data
 
    copy : bool, default True
        Whether to copy the data, even if not necessary. Depending
        on the type of `data`, creating the new array may require
        copying data, even if ``copy=False``.
 
    Returns
    -------
    ExtensionArray
        The newly created array.
 
    Raises
    ------
    ValueError
        When `data` is not 1-dimensional.
 
    See Also
    --------
    numpy.array : Construct a NumPy array.
    Series : Construct a pandas Series.
    Index : Construct a pandas Index.
    arrays.PandasArray : ExtensionArray wrapping a NumPy array.
    Series.array : Extract the array stored within a Series.
 
    Notes
    -----
    Omitting the `dtype` argument means pandas will attempt to infer the
    best array type from the values in the data. As new array types are
    added by pandas and 3rd party libraries, the "best" array type may
    change. We recommend specifying `dtype` to ensure that
 
    1. the correct array type for the data is returned
    2. the returned array type doesn't change as new extension types
       are added by pandas and third-party libraries
 
    Additionally, if the underlying memory representation of the returned
    array matters, we recommend specifying the `dtype` as a concrete object
    rather than a string alias or allowing it to be inferred. For example,
    a future version of pandas or a 3rd-party library may include a
    dedicated ExtensionArray for string data. In this event, the following
    would no longer return a :class:`arrays.PandasArray` backed by a NumPy
    array.
 
    >>> pd.array(['a', 'b'], dtype=str)
    <PandasArray>
    ['a', 'b']
    Length: 2, dtype: str32
 
    This would instead return the new ExtensionArray dedicated for string
    data. If you really need the new array to be backed by a  NumPy array,
    specify that in the dtype.
 
    >>> pd.array(['a', 'b'], dtype=np.dtype("<U1"))
    <PandasArray>
    ['a', 'b']
    Length: 2, dtype: str32
 
    Finally, Pandas has arrays that mostly overlap with NumPy
 
      * :class:`arrays.DatetimeArray`
      * :class:`arrays.TimedeltaArray`
 
    When data with a ``datetime64[ns]`` or ``timedelta64[ns]`` dtype is
    passed, pandas will always return a ``DatetimeArray`` or ``TimedeltaArray``
    rather than a ``PandasArray``. This is for symmetry with the case of
    timezone-aware data, which NumPy does not natively support.
 
    >>> pd.array(['2015', '2016'], dtype='datetime64[ns]')
    <DatetimeArray>
    ['2015-01-01 00:00:00', '2016-01-01 00:00:00']
    Length: 2, dtype: datetime64[ns]
 
    >>> pd.array(["1H", "2H"], dtype='timedelta64[ns]')
    <TimedeltaArray>
    ['0 days 01:00:00', '0 days 02:00:00']
    Length: 2, dtype: timedelta64[ns]
 
    Examples
    --------
    If a dtype is not specified, pandas will infer the best dtype from the values.
    See the description of `dtype` for the types pandas infers for.
 
    >>> pd.array([1, 2])
    <IntegerArray>
    [1, 2]
    Length: 2, dtype: Int64
 
    >>> pd.array([1, 2, np.nan])
    <IntegerArray>
    [1, 2, <NA>]
    Length: 3, dtype: Int64
 
    >>> pd.array([1.1, 2.2])
    <FloatingArray>
    [1.1, 2.2]
    Length: 2, dtype: Float64
 
    >>> pd.array(["a", None, "c"])
    <StringArray>
    ['a', <NA>, 'c']
    Length: 3, dtype: string
 
    >>> with pd.option_context("string_storage", "pyarrow"):
    ...     arr = pd.array(["a", None, "c"])
    ...
    >>> arr
    <ArrowStringArray>
    ['a', <NA>, 'c']
    Length: 3, dtype: string
 
    >>> pd.array([pd.Period('2000', freq="D"), pd.Period("2000", freq="D")])
    <PeriodArray>
    ['2000-01-01', '2000-01-01']
    Length: 2, dtype: period[D]
 
    You can use the string alias for `dtype`
 
    >>> pd.array(['a', 'b', 'a'], dtype='category')
    ['a', 'b', 'a']
    Categories (2, object): ['a', 'b']
 
    Or specify the actual dtype
 
    >>> pd.array(['a', 'b', 'a'],
    ...          dtype=pd.CategoricalDtype(['a', 'b', 'c'], ordered=True))
    ['a', 'b', 'a']
    Categories (3, object): ['a' < 'b' < 'c']
 
    If pandas does not infer a dedicated extension type a
    :class:`arrays.PandasArray` is returned.
 
    >>> pd.array([1 + 1j, 3 + 2j])
    <PandasArray>
    [(1+1j), (3+2j)]
    Length: 2, dtype: complex128
 
    As mentioned in the "Notes" section, new extension types may be added
    in the future (by pandas or 3rd party libraries), causing the return
    value to no longer be a :class:`arrays.PandasArray`. Specify the `dtype`
    as a NumPy dtype if you need to ensure there's no future change in
    behavior.
 
    >>> pd.array([1, 2], dtype=np.dtype("int32"))
    <PandasArray>
    [1, 2]
    Length: 2, dtype: int32
 
    `data` must be 1-dimensional. A ValueError is raised when the input
    has the wrong dimensionality.
 
    >>> pd.array(1)
    Traceback (most recent call last):
      ...
    ValueError: Cannot pass scalar '1' to 'pandas.array'.
    r)    Ú BooleanArrayÚ DatetimeArrayr+Ú FloatingArrayÚ IntegerArrayÚ IntervalArrayÚ PandasArrayÚ PeriodArrayÚTimedeltaArray)Ú StringDtypezCannot pass scalar 'z' to 'pandas.array'.z'Cannot pass DataFrame to 'pandas.array'NT)Ú extract_numpy©r.r/)ZskipnaZperiod©r/ÚintervalÚdatetimeÚ    timedeltaÚstringÚinteger)Zfloatingzmixed-integer-floatr.Úboolean),Úpandas.core.arraysr1r2r+r3r4r5r6r7r8Zpandas.core.arrays.string_r9r
Ú    is_scalarÚ
ValueErrorÚ
isinstancer"Ú    TypeErrorr'r$r.Ú extract_arrayÚstrÚregistryÚfindrr/rrrÚconstruct_array_typeÚ_from_sequenceZ infer_dtyperrrr r Ú
startswithÚgetattrÚnpÚfloat16rr )r-r.r/r1r2r+r3r4r5r6r7r8r9ÚmsgÚclsZinferred_dtypeZ period_data©rTúOd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/construction.pyÚarrayJslY, 
 
 
 
 
ÿ
ÿ
 
 
 
 
 
ÿþ
 
 
rV.zSeries | Indexr )Úobjr:Ú extract_ranger0cCsdS©NrT©rWr:rXrTrTrUrH~srHrz T | ArrayLikecCsdSrYrTrZrTrTrUrH…sFcCsFt|ttfƒr,t|tƒr&|r"|jS|S|jS|rBt|tƒrB| ¡S|S)a€
    Extract the ndarray or ExtensionArray from a Series or Index.
 
    For all other types, `obj` is just returned as is.
 
    Parameters
    ----------
    obj : object
        For Series / Index, the underlying ExtensionArray is unboxed.
 
    extract_numpy : bool, default False
        Whether to extract the ndarray from a PandasArray.
 
    extract_range : bool, default False
        If we have a RangeIndex, return range._values if True
        (which is a materialized integer ndarray), otherwise return unchanged.
 
    Returns
    -------
    arr : object
 
    Examples
    --------
    >>> extract_array(pd.Series(['a', 'b', 'c'], dtype='category'))
    ['a', 'b', 'c']
    Categories (3, object): ['a', 'b', 'c']
 
    Other objects like lists, arrays, and DataFrames are just passed through.
 
    >>> extract_array([1, 2, 3])
    [1, 2, 3]
 
    For an ndarray-backed Series / Index the ndarray is returned.
 
    >>> extract_array(pd.Series([1, 2, 3]))
    array([1, 2, 3])
 
    To extract all the way down to the ndarray, pass ``extract_numpy=True``.
 
    >>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True)
    array([1, 2, 3])
    )rFr$r'r&Z_valuesr%Zto_numpyrZrTrTrUrHŒs-
cCsTt|tjƒrP|jjdkr.ddlm}| |¡S|jjdkrPddlm}| |¡S|S)zS
    Wrap datetime64 and timedelta64 ndarrays in DatetimeArray/TimedeltaArray.
    ÚMr)r2Úm)r8)    rFrPÚndarrayr.ÚkindrCr2rMr8)Úarrr2r8rTrTrUÚensure_wrapped_if_datetimelikeÊs   
 
r`zma.MaskedArrayz
np.ndarray)r-r0cCs\t |¡}| ¡rPt|jtjƒ\}}ttj|ƒ}|j|dd}|     ¡|||<n| 
¡}|S)z?
    Convert numpy MaskedArray to ensure mask is softened.
    Tr<) r    Z getmaskarrayÚanyrr.rPÚnanrÚastypeZ soften_maskr/)r-Úmaskr.Z
fill_valuerTrTrUÚsanitize_masked_arrayÜs
 
re©Úallow_2dz Index | NonezDtypeObj | None)Úindexr.r/rgr0cCs\t|tjƒrt|ƒ}t|tƒr$|j}t|ddd}t|tjƒrb|j    dkrb|dkrV|j
}t   |¡}nt|t ƒrxt|ƒ}d}t|ƒs¤|dkrtdƒ‚t|t|ƒ|ƒ}|St|tƒrÜ|dk    rÆ|j||d}n|rÔ| ¡}n|}nBt|tƒr t|ƒ| ¡}|j|||d}nt|tjƒrxt|tjƒr.|j}|dkrj|}|j
tkrPt|ƒ}||krv|rv| ¡}n t|||ƒ}n¦t|d    ƒr¤tj ||d}t!|||d|d
St|ƒt"|ƒ}t|ƒdkrÞ|dkrÞtj gtj#d }n@|dk    röt|||ƒ}n(t$|ƒ}|j
tkrt%tj|ƒ}t|ƒ}t&|||||d }t|tjƒrXt%tj
|ƒ}t'||||ƒ}|S) a¸
    Sanitize input data to an ndarray or ExtensionArray, copy if specified,
    coerce to the dtype if specified.
 
    Parameters
    ----------
    data : Any
    index : Index or None, default None
    dtype : np.dtype, ExtensionDtype, or None, default None
    copy : bool, default False
    allow_2d : bool, default False
        If False, raise if we have a 2D Arraylike.
 
    Returns
    -------
    np.ndarray or ExtensionArray
    T)r:rXrNFz2index must be specified when data is not list-liker<r;Z    __array__)rhr.r/rg©r.rf)(rFr    Z MaskedArrayrer!Z numpy_dtyperHrPr]Úndimr.r
Zitem_from_zerodimÚrangeÚrange_to_ndarrayrrErÚlenr#rcr/rÚ_sanitize_non_orderedrLrMZmatrixÚAÚobjectrÚ    _try_castÚhasattrrVÚsanitize_arrayÚlistÚfloat64rrÚ_sanitize_ndimÚ_sanitize_str_dtypes)r-rhr.r/rgÚsubarrrSrTrTrUrsîsz 
 
 
 
 
 
 û    
   rsrk)Úrngr0c Cs²ztj|j|j|jdd}Wntk
r¬|jdkr@|jdks\|jdkrX|jkrœnn@ztj|j|j|jdd}Wq¨tk
r˜tt|ƒƒ}Yq¨Xn tt|ƒƒ}YnX|S)z)
    Cast a range object to ndarray.
    Úint64rirZuint64)rPZarangeÚstartÚstopÚstepÚ OverflowErrorrrt)ryr_rTrTrUrlis0rlÚNone)r0cCs(t|ttfƒr$tdt|ƒj›dƒ‚dS)z@
    Raise only for unordered sets, e.g., not for dict_keys
    ú'z' type is unorderedN)rFÚsetÚ    frozensetrGÚtypeÚ__name__)r-rTrTrUrn|srn)Úresultr.rhrgr0cCs®t|ddƒdkrtdƒ‚|jdkr.t||ƒ}n||jdkrªt|tjƒr^|rL|Std|j›dƒ‚t|ƒrœt|t    ƒrœt
j |t  d¡d}|  ¡}|j||d}nt
j ||d}|S)    z6
    Ensure we have a 1-dimensional result array.
    rjrz(result should be arraylike with ndim > 0éz1Data must be 1-dimensional, got ndarray of shape z insteadrpri)rOrErjÚ _maybe_repeatrFrPr]ÚshaperrÚcomZasarray_tuplesafer.rLrM)r…r-r.rhrgrSrTrTrUrv„s" 
 
  ÿrvznp.dtype | None)r…r.r/r0cCsJt|jjtƒrFt |¡sFt t|ƒ¡s6tj    ||dd}tj    |t
|d}|S)z=
    Ensure we have a dtype that is supported by pandas.
    Fr;) Ú
issubclassr.rƒrIr
rDrPÚallr(rVrp)r…r-r.r/rTrTrUrw«s     
rw)r_rhr0cCs:|dk    r6dt|ƒkr$t|ƒkr6nn| t|ƒ¡}|S)zx
    If we have a length-1 array and an index describing how long we expect
    the result to be, repeat the array.
    Nr†)rmÚrepeat)r_rhrTrTrUr‡¿s r‡zlist | np.ndarrayznp.dtype)r_r.r/r0cCsÆt|tjƒ}t|ƒr6|s$t|ƒ}|St|ƒj||dS|jdkrŠ|rjttj|ƒ}|j    }|j
dkrt|  ¡}n
t |ƒf}t j|d|d |¡S|jdkržt||ƒSt|ƒr²t||ƒ}ntj|||d}|S)aL
    Convert input to numpy ndarray and optionally cast to a given dtype.
 
    Parameters
    ----------
    arr : ndarray or list
        Excludes: ExtensionArray, Series, Index.
    dtype : np.dtype
    copy : bool
        If False, don't copy the data if not needed.
 
    Returns
    -------
    np.ndarray or ExtensionArray
    r<ÚUr†F)Zconvert_na_valuer/)r\r[r;)rFrPr]rrr`rcr^rrˆrjZravelrmr
Zensure_string_arrayZreshaperrrrV)r_r.r/Z
is_ndarrayrxrˆrTrTrUrqÊs, 
 
 
 
ÿ
 
 rq)NT)..)..)FF)NF)JÚ__doc__Ú
__future__rÚtypingrrrrrrÚnumpyrPr    Z pandas._libsr
Zpandas._libs.tslibs.periodr Zpandas._typingr r rrrZpandas.core.dtypes.baserrrJZpandas.core.dtypes.castrrrrrrrZpandas.core.dtypes.commonrrrrrrr Zpandas.core.dtypes.dtypesr!Zpandas.core.dtypes.genericr"r#r$r%r&r'Zpandas.core.dtypes.missingr(Zpandas.core.commonÚcoreÚcommonr‰Zpandasr)r*Zpandas.core.arrays.baser+rVrHr`rersrlrnrvrwr‡rqrTrTrTrUÚ<module>s^         $    $        ý6ÿÿÿ>üú{ú'