
    [i ?              
         U d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZ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 d dlmZmZ d dlmZ d dl m!Z! e	rd dl"m#Z#m$Z$ d dl%m&Z& d dl m'Z'm(Z( d dl)m*Z*m+Z+ e
Z,de-d<   	 ed    Z.de-d<   ed   Z/de-d<   ee.e/f   Z0de-d<   d Z1de-d<   dZ2de-d<    G d deeeeeef         Z3 G d deeef         Z4y)    )annotationsNreduce)chain)TYPE_CHECKINGAnyLiteralProtocoloverload)EagerNamespace)combine_alias_output_namescombine_evaluate_output_namesPandasLikeDataFramePandasLikeExpr)PandasSelectorNamespacePandasLikeSeries)NativeDataFrameTNativeSeriesT)is_non_nullable_boolean)
zip_strict)IterableSequence)	TypeAlias)ImplementationVersion)	IntoDTypePythonLiteralr   
Incomplete	_Vertical   _HorizontalAxisVERTICAL
HORIZONTALc                      e Zd Zedd       Zedd       Zedd       Zedd       ZddZddZ	ddZ
ddZdd	Z	 	 	 	 	 	 dd
Z	 	 	 	 	 	 ddZddZddZddZedd       Zd dZ	 	 	 	 d!dZd dZ	 	 	 	 	 	 	 	 d"dZ	 d#	 	 	 	 	 	 	 d$dZy)%PandasLikeNamespacec                    t         S Nr   selfs    p/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/narwhals/_pandas_like/namespace.py
_dataframezPandasLikeNamespace._dataframe4   s    ""    c                    t         S r+   r   r,   s    r.   _exprzPandasLikeNamespace._expr8   s    r0   c                    t         S r+   r   r,   s    r.   _serieszPandasLikeNamespace._series<   s    r0   c                ,    t        j                  |       S r+   )r   from_namespacer,   s    r.   	selectorszPandasLikeNamespace.selectors@   s    &55d;;r0   c                     || _         || _        y r+   )_implementation_version)r-   implementationversions      r.   __init__zPandasLikeNamespace.__init__D   s    -r0   c                f    dfd}| j                   j                  |t         t         |       S )Nc                8      fdD        }t        d |      gS )Nc              3  <   K   | ]  } |      D ]  }|   y wr+    ).0r2   sdfs      r.   	<genexpr>z=PandasLikeNamespace.coalesce.<locals>.func.<locals>.<genexpr>J   s     >UEE"IqaIaUs   c                *    | j                  |d d       S )Nstrategylimit	fill_null)xys     r.   <lambda>z<PandasLikeNamespace.coalesce.<locals>.func.<locals>.<lambda>L   s    AKKDK$Mr0   r   )rD   seriesexprss   ` r.   funcz*PandasLikeNamespace.coalesce.<locals>.funcI   s"    >U>FMvV r0   rQ   evaluate_output_namesalias_output_namescontextrD   r   returnzlist[PandasLikeSeries]r2   _from_callabler   r   r-   rP   rQ   s    ` r.   coalescezPandasLikeNamespace.coalesceH   s<    	 zz(("?"G95A	 ) 
 	
r0   c                j     d fdt        fdd d  j                   j                        S )Nc                   t        t        t        t        f      r	 dd l}dd l}ddlm} t        t              rt              n}r |j                        nd }|j                  |g|      }j                  j                         }	|	j                  |j                  j                  |      d| j                   j"                  dd       }
j$                  j'                  |
      S j$                  j)                  gd| j                   j"                  dd 	      }r|j+                        S |S # t        $ r}d}t        |      |d }~ww xY w)
Nr   zqNested structures require pyarrow to be installed for pandas backend. Please install pyarrow: pip install pyarrow)narwhals_to_native_dtype)typeliteralr#   )nameindex)rU   )datara   rb   rU   )
isinstancelisttupledictpandaspyarrowImportErrornarwhals._arrow.utilsr^   r:   arrayr9   to_native_namespaceSeriesarraysArrowExtensionArray_native_framerb   r4   from_nativefrom_iterablecast)rD   pdpaexcmsg_to_arrow_dtypearray_valuepa_dtypepa_arraynspandas_series_nativepandas_like_seriesdtyper-   values               r.   _lit_pandas_seriesz3PandasLikeNamespace.lit.<locals>._lit_pandas_seriesW   sX   %$t!454'( .8u-Ed5k5DI?5$--@t88[M8A ))==?')yyII11(;"**0015 (1 ($ ||//0Dd/SS!%!;!;W&&,,Qq1	 "< " )..u55%%C # 4F  &c*34s   D; ;	EEEc                     |       gS r+   rA   )rD   r   s    r.   rN   z)PandasLikeNamespace.lit.<locals>.<lambda>   s    *2./r0   c                    dgS )Nr`   rA   _dfs    r.   rN   z)PandasLikeNamespace.lit.<locals>.<lambda>   s    ykr0   rS   rT   r;   r<   )rD   r   rW   r   r   r9   r:   )r-   r   r   r   s   ```@r.   litzPandasLikeNamespace.litV   s1    &	&P /"9#//MM
 	
r0   c                T     t         fdd d  j                   j                        S )Nc                n    j                   j                  t        | j                        gddg      gS )Nlenr   )ra   rb   rU   )r4   rs   r   rq   )rD   r-   s    r.   rN   z)PandasLikeNamespace.len.<locals>.<lambda>   s8    **))*+%sD + r0   c                    dgS )Nr   rA   r   s    r.   rN   z)PandasLikeNamespace.len.<locals>.<lambda>   s    ugr0   r   r   r,   s   `r.   r   zPandasLikeNamespace.len   s-    
 #6#//MM

 
	
r0   c                f    dfd}| j                   j                  |t         t         |       S )Nc                     t        j                   fdD              }d |D        }t        t        j                  |      gS )Nc              3  .   K   | ]  } |        y wr+   rA   rB   exprrD   s     r.   rE   zCPandasLikeNamespace.sum_horizontal.<locals>.func.<locals>.<genexpr>   s     $@%$T"X%   c              3  B   K   | ]  }|j                  d dd        yw)r   NrJ   rB   rC   s     r.   rE   zCPandasLikeNamespace.sum_horizontal.<locals>.func.<locals>.<genexpr>   s     DAQ[[D$7   )r   rs   r   operatoradd)rD   itnative_seriesrP   s   `  r.   rQ   z0PandasLikeNamespace.sum_horizontal.<locals>.func   s7    $$$@%$@@BDDM8<<788r0   rR   rV   rX   rZ   s    ` r.   sum_horizontalz"PandasLikeNamespace.sum_horizontal   s<    	9
 zz(("?"G95A	 ) 
 	
r0   c               j    dfd}| j                   j                  |t         t         |       S )Nc                    D cg c]  } ||       D ]  }|  }}}st        d |D              rd}t        |      r	d |D        n
t        |      }t        t        j
                  |      gS c c}}w )Nc              3     K   | ]=  }|j                   j                  d k(  xr |j                         j                          ? ywobjectNnativer   is_nullanyr   s     r.   rE   zCPandasLikeNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>   6      (JPQ(*@qyy{/@@&   AAzwCannot use `ignore_nulls=False` in `all_horizontal` for non-nullable NumPy-backed pandas Series when nulls are present.c              3  \   K   | ]$  }t        |      r|n|j                  d dd       & yw)TNr   rK   r   s     r.   rE   zCPandasLikeNamespace.all_horizontal.<locals>.func.<locals>.<genexpr>   s4       $ 13AT4QU9VV#   *,)r   
ValueErroriterr   r   and_rD   r2   rC   rO   rx   r   rP   ignore_nullss         r.   rQ   z0PandasLikeNamespace.all_horizontal.<locals>.func   s    %*>UEE"IqaIaUF>C (JP( %
 P o%   $ &\  8=="-..# ?   A2rR   rV   rX   r-   r   rP   rQ   s    `` r.   all_horizontalz"PandasLikeNamespace.all_horizontal   s<    	/( zz(("?"G95A	 ) 
 	
r0   c               j    dfd}| j                   j                  |t         t         |       S )Nc                    D cg c]  } ||       D ]  }|  }}}st        d |D              rd}t        |      r	d |D        n
t        |      }t        t        j
                  |      gS c c}}w )Nc              3     K   | ]=  }|j                   j                  d k(  xr |j                         j                          ? ywr   r   r   s     r.   rE   zCPandasLikeNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>   r   r   zwCannot use `ignore_nulls=False` in `any_horizontal` for non-nullable NumPy-backed pandas Series when nulls are present.c              3  \   K   | ]$  }t        |      r|n|j                  d dd       & yw)FNr   r   s     r.   rE   zCPandasLikeNamespace.any_horizontal.<locals>.func.<locals>.<genexpr>   s4       $ 13AUDRV9WW#r   )r   r   r   r   r   or_r   s         r.   rQ   z0PandasLikeNamespace.any_horizontal.<locals>.func   s    %*>UEE"IqaIaUF>C (JP( %
 P o%   $ &\  8<<,--# ?r   rR   rV   rX   r   s    `` r.   any_horizontalz"PandasLikeNamespace.any_horizontal   s<    	.( zz(("?"G95A	 ) 
 	
r0   c                f    dfd}| j                   j                  |t         t         |       S )Nc                    D cg c]  } ||       D ]  }|  }}}d |D        }d |D        }t        t        j                  |      t        t        j                  |      z  gS c c}}w )Nc              3  D   K   | ]  }|j                  d dd        yw)r   NrG   rJ   r   s     r.   rE   zDPandasLikeNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>   s      VAakk!d$k?s    c              3  B   K   | ]  }d |j                         z
    yw)r#   N)r   r   s     r.   rE   zDPandasLikeNamespace.mean_horizontal.<locals>.func.<locals>.<genexpr>   s     <|!a!))+o|r   )r   r   r   )rD   r2   rC   expr_resultsrO   non_narP   s         r.   rQ   z1PandasLikeNamespace.mean_horizontal.<locals>.func   sa    +0D5%%)QA)A5LDVVF<|<F8<<06(,,3OOPP Es   A(rR   rV   rX   rZ   s    ` r.   mean_horizontalz#PandasLikeNamespace.mean_horizontal   s=    	Q zz(("?"G95A	 ) 
 	
r0   c                j     d fd} j                   j                  |t         t                S )Nc                6    t        t        j                   fdD                    }t        j	                  d |D        d      j
                  j                  d      j                  j                        j                  |d   j                        gS )	Nc              3  .   K   | ]  } |        y wr+   rA   r   s     r.   rE   zCPandasLikeNamespace.min_horizontal.<locals>.func.<locals>.<genexpr>        -I54d2h5r   c              3  <   K   | ]  }|j                           y wr+   to_framer   s     r.   rE   zCPandasLikeNamespace.min_horizontal.<locals>.func.<locals>.<genexpr>        6v!v   
horizontalhowr#   axisr;   r<   r   )re   r   rs   r   concatrq   minr9   r:   aliasra   rD   rO   rP   r-   s   ` r.   rQ   z0PandasLikeNamespace.min_horizontal.<locals>.func   s~    %---I5-IIJF KK6v6L   #mCCQCK#'#7#7 MM %q	' r0   rR   rV   rX   rZ   s   `` r.   min_horizontalz"PandasLikeNamespace.min_horizontal   <    
	 zz(("?"G95A	 ) 
 	
r0   c                j     d fd} j                   j                  |t         t                S )Nc                6    t        t        j                   fdD                    }t        j	                  d |D        d      j
                  j                  d      j                  j                        j                  |d   j                        gS )	Nc              3  .   K   | ]  } |        y wr+   rA   r   s     r.   rE   zCPandasLikeNamespace.max_horizontal.<locals>.func.<locals>.<genexpr>  r   r   c              3  <   K   | ]  }|j                           y wr+   r   r   s     r.   rE   zCPandasLikeNamespace.max_horizontal.<locals>.func.<locals>.<genexpr>  r   r   r   r   r#   r   r   r   )re   r   rs   r   r   r   maxr9   r:   r   ra   r   s   ` r.   rQ   z0PandasLikeNamespace.max_horizontal.<locals>.func  s~    %---I5-IIJF KK6v6L   fSSaS[#'#7#7 MM %q	' r0   rR   rV   rX   rZ   s   `` r.   max_horizontalz"PandasLikeNamespace.max_horizontal   r   r0   c                J    | j                   j                         j                  S )zvConcatenate pandas objects along a particular axis.

        Return the **native** equivalent of `pd.concat`.
        )r9   rm   r   r,   s    r.   _concatzPandasLikeNamespace._concat  s     ##779@@@r0   c                   | j                   j                         r'| j                  dk  r| j                  |t        d      S | j                  |t              S )N   Fr   copyr   )r9   	is_pandas_backend_versionr   r&   r-   dfss     r.   _concat_diagonalz$PandasLikeNamespace._concat_diagonal  sI    ))+0E0E0L<<(<??||Ch|//r0   c                  | j                   j                         rQt        j                         5  t        j                  ddt
               | j                  |t              cd d d        S | j                   j                         r'| j                  dk  r| j                  |t        d      S | j                  |t              S # 1 sw Y    xY w)NignorezDThe behavior of array concatenation with empty entries is deprecated)messagecategoryr   r   Fr   )
r9   is_cudfwarningscatch_warningsfilterwarningsFutureWarningr   r'   r   r   r   s     r.   _concat_horizontalz&PandasLikeNamespace._concat_horizontal!  s     '')((*''b*
 ||Cj|9 +* !!++-$2G2G$2N<<*5<AA||Cj|11 +*s   3CCc                  |d   j                   }t        |dd  d      D ]n  \  }}|j                   }t        |      t        |      k(  r||k(  j                         r=d|j	                          d| d|j	                          d}t        |       | j                  j                         r'| j                  dk  r| j                  |t        d	
      S | j                  |t              S )Nr   r#   )startz>unable to vstack, column names don't match:
   - dataframe 0: z
   - dataframe z: 
r   Fr   r   )columns	enumerater   allto_list	TypeErrorr9   r   r   r   r&   )r-   r   cols_0irD   cols_currentrx   s          r.   _concat_verticalz$PandasLikeNamespace._concat_vertical0  s    Qs12wa0EAr::L\"c&k18N7S7S7U))/)9(: ;&&'S<+?+?+A*B"F 
  n$ 1 ))+0E0E0L<<(<??||Ch|//r0   c                   | j                   j                  j                         dfd}| j                  j	                  |t         t         |       S )Nc                   D cg c]  } ||       D ]  }|  }}}|D cg c]  }|j                         }}|D cg c]  }|j                          }}s=t        t        j                  |      }t        fd|      j                  | d       }|gS d t        ||      D        ^}}	|j                  |j                         j                  d|j                  j                  |j                  j                              fd|d d D        }
t        t        j                  d t        |
|	      D        |      }|gS c c}}w c c}w c c}w )Nc                    | z   |z   S r+   rA   )rL   rM   	separators     r.   rN   z>PandasLikeNamespace.concat_str.<locals>.func.<locals>.<lambda>M  s    Q]Q->r0   c              3  H   K   | ]  \  }}|j                  | d         yw Nzip_with)rB   rC   nms      r.   rE   z?PandasLikeNamespace.concat_str.<locals>.func.<locals>.<genexpr>T  s&      '5REArAJJsB'5Rs    "sep)ra   rb   r   c              3  D   K   | ]  }j                  | d         ywr  r  )rB   r  	sep_arrays     r.   rE   z?PandasLikeNamespace.concat_str.<locals>.func.<locals>.<genexpr>_  s!     SNbi00"b9Ns    c              3  ,   K   | ]  \  }}||z     y wr+   rA   )rB   rC   vs      r.   rE   z?PandasLikeNamespace.concat_str.<locals>.func.<locals>.<genexpr>b  s     F'Etq!QU'Es   )rt   r   r   r   r   r  r   _with_native__native_namespace__rn   r   rb   r   r   )rD   r2   rC   r   rO   	null_masknull_mask_resultresult
init_valuevalues
separatorsr  rP   r   r   strings              @r.   rQ   z,PandasLikeNamespace.concat_str.<locals>.funcF  sN   +0D5%%)QA)A5LD.:;laffVnlF;.:;llI;#)(,,	#B  >GPP%%t2 8O%'5?	5R'#
V '33335<<!"(//55(//55	 = 	 TIcrNS
LLFz*f'EF 8O? E;;s   EEErR   rV   )r:   dtypesStringr2   rY   r   r   )r-   r   r   rP   rQ   r  s    ``` @r.   
concat_strzPandasLikeNamespace.concat_strA  s\     %%,,. 	  	D zz(("?"G95A	 ) 
 	
r0   Nc                @    |j                   }| ||      S  |||      S r+   )where)r-   whenthen	otherwiser  s        r.   _if_then_elsez!PandasLikeNamespace._if_then_elseo  s(     !JJ'/uT{KU45KKr0   )rW   ztype[PandasLikeDataFrame])rW   ztype[PandasLikeExpr])rW   ztype[PandasLikeSeries])rW   r   )r;   r   r<   r   rW   None)rP   r   rW   r   )r   r    r   zIntoDType | NonerW   r   )rW   r   )rP   r   r   boolrW   r   )rW   z._NativeConcat[NativeDataFrameT, NativeSeriesT])r   zSequence[NativeDataFrameT]rW   r   )r   z*Sequence[NativeDataFrameT | NativeSeriesT]rW   r   )rP   r   r   strr   r  rW   r   r+   )r  r   r  r   r  zNativeSeriesT | NonerW   r   )__name__
__module____qualname__propertyr/   r2   r4   r7   r=   r[   r   r   r   r   r   r   r   r   r   r   r   r   r  r  rA   r0   r.   r)   r)   +   sE    # #       < < 
/
b


$
48
	
<
$
48
	
<

(
( A A0
2=2	20",
$,
14,
DH,
	,
d +/	LL L (	L
 
Lr0   r)   c                      e Zd Zedd	 	 	 	 	 	 	 d	d       Zedd	 	 	 	 	 	 	 d
d       Zedd	 	 	 	 	 	 	 dd       Zedd	 	 	 	 	 	 	 dd       Zdd	 	 	 	 	 	 	 ddZy)_NativeConcat.)r   c                    y r+   rA   r-   objsr   r   s       r.   __call__z_NativeConcat.__call__z       r0   c                    y r+   rA   r(  s       r.   r*  z_NativeConcat.__call__  s     r0   c                    y r+   rA   r(  s       r.   r*  z_NativeConcat.__call__  r+  r0   c                    y r+   rA   r(  s       r.   r*  z_NativeConcat.__call__  s     ,/r0   Nc                    y r+   rA   r(  s       r.   r*  z_NativeConcat.__call__  s     ,/r0   )r)  zIterable[NativeDataFrameT]r   r"   r   bool | NonerW   r   )r)  zIterable[NativeSeriesT]r   r"   r   r0  rW   r   )r)  *Iterable[NativeDataFrameT | NativeSeriesT]r   r$   r   r0  rW   r   )r)  r1  r   r%   r   r0  rW   z NativeDataFrameT | NativeSeriesT)r!  r"  r#  r   r*  rA   r0   r.   r&  r&  y  s$     ( 	
  
  UX+6?GR	    8 	
  
    /8/ 	/
 / 
*/ / !/8/ 	/
 / 
*/r0   r&  )5
__future__r   r   r   	functoolsr   	itertoolsr   typingr   r   r	   r
   r   narwhals._compliantr   narwhals._expression_parsingr   r   narwhals._pandas_like.dataframer   narwhals._pandas_like.exprr   narwhals._pandas_like.selectorsr   narwhals._pandas_like.seriesr   narwhals._pandas_like.typingr   r   narwhals._pandas_like.utilsr   narwhals._utilsr   collections.abcr   r   typing_extensionsr   r   r   narwhals.typingr   r    r!   __annotations__r"   r$   r%   r&   r'   r)   r&  rA   r0   r.   <module>rC     s    "     B B . @ 5 C 9 H ? &2+78 
I  > qz	9 ! Y #)[01i 1) 
K KL		KL\
$/H-}<= $/r0   