§
    q-Ph£`  ã                  óz  — d dl mZ d dlZd dlmZ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 d d	lmZmZ d d
lmZmZmZmZ d dlmZ  ej         e!¦  «        5  d dl"mZ# ddd¦  «         n# 1 swxY w Y   erd dlm$Z$ d dlm%Z%m&Z&m'Z'm(Z( d dlm)Z)m*Z*m+Z+ ddddœd1d„Z,dddœd2d'„Z-dddd(œd3d0„Z.dS )4é    )ÚannotationsN)Ú	GeneratorÚIteratorÚSequence)Úreduce)Úchain)ÚTYPE_CHECKINGÚget_args)Ú	functions)ÚConcatMethod)Úordered_uniqueÚqualified_type_name)Úwrap_dfÚ	wrap_exprÚwrap_ldfÚwrap_s)ÚInvalidOperationError)ÚIterable)Ú	DataFrameÚExprÚ	LazyFrameÚSeries)Ú	FrameTypeÚJoinStrategyÚ
PolarsTypeÚverticalFT)ÚhowÚrechunkÚparallelÚitemsúIterable[PolarsType]r   r   r   Úboolr   Úreturnr   c          
     ó<  ‡‡‡— t          | ¦  «        }|sd}t          |¦  «        ‚t          |¦  «        dk    r?t          |d         t          j        t          j        t          j        f¦  «        r|d         S |                     d¦  «        r”t          |d         t          j        t          j        f¦  «        s)|›dt          |d         ¦  «        ›}t          |¦  «        ‚t          t          j        d„ |D ¦   «         ¦  «        ¦  «        }d„ t          t          |¦  «        ¦  «        D ¦   «         Št          ‰¦  «        }t          t!          d„ t          d	„ |D ¦   «         ¦  «        ¦  «        ˆfd
„¬¦  «        Š‰s|›d}t#          |¦  «        ‚|dk    rdn|                     d¦  «        Š t!          ˆˆfd„d„ |D ¦   «         ¦  «                             ‰¬¦  «        j        |Ž }t          |d         t          j        ¦  «        }	|	r|                     ¦   «         n|S |d         }
ddlm} t          |
t          j        ¦  «        r}|dk    r#t1          t3          j        |¦  «        ¦  «        }n|dk    rWt7          t3          j        d„ |D ¦   «         ||d¬¦  «        ¦  «                             |                     ¦   «         ¬¦  «        }nµ|dk    r#t1          t3          j        |¦  «        ¦  «        }nŒ|dk    rWt7          t3          j        d„ |D ¦   «         ||d¬¦  «        ¦  «                             |                     ¦   «         ¬¦  «        }n/|dk    r#t1          t3          j         |¦  «        ¦  «        }nd !                    d„ tE          tF          ¦  «        D ¦   «         ¦  «        }d|› d |›}t          |¦  «        ‚t          |
t          j        ¦  «        ré|d!v r8t7          t3          j        |||| $                    d"¦  «        ¬¦  «        ¦  «        S |d#v r8t7          t3          j        |||| $                    d"¦  «        ¬¦  «        ¦  «        S |dk    r#t7          t3          j%        ||¬$¦  «        ¦  «        S d !                    d%„ tE          tF          ¦  «        D ¦   «         ¦  «        }d&|› d |›}t          |¦  «        ‚t          |
t          j        ¦  «        r9|dk    r"tM          t3          j'        |¦  «        ¦  «        }nyd'}t          |¦  «        ‚t          |
t          j(        ¦  «        r,tS          t3          j*        d(„ |D ¦   «         |¦  «        ¦  «        S d)t          |
¦  «        ›d*}t          |¦  «        ‚|r| +                    ¦   «         S |S )+uÉ  
    Combine multiple DataFrames, LazyFrames, or Series into a single object.

    Parameters
    ----------
    items
        DataFrames, LazyFrames, or Series to concatenate.
    how : {'vertical', 'vertical_relaxed', 'diagonal', 'diagonal_relaxed', 'horizontal', 'align', 'align_full', 'align_inner', 'align_left', 'align_right'}
        Note that `Series` only support the `vertical` strategy.

        * vertical: Applies multiple `vstack` operations.
        * vertical_relaxed: Same as `vertical`, but additionally coerces columns to
          their common supertype *if* they are mismatched (eg: Int32 â†’ Int64).
        * diagonal: Finds a union between the column schemas and fills missing column
          values with `null`.
        * diagonal_relaxed: Same as `diagonal`, but additionally coerces columns to
          their common supertype *if* they are mismatched (eg: Int32 â†’ Int64).
        * horizontal: Stacks Series from DataFrames horizontally and fills with `null`
          if the lengths don't match.
        * align, align_full, align_left, align_right: Combines frames horizontally,
          auto-determining the common key columns and aligning rows using the same
          logic as `align_frames` (note that "align" is an alias for "align_full").
          The "align" strategy determines the type of join used to align the frames,
          equivalent to the "how" parameter on `align_frames`. Note that the common
          join columns are automatically coalesced, but other column collisions
          will raise an error (if you need more control over this you should use
          a suitable `join` method directly).
    rechunk
        Make sure that the result data is in contiguous memory.
    parallel
        Only relevant for LazyFrames. This determines if the concatenated
        lazy computations may be executed in parallel.

    Examples
    --------
    >>> df1 = pl.DataFrame({"a": [1], "b": [3]})
    >>> df2 = pl.DataFrame({"a": [2], "b": [4]})
    >>> pl.concat([df1, df2])  # default is 'vertical' strategy
    shape: (2, 2)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
    â”‚ a   â”† b   â”‚
    â”‚ --- â”† --- â”‚
    â”‚ i64 â”† i64 â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
    â”‚ 1   â”† 3   â”‚
    â”‚ 2   â”† 4   â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜

    >>> df1 = pl.DataFrame({"a": [1], "b": [3]})
    >>> df2 = pl.DataFrame({"a": [2.5], "b": [4]})
    >>> pl.concat([df1, df2], how="vertical_relaxed")  # 'a' coerced into f64
    shape: (2, 2)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
    â”‚ a   â”† b   â”‚
    â”‚ --- â”† --- â”‚
    â”‚ f64 â”† i64 â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
    â”‚ 1.0 â”† 3   â”‚
    â”‚ 2.5 â”† 4   â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜

    >>> df_h1 = pl.DataFrame({"l1": [1, 2], "l2": [3, 4]})
    >>> df_h2 = pl.DataFrame({"r1": [5, 6], "r2": [7, 8], "r3": [9, 10]})
    >>> pl.concat([df_h1, df_h2], how="horizontal")
    shape: (2, 5)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
    â”‚ l1  â”† l2  â”† r1  â”† r2  â”† r3  â”‚
    â”‚ --- â”† --- â”† --- â”† --- â”† --- â”‚
    â”‚ i64 â”† i64 â”† i64 â”† i64 â”† i64 â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
    â”‚ 1   â”† 3   â”† 5   â”† 7   â”† 9   â”‚
    â”‚ 2   â”† 4   â”† 6   â”† 8   â”† 10  â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜

    The "diagonal" strategy allows for some frames to have missing columns,
    the values for which are filled with `null`:

    >>> df_d1 = pl.DataFrame({"a": [1], "b": [3]})
    >>> df_d2 = pl.DataFrame({"a": [2], "c": [4]})
    >>> pl.concat([df_d1, df_d2], how="diagonal")
    shape: (2, 3)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
    â”‚ a   â”† b    â”† c    â”‚
    â”‚ --- â”† ---  â”† ---  â”‚
    â”‚ i64 â”† i64  â”† i64  â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
    â”‚ 1   â”† 3    â”† null â”‚
    â”‚ 2   â”† null â”† 4    â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜

    The "align" strategies require at least one common column to align on:

    >>> df_a1 = pl.DataFrame({"id": [1, 2], "x": [3, 4]})
    >>> df_a2 = pl.DataFrame({"id": [2, 3], "y": [5, 6]})
    >>> df_a3 = pl.DataFrame({"id": [1, 3], "z": [7, 8]})
    >>> pl.concat([df_a1, df_a2, df_a3], how="align")  # equivalent to "align_full"
    shape: (3, 4)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
    â”‚ id  â”† x    â”† y    â”† z    â”‚
    â”‚ --- â”† ---  â”† ---  â”† ---  â”‚
    â”‚ i64 â”† i64  â”† i64  â”† i64  â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
    â”‚ 1   â”† 3    â”† null â”† 7    â”‚
    â”‚ 2   â”† 4    â”† 5    â”† null â”‚
    â”‚ 3   â”† null â”† 6    â”† 8    â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
    >>> pl.concat([df_a1, df_a2, df_a3], how="align_left")
    shape: (2, 4)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
    â”‚ id  â”† x   â”† y    â”† z    â”‚
    â”‚ --- â”† --- â”† ---  â”† ---  â”‚
    â”‚ i64 â”† i64 â”† i64  â”† i64  â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
    â”‚ 1   â”† 3   â”† null â”† 7    â”‚
    â”‚ 2   â”† 4   â”† 5    â”† null â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
    >>> pl.concat([df_a1, df_a2, df_a3], how="align_right")
    shape: (2, 4)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
    â”‚ id  â”† x    â”† y    â”† z   â”‚
    â”‚ --- â”† ---  â”† ---  â”† --- â”‚
    â”‚ i64 â”† i64  â”† i64  â”† i64 â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•¡
    â”‚ 1   â”† null â”† null â”† 7   â”‚
    â”‚ 3   â”† null â”† 6    â”† 8   â”‚
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
    >>> pl.concat([df_a1, df_a2, df_a3], how="align_inner")
    shape: (0, 4)
    â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
    â”‚ id  â”† x   â”† y   â”† z   â”‚
    â”‚ --- â”† --- â”† --- â”† --- â”‚
    â”‚ i64 â”† i64 â”† i64 â”† i64 â”‚
    â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
    â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
    zcannot concat empty listé   r   Úalignz strategy is not supported for c              3  ó>   K  — | ]}|                      ¦   «         V — Œd S ©N©Úcollect_schema©Ú.0Úes     úV/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/functions/eager.pyú	<genexpr>zconcat.<locals>.<genexpr>¹   s.   è è € Ð.QÐ.QÀa¨q×/?Ò/?Ñ/AÔ/AÐ.QÐ.QÐ.QÐ.QÐ.QÐ.Qó    c                ó   — i | ]\  }}||“Œ	S © r2   )r,   ÚkÚvs      r.   ú
<dictcomp>zconcat.<locals>.<dictcomp>º   s   € ÐGÐGÐG™˜˜1ˆq!ÐGÐGÐGr0   c                ó@   — t          | ¦  «        t          |¦  «        z  S r(   )Úset)ÚxÚys     r.   ú<lambda>zconcat.<locals>.<lambda>¾   s   € S ™VœV¥c¨!¡f¤f™_€ r0   c              3  ó>   K  — | ]}|                      ¦   «         V — Œd S r(   r)   r+   s     r.   r/   zconcat.<locals>.<genexpr>¿   s.   è è € Ð8Ð8¨Qa×&Ò&Ñ(Ô(Ð8Ð8Ð8Ð8Ð8Ð8r0   c                ó0   •— ‰                      | d¦  «        S )Nr   )Úget)r3   Úkeys    €r.   r:   zconcat.<locals>.<lambda>Á   s   ø€ ˜#Ÿ'š' ! Q™-œ-€ r0   )r>   z- strategy requires at least one common columnÚfullÚalign_c                ó8   •— |                       |‰‰dd¬¦  «        S )NÚ
right_leftT)Úonr   Úmaintain_orderÚcoalesce©Újoin)r8   r9   Úcommon_colsÚjoin_methods     €€r.   r:   zconcat.<locals>.<lambda>Ï   s-   ø€ Ø—F’FØØ&Ø'Ø'3Ø!%ð ñ ô ð r0   c                ó6   — g | ]}|                      ¦   «         ‘ŒS r2   ©Úlazy©r,   Údfs     r.   ú
<listcomp>zconcat.<locals>.<listcomp>Ø   s    € Ð+Ð+Ð+˜r—’‘”Ð+Ð+Ð+r0   )Úby©ÚQueryOptFlagsr   Úvertical_relaxedc                ó6   — g | ]}|                      ¦   «         ‘ŒS r2   rK   rM   s     r.   rO   zconcat.<locals>.<listcomp>ë   ó    € Ð/Ð/Ð/ 2R—W’W‘Y”YÐ/Ð/Ð/r0   T)r   r   Úto_supertypes©ÚoptimizationsÚdiagonalÚdiagonal_relaxedc                ó6   — g | ]}|                      ¦   «         ‘ŒS r2   rK   rM   s     r.   rO   zconcat.<locals>.<listcomp>÷   rU   r0   Ú
horizontalz, c              3  ó4   K  — | ]}t          |¦  «        V — Œd S r(   ©Úrepr©r,   Úms     r.   r/   zconcat.<locals>.<genexpr>   ó(   è è € ÐHÐH¨A¥ Q¡¤ÐHÐHÐHÐHÐHÐHr0   z DataFrame `how` must be one of {z}, got )r   rS   Úrelaxed)rY   rZ   )r   c              3  ó4   K  — | ]}t          |¦  «        V — Œd S r(   r^   r`   s     r.   r/   zconcat.<locals>.<genexpr>  rb   r0   z LazyFrame `how` must be one of {z/Series only supports 'vertical' concat strategyc                ó   — g | ]	}|j         ‘Œ
S r2   )Ú_pyexprr+   s     r.   rO   zconcat.<locals>.<listcomp>+  s   € Ð)CÐ)CÐ)C¸¨!¬)Ð)CÐ)CÐ)Cr0   zdid not expect type: z in `concat`),ÚlistÚ
ValueErrorÚlenÚ
isinstanceÚplr   r   r   Ú
startswithr   Ú	TypeErrorr   Úfrom_iterableÚ	enumerater   Úsortedr   r   ÚremoveprefixÚsortÚselectÚcollectÚpolars.lazyframe.opt_flagsrR   r   ÚplrÚ	concat_dfr   Ú	concat_lfÚ_eagerÚconcat_df_diagonalÚconcat_lf_diagonalÚconcat_df_horizontalrG   r
   r   ÚendswithÚconcat_lf_horizontalr   Úconcat_seriesr   r   Úconcat_exprr   )r    r   r   r   ÚelemsÚmsgÚall_columnsÚoutput_column_orderÚlfÚeagerÚfirstrR   ÚoutÚallowedrH   rI   r>   s                 @@@r.   ÚconcatrŠ      s  øøø€ õ^ ‰KŒK€Eàð Ø(ˆÝ˜‰oŒoÐÝ	ˆU‰ŒqŠˆZØˆaŒ•2”<¥¤­B¬LÐ9ñô ˆð QŒxˆà
‡~‚~gÑÔñ +-Ý˜% œ(¥R¤\µ2´<Ð$@ÑAÔAð 	!ØÐ\Ð\Õ;NÈuÐUVÌxÑ;XÔ;XÐ\Ð\ˆCÝ˜C‘.”.Ð õ 5Ô.Ð.QÐ.QÈ5Ð.QÑ.QÔ.QÑQÔQÑRÔRˆØGÐG¥	­.¸Ñ*EÔ*EÑ FÔ FÐGÑGÔGˆÝ" 3™iœiÐÝÝØ,Ð,ÝÐ8Ð8°%Ð8Ñ8Ô8Ñ8Ô8ñô ð (Ð'Ð'Ð'ð
ñ 
ô 
ˆð ð 	-ØÐIÐIÐIˆCÝ'¨Ñ,Ô,Ð,ð
 ˜W’nnˆFˆF¨#×*:Ò*:¸8Ñ*DÔ*Dð 	ðFðð ð ð ð ð ,Ð+ UÐ+Ñ+Ô+ñô ÷ ŠT[ˆTÑ!Ô!ÜÐ(ð*ð 	õ  ˜5 œ8¥R¤\Ñ2Ô2ˆØ$Ð,ˆrzŠz‰|Œ|ˆ|¨"Ð,ð !ŒH€Eà8Ð8Ð8Ð8Ð8Ð8å%œÑ&Ô&ñ IØ*ÒÐÝ#œ-¨Ñ.Ô.Ñ/Ô/ˆC‰CØÐ&Ò&Ð&ÝÝ”Ø/Ð/¨Ð/Ñ/Ô/Ø#Ø%Ø"&ð	ñ ô ñô ÷ Šg M×$8Ò$8Ñ$:Ô$:ˆgÑ;Ô;ð ‰Cð JÒÐÝ#Ô0°Ñ7Ô7Ñ8Ô8ˆC‰CØÐ&Ò&Ð&ÝÝÔ&Ø/Ð/¨Ð/Ñ/Ô/Ø#Ø%Ø"&ð	ñ ô ñô ÷ Šg M×$8Ò$8Ñ$:Ô$:ˆgÑ;Ô;ð ‰Cð LÒ Ð Ý#Ô2°5Ñ9Ô9Ñ:Ô:ˆC‰Cà—i’iÐHÐHµ½,Ñ1GÔ1GÐHÑHÔHÑHÔHˆGØN°gÐNÐNÀsÐNÐNˆCÝ˜S‘/”/Ð!å	E2œ<Ñ	(Ô	(ð *ØÐ2Ð2Ð2ÝÝ”ØØ#Ø%Ø"%§,¢,¨yÑ"9Ô"9ð	ñ ô ñô ð ð Ð4Ð4Ð4ÝÝÔ&ØØ#Ø%Ø"%§,¢,¨yÑ"9Ô"9ð	ñ ô ñô ð ð LÒ Ð ÝÝÔ(ØØ%ðñ ô ñô ð ð —i’iÐHÐHµ½,Ñ1GÔ1GÐHÑHÔHÑHÔHˆGØN°gÐNÐNÀsÐNÐNˆCÝ˜S‘/”/Ð!å	E2œ9Ñ	%Ô	%ð Ø*ÒÐÝÔ*¨5Ñ1Ô1Ñ2Ô2ˆCˆCàCˆCÝ˜S‘/”/Ð!å	E2œ7Ñ	#Ô	#ð ÝœÐ)CÐ)C¸UÐ)CÑ)CÔ)CÀWÑMÔMÑNÔNÐNàPÕ&9¸%Ñ&@Ô&@ÐPÐPÐPˆÝ˜‰nŒnÐàð Ø{Š{‰}Œ}ÐØ€Jr0   r?   )r   Ú
descendingÚ
idx_framesútuple[int, LazyFrame]Úalign_onú	list[str]r   r‹   úbool | Sequence[bool]r   c                ó  ‡ ‡— t          |¦  «        dk    }dˆ ˆfd„}ddlm} t          ||¦  «        d	                              ‰ |¬
¦  «        }|r:|                     |                     ¦   «         ¬¦  «                             ¦   «         }|S )zLCreate a single master frame with all rows aligned on the common key values.éú   Úidx_xr   Úidx_yr#   c           
     ó\   •— | |c\  }}\  }}||                      |‰‰d|› ddd¬¦  «        fS )Nú:TrB   )r   rC   ÚsuffixÚnulls_equalrE   rD   rF   )r“   r”   Ú_r8   Úy_idxr9   rŽ   r   s         €€r.   Ú	join_funcz"_alignment_join.<locals>.join_func@  sV   ø€ ð # EÐ‰ˆˆA‘
˜Øa—f’fØØØØu;;ØØØ'ð ñ 
ô 
ð 
ð 	
r0   r   rQ   r%   )rP   r‹   rW   )r“   r   r”   r   r#   r   )ri   Úpolars.lazyframerR   r   rr   rt   ÚnonerL   )rŽ   r   r‹   rŒ   Úpost_align_collectr›   rR   Újoineds   ``      r.   Ú_alignment_joinr    5  s®   øø€ õ ˜Z™œ¨CÒ/Ðð
ð 
ð 
ð 
ð 
ð 
ð 
ð /Ð.Ð.Ð.Ð.Ð.åI˜zÑ*Ô*¨1Ô-×2Ò2°hÈ:Ð2ÑVÔV€FØð KØ—’¨m×.@Ò.@Ñ.BÔ.BÑCÔC×HÒHÑJÔJˆØ€Mr0   )r   rs   r‹   ÚframesúFrameType | Iterable[FrameType]rC   úBstr | Expr | Sequence[str] | Sequence[Expr] | Sequence[str | Expr]rs   ú(str | Expr | Sequence[str | Expr] | Noneúlist[FrameType]c                ó  ‡‡— |sg S t          |¦  «        dk    r4t          |d         t          j        t          j        f¦  «        s|d         }t          |t
          t          f¦  «        rt          |¦  «        }t          d„ |D ¦   «         ¦  «        dk    rd}t          |¦  «        ‚t          |d         t          j        ¦  «        }t          | t          ¦  «        st          | t          ¦  «        s| gn| } d„ | D ¦   «         }d„ t          |¦  «        D ¦   «         }t          ||||dœŽ}	t          |	                     ¦   «         ¦  «        Šg }
|D ]a\  }}d|› Šˆˆfd	„|                     ¦   «         D ¦   «         } |	j        |Ž }||                     |¦  «        }|
                     |¦  «         Œb|rt#          j        |
¦  «        n|
S )
u#  
    Align a sequence of frames using common values from one or more columns as a key.

    Frames that do not contain the given key values have rows injected (with nulls
    filling the non-key columns), and each resulting frame is sorted by the key.

    The original column order of input frames is not changed unless `select` is
    specified (in which case the final column order is determined from that). In the
    case where duplicate key values exist, the alignment behaviour is determined by
    the given alignment strategy specified in the `how` parameter (by default this
    is a full outer join, but if your data is suitable you can get a large speedup
    by setting `how="left"` instead).

    Note that this function does not result in a joined frame - you receive the same
    number of frames back that you passed in, but each is now aligned by key and has
    the same number of rows.

    Parameters
    ----------
    frames
        Sequence of DataFrames or LazyFrames.
    on
        One or more columns whose unique values will be used to align the frames.
    select
        Optional post-alignment column select to constrain and/or order
        the columns returned from the newly aligned frames.
    descending
        Sort the alignment column values in descending order; can be a single
        boolean or a list of booleans associated with each column in `on`.
    how
        By default the row alignment values are determined using a full outer join
        strategy across all frames; if you know that the first frame contains all
        required keys, you can set `how="left"` for a large performance increase.

    Examples
    --------
    >>> from datetime import date
    >>> df1 = pl.DataFrame(
    ...     {
    ...         "dt": [date(2022, 9, 1), date(2022, 9, 2), date(2022, 9, 3)],
    ...         "x": [3.5, 4.0, 1.0],
    ...         "y": [10.0, 2.5, 1.5],
    ...     }
    ... )
    >>> df2 = pl.DataFrame(
    ...     {
    ...         "dt": [date(2022, 9, 2), date(2022, 9, 3), date(2022, 9, 1)],
    ...         "x": [8.0, 1.0, 3.5],
    ...         "y": [1.5, 12.0, 5.0],
    ...     }
    ... )
    >>> df3 = pl.DataFrame(
    ...     {
    ...         "dt": [date(2022, 9, 3), date(2022, 9, 2)],
    ...         "x": [2.0, 5.0],
    ...         "y": [2.5, 2.0],
    ...     }
    ... )  # doctest: +IGNORE_RESULT
    >>> pl.Config.set_tbl_formatting("UTF8_FULL")  # doctest: +IGNORE_RESULT
    #
    # df1                              df2                              df3
    # shape: (3, 3)                    shape: (3, 3)                    shape: (2, 3)
    # â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”      â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”      â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”
    # â”‚ dt         â”† x   â”† y    â”‚      â”‚ dt         â”† x   â”† y    â”‚      â”‚ dt         â”† x   â”† y   â”‚
    # â”‚ ---        â”† --- â”† ---  â”‚      â”‚ ---        â”† --- â”† ---  â”‚      â”‚ ---        â”† --- â”† --- â”‚
    # â”‚ date       â”† f64 â”† f64  â”‚      â”‚ date       â”† f64 â”† f64  â”‚      â”‚ date       â”† f64 â”† f64 â”‚
    # â•žâ•â•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡      â•žâ•â•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡      â•žâ•â•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•¡
    # â”‚ 2022-09-01 â”† 3.5 â”† 10.0 â”‚\  ,->â”‚ 2022-09-02 â”† 8.0 â”† 1.5  â”‚\  ,->â”‚ 2022-09-03 â”† 2.0 â”† 2.5 â”‚
    # â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤ \/   â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤ \/   â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    # â”‚ 2022-09-02 â”† 4.0 â”† 2.5  â”‚_/\,->â”‚ 2022-09-03 â”† 1.0 â”† 12.0 â”‚_/`-->â”‚ 2022-09-02 â”† 5.0 â”† 2.0 â”‚
    # â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤  /\  â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜
    # â”‚ 2022-09-03 â”† 1.0 â”† 1.5  â”‚_/  `>â”‚ 2022-09-01 â”† 3.5 â”† 5.0  â”‚-//-
    # â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜      â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
    ...

    Align frames by the "dt" column:

    >>> af1, af2, af3 = pl.align_frames(
    ...     df1, df2, df3, on="dt"
    ... )  # doctest: +IGNORE_RESULT
    #
    # df1                              df2                              df3
    # shape: (3, 3)                    shape: (3, 3)                    shape: (3, 3)
    # â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”      â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”      â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
    # â”‚ dt         â”† x   â”† y    â”‚      â”‚ dt         â”† x   â”† y    â”‚      â”‚ dt         â”† x    â”† y    â”‚
    # â”‚ ---        â”† --- â”† ---  â”‚      â”‚ ---        â”† --- â”† ---  â”‚      â”‚ ---        â”† ---  â”† ---  â”‚
    # â”‚ date       â”† f64 â”† f64  â”‚      â”‚ date       â”† f64 â”† f64  â”‚      â”‚ date       â”† f64  â”† f64  â”‚
    # â•žâ•â•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡      â•žâ•â•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡      â•žâ•â•â•â•â•â•â•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
    # â”‚ 2022-09-01 â”† 3.5 â”† 10.0 â”‚----->â”‚ 2022-09-01 â”† 3.5 â”† 5.0  â”‚----->â”‚ 2022-09-01 â”† null â”† null â”‚
    # â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    # â”‚ 2022-09-02 â”† 4.0 â”† 2.5  â”‚----->â”‚ 2022-09-02 â”† 8.0 â”† 1.5  â”‚----->â”‚ 2022-09-02 â”† 5.0  â”† 2.0  â”‚
    # â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    # â”‚ 2022-09-03 â”† 1.0 â”† 1.5  â”‚----->â”‚ 2022-09-03 â”† 1.0 â”† 12.0 â”‚----->â”‚ 2022-09-03 â”† 2.0  â”† 2.5  â”‚
    # â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜      â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜      â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
    ...

    Align frames by "dt" using "left" alignment, but keep only cols "x" and "y":

    >>> af1, af2, af3 = pl.align_frames(
    ...     df1, df2, df3, on="dt", select=["x", "y"], how="left"
    ... )  # doctest: +IGNORE_RESULT
    #
    # af1                 af2                 af3
    # shape: (3, 3)       shape: (3, 3)       shape: (3, 3)
    # â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”      â”Œâ”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”      â”Œâ”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”€â”
    # â”‚ x   â”† y    â”‚      â”‚ x   â”† y    â”‚      â”‚ x    â”† y    â”‚
    # â”‚ --- â”† ---  â”‚      â”‚ --- â”† ---  â”‚      â”‚ ---  â”† ---  â”‚
    # â”‚ f64 â”† f64  â”‚      â”‚ f64 â”† f64  â”‚      â”‚ f64  â”† f64  â”‚
    # â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡      â•žâ•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡      â•žâ•â•â•â•â•â•â•ªâ•â•â•â•â•â•â•¡
    # â”‚ 3.5 â”† 10.0 â”‚      â”‚ 3.5 â”† 5.0  â”‚      â”‚ null â”† null â”‚
    # â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    # â”‚ 4.0 â”† 2.5  â”‚      â”‚ 8.0 â”† 1.5  â”‚      â”‚ 5.0  â”† 2.0  â”‚
    # â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤      â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¼â•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    # â”‚ 1.0 â”† 1.5  â”‚      â”‚ 1.0 â”† 12.0 â”‚      â”‚ 2.0  â”† 2.5  â”‚
    # â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜      â””â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜      â””â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”€â”˜
    ...

    Now data is aligned, and you can easily calculate the row-wise dot product:

    >>> (af1 * af2 * af3).fill_null(0).select(pl.sum_horizontal("*").alias("dot"))
    shape: (3, 1)
    â”Œâ”€â”€â”€â”€â”€â”€â”€â”
    â”‚ dot   â”‚
    â”‚ ---   â”‚
    â”‚ f64   â”‚
    â•žâ•â•â•â•â•â•â•â•¡
    â”‚ 0.0   â”‚
    â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    â”‚ 167.5 â”‚
    â”œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ•Œâ”¤
    â”‚ 47.0  â”‚
    â””â”€â”€â”€â”€â”€â”€â”€â”˜
    r%   r   c                ó,   — h | ]}t          |¦  «        ’ŒS r2   )Útype)r,   Úfs     r.   ú	<setcomp>zalign_frames.<locals>.<setcomp>ë  s   € Ð$Ð$Ð$˜D‰GŒGÐ$Ð$Ð$r0   zJinput frames must be of a consistent type (all LazyFrame or all DataFrame)c                óx   — g | ]7}t          |t          j        ¦  «        r|j                             ¦   «         n|‘Œ8S r2   )rj   rk   r   ÚmetaÚoutput_name)r,   Úcs     r.   rO   z align_frames.<locals>.<listcomp>ó  s<   € ÐTÐTÐTÈA­°Aµr´wÑ)?Ô)?ÐF”×#Ò#Ñ%Ô%Ð%ÀQÐTÐTÐTr0   c                ó@   — g | ]\  }}||                      ¦   «         f‘ŒS r2   rK   )r,   ÚidxÚframes      r.   rO   z align_frames.<locals>.<listcomp>÷  s)   € ÐJÐJÐJ©*¨#¨u3˜Ÿ
š
™œÐ%ÐJÐJÐJr0   )rŽ   r   r‹   r–   c                óž   •— g | ]I}|› ‰› ‰v r+t          j        |› ‰› ¦  «                             |¦  «        nt          j        |¦  «        ‘ŒJS r2   )ÚFÚcolÚalias)r,   r®   Úaligned_colsÚsfxs     €€r.   rO   z align_frames.<locals>.<listcomp>  si   ø€ ð 
ð 
ð 
àð /0¨;°¨;¨;¸,Ð+FÐ+FAŒEQ+˜++ÑÔ×$Ò$ QÑ'Ô'Ð'ÍAÌEÐRSÉHÌHð
ð 
ð 
r0   )ri   rj   rk   r   r   r   r   Útuplerm   Ústrr   ro   r    r7   r*   rs   Úappendr³   Úcollect_all)rC   r   rs   r‹   r¡   r‚   r†   rŽ   rŒ   Úalignment_frameÚaligned_framesr°   r…   Údf_colsr©   r¶   r·   s                  @@r.   Úalign_framesr¿   W  s  øø€ ðX ð Øˆ	å
ˆ6{„{aÒÐ¥
¨6°!¬9µr´|ÅRÄ\Ð6RÑ SÔ SÐØ˜”ˆÝ&9¥hÐ/Ñ0Ô0ð Ýv‘”ˆå
Ð$Ð$˜VÐ$Ñ$Ô$Ñ%Ô%¨Ò*Ð*àXð 	õ ˜‰nŒnÐåv˜a”y¥"¤,Ñ/Ô/€EÝ˜R¥Ñ%Ô%Ð	N­Z¸½HÑ-EÔ-EÐ	Nˆ"ˆˆÈB€BØTÐTÐQSÐTÑTÔT€Hð KÐJ½	À&Ñ8IÔ8IÐJÑJÔJ€JÝ%Ø	˜h¨C¸Jðð ð €Oõ
 ×5Ò5Ñ7Ô7Ñ8Ô8€LØ€NØð 	!ð 	!‰ˆˆRØ#ˆiˆiˆð
ð 
ð 
ð 
ð 
à×&Ò&Ñ(Ô(ð
ñ 
ô 
ˆð #ˆOÔ" GÐ,ˆØÐØ—’˜Ñ Ô ˆAØ×Ò˜aÑ Ô Ð Ð à,1ÐE1Œ=˜Ñ(Ô(Ð(°~ÐEr0   )
r    r!   r   r   r   r"   r   r"   r#   r   )
rŒ   r   rŽ   r   r   r   r‹   r   r#   r   )r¡   r¢   rC   r£   r   r   rs   r¤   r‹   r   r#   r¥   )/Ú
__future__r   Ú
contextlibÚcollections.abcr   r   r   Ú	functoolsr   Ú	itertoolsr   Útypingr	   r
   Úpolars._reexportÚ	_reexportrk   Úpolarsr   r³   Úpolars._typingr   Úpolars._utils.variousr   r   Úpolars._utils.wrapr   r   r   r   Úpolars.exceptionsr   ÚsuppressÚImportErrorÚpolars.polarsrv   r   r   r   r   r   r   r   r   rŠ   r    r¿   r2   r0   r.   ú<module>rÐ      st  ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *à Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ 3Ð 3Ð 3Ð 3Ð 3Ð 3à€ZÔ˜Ñ%Ô%ð  ð  ØÐÐÐÐÐð ð  ð  ñ  ô  ð  ð  ð  ð  ð  ð  øøøð  ð  ð  ð  ð ð CØ(Ð(Ð(Ð(Ð(Ð(à9Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9Ð9ØBÐBÐBÐBÐBÐBÐBÐBÐBÐBð #ØØðXð Xð Xð Xð Xð Xð| Ø(-ð	ð ð ð ð ð ðJ Ø7;Ø(-ðsFð sFð sFð sFð sFð sFð sFð sFs   Á%A8Á8A<Á?A<