o
    5cb                     @  s"  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ ddlZddlZddlmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&  m'Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 erddl3m4Z4m5Z5 ddl6m7Z7 e									d9d:d d!Z8e									d9d;d$d!Z8e									d9d<d'd!Z8e								d=d>d)d!Z8e									d9d?d+d!Z8eddgd,		-	.				.	.	/d@d?d0d!Z8G d1d2 d2Z9dAd4d5Z:dBdCd7d8Z;dS )Dz
Concat routines.
    )annotations)abc)TYPE_CHECKINGCallableHashableIterableLiteralMappingcastoverloadN)Axis	HashableT)cache_readonlydeprecate_nonkeyword_arguments)find_stack_level)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.objs3Iterable[DataFrame] | Mapping[HashableT, DataFrame]axisLiteral[0, 'index']joinstrignore_indexboolverify_integritysortcopyreturnr    c
           
      C     d S N 
r#   r%   r'   r)   keyslevelsnamesr+   r,   r-   r1   r1   P/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/core/reshape/concat.pyconcatB      r7   -Iterable[Series] | Mapping[HashableT, Series]r!   c
           
      C  r/   r0   r1   r2   r1   r1   r6   r7   R   r8   /Iterable[NDFrame] | Mapping[HashableT, NDFrame]DataFrame | Seriesc
           
      C  r/   r0   r1   r2   r1   r1   r6   r7   b   r8   Literal[1, 'columns']c
           
      C  r/   r0   r1   r2   r1   r1   r6   r7   r   r8   r   c
           
      C  r/   r0   r1   r2   r1   r1   r6   r7      r8   )versionallowed_argsouterFTc
                 C  s$   t | ||||||||	|d
}
|
 S )az  
    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 when `join`
        is 'outer'.
        This has no effect when ``join='inner'``, which already preserves
        the order of the non-concatenation axis.

        .. versionchanged:: 1.0.0

           Changed to not sort by default.

    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
    )	r%   r)   r'   r3   r4   r5   r+   r-   r,   )_Concatenator
get_result)r#   r%   r'   r)   r3   r4   r5   r+   r,   r-   opr1   r1   r6   r7      s    _c                   @  sl   e Zd ZdZ									d$d%ddZdd Zd&ddZd'ddZd(ddZe	d)dd Z
d*d"d#ZdS )+r@   zB
    Orchestrates a concatenation operation for BlockManagers
    r   r?   NFTr#   r:   r'   r(   r)   r*   r+   r-   r.   Nonec                   s  t  tttfrtdt j d|dkrd| _n|dkr#d| _ntdt  t	j
rA|d u r7t  } fdd	|D  nt  t d
krOtd|d u r[ttj   n;g }g }t| D ]\}}|d u rmqd|| || qd| t |trt|j||jd}nt|dd }t||d}t d
krtdt } D ]}t |ttfsdt| d}t|||j qd }t|dkrt|} D ]}|j|krt|jr|} nqn%dd	  D }t|r|d u r|d u r|d u r| js|  d
 }|d u r d
 } | _t |tr%d
dlm } |!|}n|!|}t |t| _"| j"r9|#|}t |t| _$d
|  krL|jksXn t%d|j d| t|dkrd
}|j}g | j| _  D ]H}|j}||krxn6||d krtdt|dd }|s|d u r|}|d7 }| j"r|dkrd
}t&d|}|'||i}| j| qm|| _(| j"rd| j( nd
| _)|| _|pt|dd | _|| _*t+|
st,j-dt.t/ d |
| _0|| _1|| _2|	| _3| 4 | _5d S )NzTfirst argument must be an iterable of pandas objects, you passed an object of type ""r?   FinnerTz?Only can inner (intersect) or outer (union) join the other axisc                   s   g | ]} | qS r1   r1   ).0kr#   r1   r6   
<listcomp>      z*_Concatenator.__init__.<locals>.<listcomp>r   zNo objects to concatenate)r5   name)rK   zAll objects passed were Nonez#cannot concatenate object of type 'z+'; only Series and DataFrame objs are valid   c                 S  s(   g | ]}t |jd kst|tr|qS )r   )sumshape
isinstancer   )rF   objr1   r1   r6   rI     s    )r    zaxis must be between 0 and z, input was z>cannot concatenate unaligned mixed dimensional NDFrame objectsr;   r5   zUPassing non boolean values for sort is deprecated and will error in a future version!)
stacklevel)6rO   r   r   r(   	TypeErrortype__name__	intersect
ValueErrorr   r	   listr3   lencomnot_nonezipappendr   from_tuplesr5   getattrr   setaddndimmaxnprM   rN   r#   pandasr    _get_axis_number	_is_frame_get_block_manager_axis
_is_seriesAssertionErrorr
   _constructorbm_axisr%   r4   r   warningswarnFutureWarningr   r,   r)   r+   r-   _get_new_axesnew_axes)selfr#   r%   r'   r3   r4   r5   r)   r+   r-   r,   
clean_keys
clean_objsrG   vrK   ndimsrP   msgsamplemax_ndimnon_emptiesr    current_columnra   r1   rH   r6   __init__  s   








z_Concatenator.__init__c                 C  sx  | j ratd| jd }| jdkr:t| j}|j}dd | jD }t|dd}||| jd ||j	d}|j
| ddS tttt| j| j}|j}| j\}}	|||| jd	}
|	|
_|
j
| ddS td
| jd }g }| jD ]/}i }t| jD ]\}}|| jkrqw|jd|  }||s||||< qw||j|f qnt|| j| j| jd}| js|  |j}||j
| ddS )Nr!   r   c                 S     g | ]}|j qS r1   )_values)rF   serr1   r1   r6   rI   B      z,_Concatenator.get_result.<locals>.<listcomp>)r%   )indexrK   dtyper7   )method)r   r-   r    rL   )concat_axisr-   )rh   r
   r#   rk   rY   consensus_name_attrrj   r   rp   r   __finalize__dictr[   rangerX   _constructor_expanddimr-   columns	enumerateaxesequalsget_indexerr\   _mgrr   _consolidate_inplace)rq   rw   rK   consarrsresresultdatar   r   dfmgrs_indexersrP   indexersax
new_labels
obj_labelsnew_datar1   r1   r6   rA   5  sD   




z_Concatenator.get_resultintc                 C  s    | j r
| jdkr
dS | jd jS )NrL      r   )rh   rk   r#   ra   rq   r1   r1   r6   _get_result_dimq  s   z_Concatenator._get_result_dimlist[Index]c                   s      } fddt|D S )Nc                   s&   g | ]}| j kr jn |qS r1   )rk   _get_concat_axis_get_comb_axisrF   ir   r1   r6   rI   y  s    z/_Concatenator._get_new_axes.<locals>.<listcomp>)r   r   )rq   ra   r1   r   r6   ro   w  s   
z_Concatenator._get_new_axesr   r   c                 C  s*   | j d |}t| j || j| j| jdS )Nr   )r%   rU   r,   r-   )r#   rg   r   rU   r,   r-   )rq   r   	data_axisr1   r1   r6   r   ~  s   z_Concatenator._get_comb_axisc           	        sb   j rs jdkrdd  jD }nl jrtt j}|S  jdu rjdgt j }d}d}t jD ])\}}t|t	sGt
dt|j d|jdurT|j||< d}q3|||< |d	7 }q3|rct|S tt jS t j jS  fd
d jD } jrttdd |D }|S  jdu r jdurtdt|}n
t| j j j} | |S )zC
        Return index to be used along concatenation axis.
        r   c                 S  r|   r1   )r   rF   xr1   r1   r6   rI     r   z2_Concatenator._get_concat_axis.<locals>.<listcomp>NFz6Cannot concatenate type 'Series' with object of type ''TrL   c                   s   g | ]}|j  j qS r1   )r   r%   r   r   r1   r6   rI         c                 s  s    | ]}t |V  qd S r0   )rX   r   r1   r1   r6   	<genexpr>  s    z1_Concatenator._get_concat_axis.<locals>.<genexpr>z+levels supported only when keys is not None)rh   rk   r#   r)   r   rX   r3   r   rO   r   rR   rS   rT   rK   r   r   	set_namesr5   rM   r4   rV   _concat_indexes_make_concat_multiindex_maybe_check_integrity)	rq   indexesidxr5   num	has_namesr   r   r   r1   r   r6   r     sN   









z_Concatenator._get_concat_axisconcat_indexc                 C  s2   | j r|js||   }td| d S d S )Nz!Indexes have overlapping values: )r+   	is_unique
duplicateduniquerV   )rq   r   overlapr1   r1   r6   r     s   z$_Concatenator._maybe_check_integrity)	r   r?   NNNFFTF)r#   r:   r'   r(   r)   r*   r+   r*   r-   r*   r.   rC   )r.   r   )r.   r   )r   r   r.   r   r.   r   )r   r   )rT   
__module____qualname____doc__r{   rA   r   ro   r   r   r   r   r1   r1   r1   r6   r@     s(     1
<


4r@   r   c                 C  s   | d  | dd  S )Nr   rL   )r\   )r   r1   r1   r6   r     s   r   r   c              	     sJ  |d u rt |d ts|d ur9t|dkr9tt| }|d u r&d gt| }|d u r1t|\}}n%dd |D }n|g}|d u rCd g}|d u rOt| g}ndd |D }|D ]}|jsft	d|
  qXt| rutdd |D sg }t||D ]F\}}g }	t|| D ]2\}
}t|t|
@ ||
kB }| st	d	|
 d
| t|d d }|	t|t| q|t|	 q|t| }t |tr||j ||j nt|\}}|| || t|t|krt|}ntdd | D dkstdt|tt|   }t|||ddS | d }t|}t|  t|}t|}g }t||D ])\}}t|}||}|dk}| rRt	d|| |t|| q3t |trw||j | fdd|jD  n||  | |}|t|  t|t|k r||j t|||ddS )Nr   rL   c                 S     g | ]}t |qS r1   r   r   r1   r1   r6   rI     rJ   z+_make_concat_multiindex.<locals>.<listcomp>c                 S  r   r1   r   r   r1   r1   r6   rI     rJ   zLevel values not unique: c                 s  s    | ]}|j V  qd S r0   )r   )rF   levelr1   r1   r6   r     s    z*_make_concat_multiindex.<locals>.<genexpr>zKey z not in level c                 S  s   h | ]}|j qS r1   )nlevels)rF   r   r1   r1   r6   	<setcomp>  r   z*_make_concat_multiindex.<locals>.<setcomp>z@Cannot concat indices that do not have the same number of levelsF)r4   codesr5   r+   z"Values not found in passed level: c                   s   g | ]}t | qS r1   )rc   tile)rF   labkpiecesr1   r6   rI   )  r   )rO   tuplerX   rW   r[   r   r   r   r   rV   tolistr   allr   anyrc   nonzeror\   repeatconcatenater   r   extendr4   r   r   ri   r   r   r   r5   )r   r3   r4   r5   zipped_r   
codes_listhlevel	to_concatkeyr   maskr   r   r   
categories	new_indexn	new_names
new_levels	new_codesmappedsingle_codesr1   r   r6   r     s   






r   )	.........)r#   r$   r%   r&   r'   r(   r)   r*   r+   r*   r,   r*   r-   r*   r.   r    )r#   r9   r%   r&   r'   r(   r)   r*   r+   r*   r,   r*   r-   r*   r.   r!   )r#   r:   r%   r&   r'   r(   r)   r*   r+   r*   r,   r*   r-   r*   r.   r;   )........)r#   r:   r%   r<   r'   r(   r)   r*   r+   r*   r,   r*   r-   r*   r.   r    )r#   r:   r%   r   r'   r(   r)   r*   r+   r*   r,   r*   r-   r*   r.   r;   )	r   r?   FNNNFFTr   )NN)r.   r   )<r   
__future__r   collectionsr   typingr   r   r   r   r   r	   r
   r   rl   numpyrc   pandas._typingr   r   pandas.util._decoratorsr   r   pandas.util._exceptionsr   pandas.core.dtypes.concatr   pandas.core.dtypes.genericr   r   pandas.core.dtypes.inferencer   pandas.core.dtypes.missingr   pandas.core.arrays.categoricalr   r   pandas.core.commoncorecommonrY   pandas.core.indexes.apir   r   r   r   r   r   r   pandas.core.internalsr   rd   r    r!   pandas.core.genericr"   r7   r@   r   r   r1   r1   r1   r6   <module>   s    (
$	 n  
F