
    Wh=5                       d dl mZ d dlmZmZmZmZ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mZmZmZ d dlmZmZmZmZ d dlmZmZ d dlmZm Z m!Z!m"Z"m#Z# erkd d	l$m%Z%m&Z&m'Z' d d
l(m)Z) d dl*Z+d dl,Z-d dl.Z/d dl0m1Z1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7 d dlm8Z8m9Z9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF  G d de3eedf         ZG eddd      ZHg dZI G d ded   eee   ed   eee         ZJ G d deJe   ee         ZK G d  d!ee   e e   eeef         ZL G d" d#eLeef   eeef         ZM G d$ d%eLeef   e	e   eeef         ZN G d& d'eLeef   e
e   eeef         ZO G d( d)eLeef   ee   eeef         ZP G d* d+eLeef   ee   eeef         ZQ G d, d-eLeef   ee   eeef         ZR G d. d/eeeHf         ZSy)0    )annotations)TYPE_CHECKINGAnyGenericLiteralProtocol)CatNamespaceDateTimeNamespaceListNamespaceStringNamespaceStructNamespace)CompliantColumn)CompliantSeriesT_coEagerDataFrameAnyEagerSeriesT_coNativeSeriesTNativeSeriesT_co)FromIterable
FromNativeNumpyConvertible
ToNarwhals)TypeVarassert_never)_StoresCompliant_StoresNativeis_compliant_seriesis_sized_multi_index_selectorunstable)IterableIteratorSequence)
ModuleTypeN)NotRequiredSelf	TypedDict)CompliantDataFrame)EagerNamespace)ImplementationVersion_LimitedContext)DType)Series)Into1DArray	IntoDTypeMultiIndexSelectorRollingInterpolationMethodSizedMultiIndexSelector_1DArray_SliceIndexc                  "    e Zd ZU ded<   ded<   y)HistDataz/NotRequired[list[float] | _1DArray | list[Any]]
breakpointz2NativeSeriesT | _1DArray | _CountsT_co | list[Any]countN)__name__
__module____qualname____annotations__     T/var/www/html/jupyter_env/lib/python3.12/site-packages/narwhals/_compliant/series.pyr5   r5   6   s    CCAAr=   r5   _CountsT_coIterable[Any]T)bound	covariant)	CompliantSeriesEagerSeriesEagerSeriesCatNamespaceEagerSeriesDateTimeNamespaceEagerSeriesHistEagerSeriesListNamespaceEagerSeriesNamespaceEagerSeriesStringNamespaceEagerSeriesStructNamespacec                     e Zd ZU ded<   edEd       ZdFdZdGdZedHd       Z	dIdZ
dJdZdKd	ZedLd
       ZedMd       ZdNdZdOdZdPdZdQdZdRdZedSd       Zeddd	 	 	 	 	 	 	 	 	 dTd       ZdUdZdUdZdUdZdUdZdVdZdVdZdRdZdRdZdFdZdRdZdWd Z dXd!Z!dYd"Z"dVd#Z#dZd$Z$d[d%Z%d\d&Z&dRd'Z'd]d(Z(d^d)Z)d^d*Z*d]d+Z+dRd,Z,dRd-Z-	 	 	 	 	 	 d_d.Z.	 	 	 	 	 	 	 	 	 	 d`d/Z/dad0Z0dYd1Z1d\d2Z2dbd3Z3dcd4Z4d^d5Z5dYd6Z6ddd7Z7	 	 	 	 	 	 ded8Z8dfd9Z9dgd:Z:dhd;Z;did<Z<d=d>djd?Z=	 	 	 	 	 	 	 	 	 	 dkd@Z>dcdAZ?dldBZ@eA	 	 	 	 	 	 dmdC       ZBeA	 	 	 	 	 	 dndD       ZCy)orC   r(   _implementationc                     y Nr<   selfs    r>   nativezCompliantSeries.nativeU   s    '*r=   c                    | S rO   r<   rP   s    r>   __narwhals_series__z#CompliantSeries.__narwhals_series__W   s    r=   c                     y rO   r<   rP   s    r>   __native_namespace__z$CompliantSeries.__native_namespace__Z       r=   c                   y rO   r<   clsdatacontexts      r>   from_nativezCompliantSeries.from_native[   s    WZr=   c                <    | j                   j                  | d      S )Nfull)level)_versionseriesrP   s    r>   to_narwhalszCompliantSeries.to_narwhals]   s    }}##D#77r=   c                     y rO   r<   rQ   rb   s     r>   _with_nativezCompliantSeries._with_native`   rW   r=   c                     y rO   r<   )rQ   versions     r>   _with_versionzCompliantSeries._with_versiona   rW   r=   c                     y rO   r<   rP   s    r>   dtypezCompliantSeries.dtyped   s    !r=   c                     y rO   r<   rP   s    r>   namezCompliantSeries.namef   s    r=   c                    y rO   r<   )rQ   rk   copys      r>   	__array__zCompliantSeries.__array__h   rW   r=   c                     y rO   r<   rQ   others     r>   __contains__zCompliantSeries.__contains__i   rW   r=   c                     y rO   r<   rQ   items     r>   __getitem__zCompliantSeries.__getitem__j   rW   r=   c                     y rO   r<   rP   s    r>   __iter__zCompliantSeries.__iter__k   rW   r=   c                ,    t        | j                        S rO   )lenrR   rP   s    r>   __len__zCompliantSeries.__len__l   s    4;;r=   c                   y rO   r<   rY   s      r>   
from_numpyzCompliantSeries.from_numpyo   s    TWr=    N)rm   rk   c                   y rO   r<   )rZ   r[   r\   rm   rk   s        r>   from_iterablezCompliantSeries.from_iterableq   s     r=   c                     y rO   r<   rr   s     r>   __radd__zCompliantSeries.__radd__{   rW   r=   c                     y rO   r<   rr   s     r>   __rand__zCompliantSeries.__rand__|   rW   r=   c                     y rO   r<   rr   s     r>   __rmul__zCompliantSeries.__rmul__}   rW   r=   c                     y rO   r<   rr   s     r>   __ror__zCompliantSeries.__ror__~   rW   r=   c                     y rO   r<   rP   s    r>   allzCompliantSeries.all   rW   r=   c                     y rO   r<   rP   s    r>   anyzCompliantSeries.any   rW   r=   c                     y rO   r<   rP   s    r>   arg_maxzCompliantSeries.arg_max   rW   r=   c                     y rO   r<   rP   s    r>   arg_minzCompliantSeries.arg_min   rW   r=   c                     y rO   r<   rP   s    r>   arg_truezCompliantSeries.arg_true   rW   r=   c                     y rO   r<   rP   s    r>   r7   zCompliantSeries.count   rW   r=   c                     y rO   r<   )rQ   	predicates     r>   filterzCompliantSeries.filter   rW   r=   c                     y rO   r<   )rQ   noffsets      r>   gather_everyzCompliantSeries.gather_every   rW   r=   c                     y rO   r<   rQ   r   s     r>   headzCompliantSeries.head   rW   r=   c                (    | j                         dk(  S Nr   )r|   rP   s    r>   is_emptyzCompliantSeries.is_empty   s    xxzQr=   c                    y rO   r<   )rQ   
descendings     r>   	is_sortedzCompliantSeries.is_sorted   rW   r=   c                     y rO   r<   )rQ   indexs     r>   rw   zCompliantSeries.item   rW   r=   c                     y rO   r<   rP   s    r>   kurtosiszCompliantSeries.kurtosis   rW   r=   c                     y rO   r<   rP   s    r>   r|   zCompliantSeries.len   rW   r=   c                     y rO   r<   rP   s    r>   maxzCompliantSeries.max   rW   r=   c                     y rO   r<   rP   s    r>   meanzCompliantSeries.mean   rW   r=   c                     y rO   r<   rP   s    r>   medianzCompliantSeries.median   rW   r=   c                     y rO   r<   rP   s    r>   minzCompliantSeries.min   rW   r=   c                     y rO   r<   rP   s    r>   n_uniquezCompliantSeries.n_unique   rW   r=   c                     y rO   r<   rP   s    r>   
null_countzCompliantSeries.null_count   rW   r=   c                     y rO   r<   )rQ   quantileinterpolations      r>   r   zCompliantSeries.quantile   s    r=   c                    y rO   r<   )rQ   r   fractionwith_replacementseeds        r>   samplezCompliantSeries.sample   s     r=   c                     y rO   r<   )rQ   indicesvaluess      r>   scatterzCompliantSeries.scatter   rW   r=   c                     y rO   r<   r   s     r>   shiftzCompliantSeries.shift   rW   r=   c                     y rO   r<   rP   s    r>   skewzCompliantSeries.skew   rW   r=   c                    y rO   r<   )rQ   r   
nulls_lasts      r>   sortzCompliantSeries.sort   rW   r=   c                    y rO   r<   rQ   ddofs     r>   stdzCompliantSeries.std   rW   r=   c                     y rO   r<   rP   s    r>   sumzCompliantSeries.sum   rW   r=   c                     y rO   r<   r   s     r>   tailzCompliantSeries.tail   rW   r=   c                     y rO   r<   rP   s    r>   to_arrowzCompliantSeries.to_arrow   rW   r=   c                    y rO   r<   )rQ   	separator
drop_firsts      r>   
to_dummieszCompliantSeries.to_dummies       25r=   c                     y rO   r<   rP   s    r>   to_framezCompliantSeries.to_frame   rW   r=   c                     y rO   r<   rP   s    r>   to_listzCompliantSeries.to_list   rW   r=   c                     y rO   r<   rP   s    r>   	to_pandaszCompliantSeries.to_pandas   rW   r=   c                     y rO   r<   rP   s    r>   	to_polarszCompliantSeries.to_polars   rW   r=   F)maintain_orderc                    y rO   r<   )rQ   r   s     r>   uniquezCompliantSeries.unique   rW   r=   c                    y rO   r<   )rQ   r   parallelrm   	normalizes        r>   value_countszCompliantSeries.value_counts   r   r=   c                    y rO   r<   r   s     r>   varzCompliantSeries.var   rW   r=   c                     y rO   r<   )rQ   maskrs   s      r>   zip_withzCompliantSeries.zip_with   rW   r=   c                    y)z(`Series.hist(bins=..., bin_count=None)`.Nr<   )rQ   binsinclude_breakpoints      r>   hist_from_binszCompliantSeries.hist_from_bins       
 	r=   c                    y)z(`Series.hist(bins=None, bin_count=...)`.Nr<   )rQ   	bin_countr   s      r>   hist_from_bin_countz#CompliantSeries.hist_from_bin_count   r   r=   returnr   )r   r$   )r   r"   )r[   r   r\   r*   r   r$   )r   Series[NativeSeriesT])rb   r   r   r$   )rh   r)   r   r$   )r   r+   )r   str)rk   r   ro   zbool | Noner   r2   )rs   r   r   bool)rw   MultiIndexSelector[Self]r   r   )r   zIterator[Any])r   int)r[   r-   r\   r*   r   r$   )
r[   r@   r\   r*   rm   r   rk   zIntoDType | Noner   r$   )rs   r   r   r$   r   r   )r   r   r   r$   )r   r   r   r   r   r$   )r   r   r   r$   )r   r   r   r   )r   
int | Noner   r   )r   float | None)r   r   )r   float)r   r   r   r0   r   r   )
r   r   r   r   r   r   r   r   r   r$   )r   zint | Sequence[int]r   r   r   r$   )r   r   r   r   r   r$   )r   r   r   r   )r   zpa.Array[Any])r   r   r   r   r   'CompliantDataFrame[Self, Any, Any, Any])r   r   )r   z	list[Any])r   zpd.Series[Any])r   z	pl.Series)r   r   r   r$   )
r   r   r   r   rm   z
str | Noner   r   r   r   )r   r   rs   r   r   r$   )r   list[float]r   r   r   r   )r   r   r   r   r   r   )Dr8   r9   r:   r;   propertyrR   rT   rV   classmethodr]   rc   rf   ri   rk   rm   rp   rt   rx   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r7   r   r   r   r   r   rw   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>   rC   rC   J   s@    $#* * 6Z Z8 5: ! ! J3E,  W W "&
 !    
  0//.!!#1<' :1+ ""$.H	 	
   
 N('F-',66-16	06 G'.)/4B66'+63=6JN6	06 .: 8<	0  59	0 r=   rC   )r2   r-   r   c                      e Zd ZU ded<   ded<   ded<   ded<   edd	       Zedd
       ZddZdd	 	 	 	 	 ddZ		 	 ddZ
ddZddZd dZed!d       Zed"d       Zed#d       Zed$d       Zed%d       Zy)&rD   r   _native_seriesr(   rM   r)   ra   r   
_broadcastc                6    | j                   j                         S rO   )rM   _backend_versionrP   s    r>   r  zEagerSeries._backend_version   s    ##4466r=   c                     y)a  Ensure all of `series` have the same length (and index if `pandas`).

        Scalars get broadcasted to the full length of the longest Series.

        This is useful when you need to construct a full Series anyway, such as:

            DataFrame.select(...)

        It should not be used in binary operations, such as:

            nw.col("a") - nw.col("a").mean()

        because then it's more efficient to extract the right-hand-side's single element as a scalar.
        Nr<   )rZ   rb   s     r>   _align_full_broadcastz!EagerSeries._align_full_broadcast   s      	r=   c                @    | j                  |g| j                  |       S )N)rm   r\   )r   rm   )rQ   values     r>   _from_scalarzEagerSeries._from_scalar   s     !!5'		4!HHr=   F)preserve_broadcastc                    y)a  Return a new `CompliantSeries`, wrapping the native `series`.

        In cases when operations are known to not affect whether a result should
        be broadcast, we can pass `preserve_broadcast=True`.
        Set this with care - it should only be set for unary expressions which don't
        change length or order, such as `.alias` or `.fill_null`. If in doubt, don't
        set it, you probably don't need it.
        Nr<   )rQ   rb   r  s      r>   rf   zEagerSeries._with_native   s     	r=   c                     y rO   r<   rP   s    r>   __narwhals_namespace__z"EagerSeries.__narwhals_namespace__   s    =@r=   c                     y rO   r<   rQ   rowss     r>   _gatherzEagerSeries._gather   rW   r=   c                     y rO   r<   r  s     r>   _gather_slicezEagerSeries._gather_slice   rW   r=   c                    t        |t        t        f      r| j                  |      S t	        |      r| j                  |j                        S t        |      r| j                  |      S t        |       y rO   )	
isinstancesliceranger  r   r  rR   r   r   rv   s     r>   rx   zEagerSeries.__getitem__   s[    dUEN+%%d++t$<<,,*40<<%%Tr=   c                     y rO   r<   rP   s    r>   r   zEagerSeries.str  s    FIr=   c                     y rO   r<   rP   s    r>   dtzEagerSeries.dt  s    GJr=   c                     y rO   r<   rP   s    r>   catzEagerSeries.cat  s    CFr=   c                     y rO   r<   rP   s    r>   listzEagerSeries.list  s    EHr=   c                     y rO   r<   rP   s    r>   structzEagerSeries.struct	  s    ILr=   Nr   ztuple[int, ...])rb   r$   r   zSequence[Self])r  r   r   r$   )rb   r   r  r   r   r$   )r   z2EagerNamespace[Any, Self, Any, Any, NativeSeriesT])r  z&SizedMultiIndexSelector[NativeSeriesT]r   r$   )r  z_SliceIndex | ranger   r$   )rw   r   r   r$   )r   z/EagerSeriesStringNamespace[Self, NativeSeriesT])r   z1EagerSeriesDateTimeNamespace[Self, NativeSeriesT])r   z,EagerSeriesCatNamespace[Self, NativeSeriesT])r   z-EagerSeriesListNamespace[Self, NativeSeriesT])r   z/EagerSeriesStructNamespace[Self, NativeSeriesT])r8   r9   r:   r;   r  r  r  r
  r  rf   r  r  r  rx   r   r  r   r"  r$  r<   r=   r>   rD   rD      s    ##7 7  "I DI#<@	A	;A QC I IJ JF FH HL Lr=   rD   c                  z    e Zd ZU ded<   ed
d       Zedd       Zedd       Zedd       Zedd       Z	ddZ
y	)_SeriesNamespacer   _compliant_seriesc                    | j                   S rO   r(  rP   s    r>   	compliantz_SeriesNamespace.compliant  s    %%%r=   c                .    | j                   j                  S rO   )r+  rM   rP   s    r>   implementationz_SeriesNamespace.implementation  s    ~~---r=   c                6    | j                   j                         S rO   )r-  r  rP   s    r>   backend_versionz _SeriesNamespace.backend_version  s    ""3355r=   c                .    | j                   j                  S rO   )r+  ra   rP   s    r>   rh   z_SeriesNamespace.version   s    ~~&&&r=   c                .    | j                   j                  S rO   )r(  rR   rP   s    r>   rR   z_SeriesNamespace.native$  s    %%,,,r=   c               8    | j                   j                  |      S rO   )r+  rf   re   s     r>   with_nativez_SeriesNamespace.with_native(  s    ~~**622r=   N)r   r   )r   r(   r%  )r   r)   )r   r   )rb   r   r   r   )r8   r9   r:   r;   r  r+  r-  r/  rh   rR   r3  r<   r=   r>   r'  r'    sq    
 +*& & . . 6 6 ' ' - -3r=   r'  c                       e Zd ZU ded<   ddZy)rI   r   r(  c                   || _         y rO   r*  re   s     r>   __init__zEagerSeriesNamespace.__init__2  s
    !'r=   N)rb   r   r   None)r8   r9   r:   r;   r6  r<   r=   r>   rI   rI   ,  s     '&(r=   rI   c                      e Zd Zy)rE   Nr8   r9   r:   r<   r=   r>   rE   rE   6       r=   rE   c                      e Zd Zy)rF   Nr9  r<   r=   r>   rF   rF   =  r:  r=   rF   c                      e Zd Zy)rH   Nr9  r<   r=   r>   rH   rH   D  r:  r=   rH   c                      e Zd Zy)rJ   Nr9  r<   r=   r>   rJ   rJ   K  r:  r=   rJ   c                      e Zd Zy)rK   Nr9  r<   r=   r>   rK   rK   R  r:  r=   rK   c                      e Zd ZU ded<   ded<   ded<   edd       Ze	 	 	 	 	 	 dd       Zdd	Zd
d	 	 	 	 	 	 	 	 	 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y)"rG   EagerSeries[NativeSeriesT]_seriesr   _breakpoint$HistData[NativeSeriesT, _CountsT_co]_datac                .    | j                   j                  S rO   )rA  rR   rP   s    r>   rR   zEagerSeriesHist.native^  s    ||"""r=   c               D    | j                  |       }||_        ||_        |S rO   )__new__rA  rB  )rZ   rb   r   objs       r>   from_serieszEagerSeriesHist.from_seriesb  s%     kk#,
r=   c                     y rO   r<   rP   s    r>   r   zEagerSeriesHist.to_framek  rW   r=   both)closedc                    y rO   r<   )rQ   startendnum_samplesrL  s        r>   _linear_spacezEagerSeriesHist._linear_spacel  s     r=   c                     y rO   r<   rP   s    r>   is_empty_serieszEagerSeriesHist.is_empty_seriesv  rW   r=   c                ,    | j                   rg g dS dg iS )N)r6   r7   r7   )rB  rP   s    r>   
data_emptyzEagerSeriesHist.data_emptyy  s    262B2Bb2.URTUr=   c                    y rO   r<   )rQ   args     r>   series_emptyzEagerSeriesHist.series_empty~      /2r=   c                   t        |      dk  r| j                         | _        | S | j                         r| j	                  |      | _        | S | j                  |      | _        | S )N   )r|   rU  rD  rS  rX  _calculate_histrQ   r   s     r>   	with_binszEagerSeriesHist.with_bins  sb    t9>*DJ
 	 !!#**40DJ  --d3DJr=   c                   |dk(  r| j                         | _        | S | j                         r| j                  |      | _        | S | j	                  | j                  |            | _        | S r   )rU  rD  rS  rX  r\  _calculate_binsrQ   r   s     r>   with_bin_countzEagerSeriesHist.with_bin_count  si    >*DJ
 	 !!#**95DJ  --d.B.B9.MNDJr=   c               \    t        |t              r| j                  dd|dz         n|}|dd  S )Nr   r[  )r  r   rQ  )rQ   rW  r   s      r>   _calculate_breakpointz%EagerSeriesHist._calculate_breakpoint  s0    4>sC4Ht!!!Qa0cABxr=   c                     y rO   r<   ra  s     r>   r`  zEagerSeriesHist._calculate_bins  rW   r=   c                     y rO   r<   r]  s     r>   r\  zEagerSeriesHist._calculate_hist  rY  r=   Nr   )rb   r@  r   r   r   r$   )r   r   )
rN  r   rO  r   rP  r   rL  zLiteral['both', 'none']r   r2   r   )r   rC  )rW  int | list[float]r   rC  )r   r  r   r$   )r   r   r   r$   )rW  rg  r   list[float] | _1DArray)r   r   r   r2   )r   rh  r   rC  )r8   r9   r:   r;   r  rR   r  rI  r   rQ  rS  rU  rX  r^  rb  rd  r`  r\  r<   r=   r>   rG   rG   Y  s    ''//# # /HL	  1 +1  	 ( 
 +V
3$3	-3 ?3*3	-3r=   rG   )T
__future__r   typingr   r   r   r   r   !narwhals._compliant.any_namespacer	   r
   r   r   r   narwhals._compliant.columnr   narwhals._compliant.typingr   r   r   r   r   narwhals._translater   r   r   r   narwhals._typing_compatr   r   narwhals._utilsr   r   r   r   r   collections.abcr   r    r!   typesr"   pandaspdpolarsplpyarrowpatyping_extensionsr#   r$   r%   narwhals._compliant.dataframer&   narwhals._compliant.namespacer'   r(   r)   r*   narwhals.dtypesr+   narwhals.seriesr,   narwhals.typingr-   r.   r/   r0   r1   r2   r3   r5   r?   __all__rC   rD   r'  rI   rE   rF   rH   rJ   rK   rG   r<   r=   r>   <module>r     sM   " A A  7  W V 9  << >>@<HH%&  B9gm]&BC B
 m?dK
y./}&']yxDM/-0(=2I DMN3()"# "2233>(_&667O--.(_&667!_../_&667o&_../_&667/"_../_&667O$_../_&667O$_../B3h}k9: B3r=   