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
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
U
¬ý°dAeã @sŽdZddlmZddlmZddlmZmZmZm    Z    m
Z
m Z m Z m Z ddlZddlmZddlmZmZmZddlmZdd    lmZdd
lmZmZdd lmZdd lm Z dd l!m"Z"m#Z#ddl$m%m&Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1er ddl2m3Z3m4Z4ddl5m6Z6e ddddddddddœ    dddddddddœdd„ƒZ7e ddddddddddœ    dddddddddœdd„ƒZ7e ddddddddddœ    d ddddddd!dœd"d„ƒZ7e ddddddddd#œd d$dddddddœd%d„ƒZ7e ddddddddddœ    d d&dddddd!dœd'd„ƒZ7dd(d)dddd)d)ddœ    d d&dddddd!dœd*d„Z7Gd+d,„d,ƒZ8d-d.œd/d0„Z9d4d1d.œd2d3„Z:dS)5z
Concat routines.
é)Ú annotations)Úabc)Ú TYPE_CHECKINGÚCallableÚHashableÚIterableÚLiteralÚMappingÚcastÚoverloadN)Úusing_copy_on_write)ÚAxisÚAxisIntÚ    HashableT)Úcache_readonly)Ú concat_compat)Ú ABCDataFrameÚ    ABCSeries)Úis_bool)Úisna)Úfactorize_from_iterableÚfactorize_from_iterables)ÚIndexÚ
MultiIndexÚall_indexes_sameÚ default_indexÚ ensure_indexÚget_objs_combined_axisÚget_unanimous_names)Úconcatenate_managers)Ú    DataFrameÚSeries)ÚNDFrame.)    ÚaxisÚjoinÚ ignore_indexÚkeysÚlevelsÚnamesÚverify_integrityÚsortÚcopyz3Iterable[DataFrame] | Mapping[HashableT, DataFrame]zLiteral[(0, 'index')]ÚstrÚboolz bool | Noner )Úobjsr#r$r%r)r*r+Úreturnc    
CsdS©N©©
r.r#r$r%r&r'r(r)r*r+r1r1úQd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/reshape/concat.pyÚconcat@sr4z-Iterable[Series] | Mapping[HashableT, Series]r!c    
CsdSr0r1r2r1r1r3r4Qsú/Iterable[NDFrame] | Mapping[HashableT, NDFrame]úDataFrame | Seriesc    
CsdSr0r1r2r1r1r3r4bs)r$r%r&r'r(r)r*r+zLiteral[(1, 'columns')]c    
CsdSr0r1r2r1r1r3r4ssr c    
CsdSr0r1r2r1r1r3r4„sÚouterFc     CsL|    dkrtƒrd}    q(d}    n|    r(tƒr(d}    t|||||||||    |d
}
|
 ¡S)a‘
    Concatenate pandas objects along a particular axis.
 
    Allows optional set logic along the other axes.
 
    Can also add a layer of hierarchical indexing on the concatenation axis,
    which may be useful if the labels are the same (or overlapping) on
    the passed axis number.
 
    Parameters
    ----------
    objs : a sequence or mapping of Series or DataFrame objects
        If a mapping is passed, the sorted keys will be used as the `keys`
        argument, unless it is passed, in which case the values will be
        selected (see below). Any None objects will be dropped silently unless
        they are all None in which case a ValueError will be raised.
    axis : {0/'index', 1/'columns'}, default 0
        The axis to concatenate along.
    join : {'inner', 'outer'}, default 'outer'
        How to handle indexes on other axis (or axes).
    ignore_index : bool, default False
        If True, do not use the index values along the concatenation axis. The
        resulting axis will be labeled 0, ..., n - 1. This is useful if you are
        concatenating objects where the concatenation axis does not have
        meaningful indexing information. Note the index values on the other
        axes are still respected in the join.
    keys : sequence, default None
        If multiple levels passed, should contain tuples. Construct
        hierarchical index using the passed keys as the outermost level.
    levels : list of sequences, default None
        Specific levels (unique values) to use for constructing a
        MultiIndex. Otherwise they will be inferred from the keys.
    names : list, default None
        Names for the levels in the resulting hierarchical index.
    verify_integrity : bool, default False
        Check whether the new concatenated axis contains duplicates. This can
        be very expensive relative to the actual data concatenation.
    sort : bool, default False
        Sort non-concatenation axis if it is not already aligned.
 
    copy : bool, default True
        If False, do not copy data unnecessarily.
 
    Returns
    -------
    object, type of objs
        When concatenating all ``Series`` along the index (axis=0), a
        ``Series`` is returned. When ``objs`` contains at least one
        ``DataFrame``, a ``DataFrame`` is returned. When concatenating along
        the columns (axis=1), a ``DataFrame`` is returned.
 
    See Also
    --------
    DataFrame.join : Join DataFrames using indexes.
    DataFrame.merge : Merge DataFrames by indexes or columns.
 
    Notes
    -----
    The keys, levels, and names arguments are all optional.
 
    A walkthrough of how this method fits in with other tools for combining
    pandas objects can be found `here
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html>`__.
 
    It is not recommended to build DataFrames by adding single rows in a
    for loop. Build a list of rows and make a DataFrame in a single concat.
 
    Examples
    --------
    Combine two ``Series``.
 
    >>> s1 = pd.Series(['a', 'b'])
    >>> s2 = pd.Series(['c', 'd'])
    >>> pd.concat([s1, s2])
    0    a
    1    b
    0    c
    1    d
    dtype: object
 
    Clear the existing index and reset it in the result
    by setting the ``ignore_index`` option to ``True``.
 
    >>> pd.concat([s1, s2], ignore_index=True)
    0    a
    1    b
    2    c
    3    d
    dtype: object
 
    Add a hierarchical index at the outermost level of
    the data with the ``keys`` option.
 
    >>> pd.concat([s1, s2], keys=['s1', 's2'])
    s1  0    a
        1    b
    s2  0    c
        1    d
    dtype: object
 
    Label the index keys you create with the ``names`` option.
 
    >>> pd.concat([s1, s2], keys=['s1', 's2'],
    ...           names=['Series name', 'Row ID'])
    Series name  Row ID
    s1           0         a
                 1         b
    s2           0         c
                 1         d
    dtype: object
 
    Combine two ``DataFrame`` objects with identical columns.
 
    >>> df1 = pd.DataFrame([['a', 1], ['b', 2]],
    ...                    columns=['letter', 'number'])
    >>> df1
      letter  number
    0      a       1
    1      b       2
    >>> df2 = pd.DataFrame([['c', 3], ['d', 4]],
    ...                    columns=['letter', 'number'])
    >>> df2
      letter  number
    0      c       3
    1      d       4
    >>> pd.concat([df1, df2])
      letter  number
    0      a       1
    1      b       2
    0      c       3
    1      d       4
 
    Combine ``DataFrame`` objects with overlapping columns
    and return everything. Columns outside the intersection will
    be filled with ``NaN`` values.
 
    >>> df3 = pd.DataFrame([['c', 3, 'cat'], ['d', 4, 'dog']],
    ...                    columns=['letter', 'number', 'animal'])
    >>> df3
      letter  number animal
    0      c       3    cat
    1      d       4    dog
    >>> pd.concat([df1, df3], sort=False)
      letter  number animal
    0      a       1    NaN
    1      b       2    NaN
    0      c       3    cat
    1      d       4    dog
 
    Combine ``DataFrame`` objects with overlapping columns
    and return only those that are shared by passing ``inner`` to
    the ``join`` keyword argument.
 
    >>> pd.concat([df1, df3], join="inner")
      letter  number
    0      a       1
    1      b       2
    0      c       3
    1      d       4
 
    Combine ``DataFrame`` objects horizontally along the x axis by
    passing in ``axis=1``.
 
    >>> df4 = pd.DataFrame([['bird', 'polly'], ['monkey', 'george']],
    ...                    columns=['animal', 'name'])
    >>> pd.concat([df1, df4], axis=1)
      letter  number  animal    name
    0      a       1    bird   polly
    1      b       2  monkey  george
 
    Prevent the result from including duplicate index values with the
    ``verify_integrity`` option.
 
    >>> df5 = pd.DataFrame([1], index=['a'])
    >>> df5
       0
    a  1
    >>> df6 = pd.DataFrame([2], index=['a'])
    >>> df6
       0
    a  2
    >>> pd.concat([df5, df6], verify_integrity=True)
    Traceback (most recent call last):
        ...
    ValueError: Indexes have overlapping values: ['a']
 
    Append a single row to the end of a ``DataFrame`` object.
 
    >>> df7 = pd.DataFrame({'a': 1, 'b': 2}, index=[0])
    >>> df7
        a   b
    0   1   2
    >>> new_row = pd.Series({'a': 3, 'b': 4})
    >>> new_row
    a    3
    b    4
    dtype: int64
    >>> pd.concat([df7, new_row.to_frame().T], ignore_index=True)
        a   b
    0   1   2
    1   3   4
    NFT)    r#r%r$r&r'r(r)r+r*)r Ú _ConcatenatorÚ
get_result) r.r#r$r%r&r'r(r)r*r+Úopr1r1r3r4•s(X
ö c
@s‚eZdZdZd"ddd    d
d
d
d
d d œd d„Zdd„Zddœdd„Zddœdd„Zdddœdd„Ze    ddœdd„ƒZ
ddœd d!„Z dS)#r8zB
    Orchestrates a concatenation operation for BlockManagers
    rr7NFTr5r r,r-ÚNone)r.r#r$r%r)r+r*r/c stˆtttfƒr&tdtˆƒj›dƒ‚|dkr6d|_n|dkrFd|_ntdƒ‚tˆt    j
ƒr‚|dkrnt ˆ  ¡ƒ}‡fdd    „|Dƒ‰nt ˆƒ‰t ˆƒd
kržtd ƒ‚|dkr¶t tjˆŽƒ‰nxg} g} t|ˆƒD]&\} }|dkrÚqÈ|  | ¡|  |¡qÈ| ‰t|tƒrt|ƒj| |jd }nt|d dƒ}t| |d}t ˆƒd
krDtdƒ‚tƒ}ˆD]:}t|ttfƒszdt|ƒ›d}t|ƒ‚| |j¡qNd}t |ƒdkrÖt|ƒ}ˆD]*}|j|kr¨t |j¡r¨|}q q¨nJdd    „ˆDƒ}t |ƒr |dkr |dkr |dkr |js |‰ˆd
}|dkr2ˆd
}ˆ|_t|tƒr\d
dlm }| !|¡}n
| !|¡}t|tƒ|_"|j"r„| #|¡}t|tƒ|_$d
|krª|jksÂnt%d|j›d|›ƒ‚t |ƒdkr„d
}|j}g|j|_‰ˆD]–}|j}||krnr||dkrtdƒ‚nZt|d dƒ}|s6|dkrB|}|d7}|j"rX|dkrXd
}t&d|ƒ}|j'||idd}|j |¡qì||_(|j"rœd|j(nd
|_)||_ |p¸t|ddƒ|_||_*t+|
ƒsÜtd|
›dƒ‚|
|_,||_-||_.|    |_/| 0¡|_1dS)NzTfirst argument must be an iterable of pandas objects, you passed an object of type "ú"r7FÚinnerTz?Only can inner (intersect) or outer (union) join the other axiscsg|] }ˆ|‘qSr1r1)Ú.0Úk©r.r1r3Ú
<listcomp>¨sz*_Concatenator.__init__.<locals>.<listcomp>rzNo objects to concatenate)r(Úname)rBzAll objects passed were Nonez#cannot concatenate object of type 'z+'; only Series and DataFrame objs are validécSs(g|] }t|jƒdks t|tƒr|‘qS)r)ÚsumÚshapeÚ
isinstancer)r>Úobjr1r1r3rAàs
)r zaxis must be between 0 and z , input was z>cannot concatenate unaligned mixed dimensional NDFrame objectsr6)r+r(z0The 'sort' keyword only accepts boolean values; z  was passed.)2rFrrr,Ú    TypeErrorÚtypeÚ__name__Ú    intersectÚ
ValueErrorrr    Úlistr&ÚlenÚcomZnot_noneÚzipÚappendrÚ from_tuplesr(ÚgetattrrÚsetÚaddÚndimÚmaxÚnprDrEr.Úpandasr Z_get_axis_numberZ    _is_frameÚ_get_block_manager_axisÚ
_is_seriesÚAssertionErrorr
Ú _constructorÚbm_axisr#r'rr*r%r)r+Ú _get_new_axesÚnew_axes)Úselfr.r#r$r&r'r(r%r)r+r*Z
clean_keysZ
clean_objsr?ÚvrBZndimsrGÚmsgÚsampleZmax_ndimZ non_emptiesr Zcurrent_columnrVr1r@r3Ú__init__‰sà ÿÿ   
    ÿ ÿ
ÿÿÿÿ
 
 
 ÿ
ÿ 
 
 
ÿz_Concatenator.__init__cCsŠ|jrÄtd|jdƒ}|jdkrtt |j¡}|j}dd„|jDƒ}t|dd}|||jd||j    d}|j
|ddSt t t t|jƒƒ|jƒƒ}|j}|j\}}    ||||jd    }
|    |
_|
j
|ddSnÂtd
|jdƒ}g} |jD]`} i} t|jƒD]<\}}||jkrqð| jd |}| |¡sð| |¡| |<qð|  | j| f¡qÞt| |j|j|jd }|jsntƒsn| ¡|j}||ƒj
|ddSdS) Nr!rcSsg|]
}|j‘qSr1)Z_values)r>Zserr1r1r3rABsz,_Concatenator.get_result.<locals>.<listcomp>)r#)ÚindexrBÚdtyper4)Úmethod)rfr+r rC)Ú concat_axisr+)r[r
r.r^rOZconsensus_name_attrr]rr`rgZ __finalize__ÚdictrPÚrangerNZ_constructor_expanddimr+ÚcolumnsÚ    enumerateÚaxesÚequalsÚ get_indexerrQZ_mgrrr Z_consolidate_inplace)rardrBZconsZarrsÚresÚresultÚdatarfrlZdfZ mgrs_indexersrGZindexersZaxZ
new_labelsZ
obj_labelsZnew_datar1r1r3r95sH
 
 
 
ÿz_Concatenator.get_resultÚint©r/cCs$|jr|jdkrdS|jdjSdS)NrCér)r[r^r.rV©rar1r1r3Ú_get_result_dimqsz_Concatenator._get_result_dimz list[Index]csˆ ¡}‡fdd„t|ƒDƒS)Ncs&g|]}|ˆjkrˆjnˆ |¡‘qSr1)r^Ú_get_concat_axisÚ_get_comb_axis©r>Úirwr1r3rAysÿz/_Concatenator._get_new_axes.<locals>.<listcomp>)rxrk)rarVr1rwr3r_ws
þz_Concatenator._get_new_axesrr)r|r/cCs*|jd |¡}t|j||j|j|jdS)Nr)r#rKr*r+)r.rZrrKr*r+)rar|Z    data_axisr1r1r3rz~sûz_Concatenator._get_comb_axisc    slˆjrêˆjdkr"dd„ˆjDƒ}nƈjr:ttˆjƒƒ}|SˆjdkrÖdgtˆjƒ}d}d}tˆjƒD]R\}}t|t    ƒsŽt
dt |ƒj ›dƒ‚|j dk    r¨|j ||<d}qf|||<|d    7}qf|rÆt|ƒSttˆjƒƒSntˆjƒ ˆj¡Sn‡fd
d„ˆjDƒ}ˆjr ttd d „|Dƒƒƒ}|SˆjdkrJˆjdk    r@td ƒ‚t|ƒ}nt|ˆjˆjˆjƒ}ˆ |¡|S)zC
        Return index to be used along concatenation axis.
        rcSsg|]
}|j‘qSr1)rf©r>Úxr1r1r3rAsz2_Concatenator._get_concat_axis.<locals>.<listcomp>NFz6Cannot concatenate type 'Series' with object of type 'ú'TrCcsg|]}|jˆj‘qSr1)rnr#r}rwr1r3rAªscss|]}t|ƒVqdSr0)rNr{r1r1r3Ú    <genexpr>­sz1_Concatenator._get_concat_axis.<locals>.<genexpr>z+levels supported only when keys is not None)r[r^r.r%rrNr&rmrFrrHrIrJrBrrZ    set_namesr(rDr'rLÚ_concat_indexesÚ_make_concat_multiindexÚ_maybe_check_integrity)    raÚindexesÚidxr(ÚnumZ    has_namesr|r~rir1rwr3ryˆsP
 
 
ÿ
 
 
 
ÿ
z_Concatenator._get_concat_axis)Ú concat_indexcCs.|jr*|js*|| ¡ ¡}td|›ƒ‚dS)Nz!Indexes have overlapping values: )r)Ú    is_uniqueZ
duplicatedÚuniquerL)rar‡Úoverlapr1r1r3rƒ½sz$_Concatenator._maybe_check_integrity)    rr7NNNFFTF) rJÚ
__module__Ú __qualname__Ú__doc__rer9rxr_rzrryrƒr1r1r1r3r8„s&õ-<
4r8rrucCs|d |dd…¡S)NrrC)rQ)r„r1r1r3rÄsrrc    sR|dkrt|dtƒs*|dk    rrt|ƒdkrrtt|Žƒ}|dkrLdgt|ƒ}|dkrbt|ƒ\}}q¬dd„|Dƒ}n:|g}|dkr†dg}|dkržt|ƒ ¡g}ndd„|Dƒ}|D]}|js°t    d| 
¡›ƒ‚q°t |ƒrêt dd„|Dƒƒs8g}t||ƒD]\}}g}    t||ƒD]h\}
} t |ƒt |
ƒ@||
kB} |  ¡sLt    d    |
›d
|›ƒ‚t | ¡dd} |     t | t| ƒ¡¡q| t |    ¡¡qøt|ƒ}t|tƒr¸| |j¡| |j¡n t|ƒ\}}| |¡| |¡t|ƒt|ƒkrôt|ƒ}n4td d „|Dƒƒdkstd ƒ‚t|ƒtt|Žƒ}t|||ddS|d}t|ƒ}t|ƒ‰t|ƒ}t|ƒ}g}t||ƒD]R\}}t|ƒ}| |¡}|dk} |  ¡r¬t    d|| ›ƒ‚| t ||¡¡qnt|tƒrö| |j¡| ‡fdd„|jDƒ¡n.| | ¡¡| ¡ |¡}| t |ˆ¡¡t|ƒt|ƒkrB| |j¡t|||ddS)NrrCcSsg|] }t|ƒ‘qSr1©rr}r1r1r3rAÓsz+_make_concat_multiindex.<locals>.<listcomp>cSsg|] }t|ƒ‘qSr1rŽr}r1r1r3rAÜszLevel values not unique: css|] }|jVqdSr0)rˆ)r>Úlevelr1r1r3r€âsz*_make_concat_multiindex.<locals>.<genexpr>zKey z not in level cSsh|]
}|j’qSr1)Znlevels)r>r…r1r1r3Ú    <setcomp>sz*_make_concat_multiindex.<locals>.<setcomp>z@Cannot concat indices that do not have the same number of levelsF)r'Úcodesr(r)éÿÿÿÿz"Values not found in passed level: csg|]}t |ˆ¡‘qSr1)rXÚtile)r>Zlab©Zkpiecesr1r3rA(s)rFÚtuplerNrMrPrrr‰rˆrLÚtolistrÚallrÚanyrXZnonzerorQÚrepeatZ concatenaterrÚextendr'r‘rr\rrpr“r()r„r&r'r(ZzippedÚ_rZ
codes_listZhlevelZ    to_concatÚkeyrfÚmaskr|r‡r‘Ú
categoriesZ    new_indexÚnZ    new_namesZ
new_levelsZ    new_codesZmappedZ single_codesr1r”r3r‚Èsœÿ
ÿ 
 
 
 
ÿÿ
 
   ÿr‚)NN);rÚ
__future__rÚ collectionsrÚtypingrrrrrr    r
r ÚnumpyrXZpandas._configr Zpandas._typingr rrZpandas.util._decoratorsrZpandas.core.dtypes.concatrZpandas.core.dtypes.genericrrZpandas.core.dtypes.inferencerZpandas.core.dtypes.missingrZpandas.core.arrays.categoricalrrZpandas.core.commonÚcoreÚcommonrOZpandas.core.indexes.apirrrrrrrZpandas.core.internalsrrYr r!Zpandas.core.genericr"r4r8rr‚r1r1r1r3Ú<module>s°  (      $      õ"õ"õ"õ"õ"õ pB