o
    $&]i5                  
   @  s  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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rd d	l%m&Z&m'Z'm(Z( d d
l)m*Z* d dl+Z,d dl-Z.d dl/Z0d dl1m2Z2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8 d dlm9Z9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZH G dd de4eedf ZIeddddZJg dZKG dd ded eee ed eee ZLG dd deLe ee ZMG d d! d!e e e!e eeef ZNG d"d# d#eNeef eeef ZOG d$d% d%eNeef e	e eeef ZPG d&d' d'eNeef e
e eeef ZQG d(d) d)eNeef ee eeef ZRG d*d+ d+eNeef ee eeef ZSG d,d- d-eNeef ee eeef ZTG d.d/ d/eeeJf ZUdS )0    )annotations)TYPE_CHECKINGAnyGenericLiteralProtocol)CatNamespaceDateTimeNamespaceListNamespaceStringNamespaceStructNamespace)CompliantColumn)CompliantSeriesT_coEagerDataFrameAnyEagerSeriesT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PythonLiteralRollingInterpolationMethodSizedMultiIndexSelector_1DArray_SliceIndexc                   @  s   e Zd ZU ded< ded< dS )HistDataz/NotRequired[list[float] | _1DArray | list[Any]]
breakpointz2NativeSeriesT | _1DArray | _CountsT_co | list[Any]countN)__name__
__module____qualname____annotations__ r<   r<   X/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/narwhals/_compliant/series.pyr5   8   s   
 r5   _CountsT_coIterable[Any]T)bound	covariant)	CompliantSeriesEagerSeriesEagerSeriesCatNamespaceEagerSeriesDateTimeNamespaceEagerSeriesHistEagerSeriesListNamespaceEagerSeriesNamespaceEagerSeriesStringNamespaceEagerSeriesStructNamespacec                   @  s  e Zd ZU ded< edddZddd	ZdddZedddZ	dddZ
dddZdddZedddZedd!d"Zdd'd(Zdd+d,Zdd/d0Zdd2d3Zdd5d6Zedd8d9Zed:d;d<dd@dAZddBdCZddDdEZddFdGZddHdIZddJdKZddLdMZddPdQZddRdSZddTdUZddVdWZddXdYZ dd[d\Z!dd]d^Z"dd_d`Z#ddcddZ$ddedfZ%ddgdhZ&ddjdkZ'ddndoZ(ddqdrZ)ddsdtZ*ddudvZ+ddxdyZ,ddzd{Z-dd|d}Z.dd~dZ/dddZ0dddZ1dddZ2dddZ3dddZ4dddZ5dddZ6dddZ7dddZ8dddZ9dddZ:dddZ;dddZ<dddZ=dddZ>dddZ?dddddZ@dddZAdddZBdddZCeDdddƄZEeDdddɄZFd;S )rB   r(   _implementationreturnr   c                 C     d S Nr<   selfr<   r<   r=   nativeW      zCompliantSeries.nativer$   c                 C  s   | S rN   r<   rO   r<   r<   r=   __narwhals_series__Y   rR   z#CompliantSeries.__narwhals_series__r"   c                 C  rM   rN   r<   rO   r<   r<   r=   __native_namespace__\       z$CompliantSeries.__native_namespace__datacontextr*   c               C  rM   rN   r<   clsrV   rW   r<   r<   r=   from_native]   rR   zCompliantSeries.from_nativeSeries[NativeSeriesT]c                 C  s   | j j| ddS )Nfull)level)_versionseriesrO   r<   r<   r=   to_narwhals_   s   zCompliantSeries.to_narwhalsr_   r   c                 C  rM   rN   r<   rP   r_   r<   r<   r=   _with_nativeb   rU   zCompliantSeries._with_nativeversionr)   c                 C  rM   rN   r<   )rP   rc   r<   r<   r=   _with_versionc   rU   zCompliantSeries._with_versionr+   c                 C  rM   rN   r<   rO   r<   r<   r=   dtypef   rR   zCompliantSeries.dtypestrc                 C  rM   rN   r<   rO   r<   r<   r=   nameh   rR   zCompliantSeries.namere   copybool | Noner3   c                C  rM   rN   r<   )rP   re   rh   r<   r<   r=   	__array__j   rU   zCompliantSeries.__array__otherboolc                 C  rM   rN   r<   rP   rk   r<   r<   r=   __contains__k   rU   zCompliantSeries.__contains__itemMultiIndexSelector[Self]c                 C  rM   rN   r<   rP   ro   r<   r<   r=   __getitem__l   rU   zCompliantSeries.__getitem__Iterator[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   __iter__m   rU   zCompliantSeries.__iter__intc                 C  s
   t | jS rN   )lenrQ   rO   r<   r<   r=   __len__n      
zCompliantSeries.__len__r-   c               C  rM   rN   r<   rX   r<   r<   r=   
from_numpyq   rR   zCompliantSeries.from_numpy N)rg   re   r?   rg   IntoDType | Nonec               C  rM   rN   r<   )rY   rV   rW   rg   re   r<   r<   r=   from_iterables   s   	zCompliantSeries.from_iterablec                 C  rM   rN   r<   rm   r<   r<   r=   __radd__}   rU   zCompliantSeries.__radd__c                 C  rM   rN   r<   rm   r<   r<   r=   __rand__~   rU   zCompliantSeries.__rand__c                 C  rM   rN   r<   rm   r<   r<   r=   __rmul__   rU   zCompliantSeries.__rmul__c                 C  rM   rN   r<   rm   r<   r<   r=   __ror__   rU   zCompliantSeries.__ror__c                 C  rM   rN   r<   rO   r<   r<   r=   all   rU   zCompliantSeries.allc                 C  rM   rN   r<   rO   r<   r<   r=   any   rU   zCompliantSeries.anyignore_nullsr0   c                C  rM   rN   r<   )rP   r   r<   r<   r=   	any_value   rU   zCompliantSeries.any_valuec                 C  rM   rN   r<   rO   r<   r<   r=   arg_max   rU   zCompliantSeries.arg_maxc                 C  rM   rN   r<   rO   r<   r<   r=   arg_min   rU   zCompliantSeries.arg_minc                 C  rM   rN   r<   rO   r<   r<   r=   arg_true   rU   zCompliantSeries.arg_truec                 C  rM   rN   r<   rO   r<   r<   r=   r7      rU   zCompliantSeries.count	predicatec                 C  rM   rN   r<   )rP   r   r<   r<   r=   filter   rU   zCompliantSeries.filterc                 C  rM   rN   r<   rO   r<   r<   r=   first   rU   zCompliantSeries.firstc                 C  rM   rN   r<   rO   r<   r<   r=   last   rU   zCompliantSeries.lastnoffsetc                 C  rM   rN   r<   )rP   r   r   r<   r<   r=   gather_every   rU   zCompliantSeries.gather_everyc                 C  rM   rN   r<   rP   r   r<   r<   r=   head   rU   zCompliantSeries.headc                 C  s   |   dkS Nr   )rv   rO   r<   r<   r=   is_empty      zCompliantSeries.is_empty
descendingc                C  rM   rN   r<   )rP   r   r<   r<   r=   	is_sorted   rU   zCompliantSeries.is_sortedindex
int | Nonec                 C  rM   rN   r<   )rP   r   r<   r<   r=   ro      rU   zCompliantSeries.itemfloat | Nonec                 C  rM   rN   r<   rO   r<   r<   r=   kurtosis   rU   zCompliantSeries.kurtosisc                 C  rM   rN   r<   rO   r<   r<   r=   rv      rU   zCompliantSeries.lenc                 C  rM   rN   r<   rO   r<   r<   r=   max   rU   zCompliantSeries.maxfloatc                 C  rM   rN   r<   rO   r<   r<   r=   mean   rU   zCompliantSeries.meanc                 C  rM   rN   r<   rO   r<   r<   r=   median   rU   zCompliantSeries.medianc                 C  rM   rN   r<   rO   r<   r<   r=   min   rU   zCompliantSeries.minc                 C  rM   rN   r<   rO   r<   r<   r=   n_unique   rU   zCompliantSeries.n_uniquec                 C  rM   rN   r<   rO   r<   r<   r=   
null_count   rU   zCompliantSeries.null_countquantileinterpolationr1   c                 C  rM   rN   r<   )rP   r   r   r<   r<   r=   r         zCompliantSeries.quantilefractionwith_replacementseedc                C  rM   rN   r<   )rP   r   r   r   r   r<   r<   r=   sample      zCompliantSeries.sampleindicesint | Sequence[int]valuesc                 C  rM   rN   r<   )rP   r   r   r<   r<   r=   scatter   rU   zCompliantSeries.scatterc                 C  rM   rN   r<   r   r<   r<   r=   shift   rU   zCompliantSeries.shiftc                 C  rM   rN   r<   rO   r<   r<   r=   skew   rU   zCompliantSeries.skew
nulls_lastc                C  rM   rN   r<   )rP   r   r   r<   r<   r=   sort   rU   zCompliantSeries.sortddofc                C  rM   rN   r<   rP   r   r<   r<   r=   std   rU   zCompliantSeries.stdc                 C  rM   rN   r<   rO   r<   r<   r=   sum   rU   zCompliantSeries.sumc                 C  rM   rN   r<   r   r<   r<   r=   tail   rU   zCompliantSeries.tailpa.Array[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   to_arrow   rU   zCompliantSeries.to_arrow	separator
drop_first'CompliantDataFrame[Self, Any, Any, Any]c                C  rM   rN   r<   )rP   r   r   r<   r<   r=   
to_dummies   r   zCompliantSeries.to_dummiesc                 C  rM   rN   r<   rO   r<   r<   r=   to_frame   rU   zCompliantSeries.to_frame	list[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   to_list   rU   zCompliantSeries.to_listpd.Series[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   	to_pandas   rU   zCompliantSeries.to_pandas	pl.Seriesc                 C  rM   rN   r<   rO   r<   r<   r=   	to_polars   rU   zCompliantSeries.to_polarsF)maintain_orderr   c                C  rM   rN   r<   )rP   r   r<   r<   r=   unique   rU   zCompliantSeries.uniquer   parallel
str | None	normalizec                C  rM   rN   r<   )rP   r   r   rg   r   r<   r<   r=   value_counts   r   zCompliantSeries.value_countsc                C  rM   rN   r<   r   r<   r<   r=   var   rU   zCompliantSeries.varmaskc                 C  rM   rN   r<   )rP   r   rk   r<   r<   r=   zip_with   rU   zCompliantSeries.zip_withbinslist[float]include_breakpointc                C     dS )z(`Series.hist(bins=..., bin_count=None)`.Nr<   )rP   r   r   r<   r<   r=   hist_from_bins      zCompliantSeries.hist_from_bins	bin_countc                C  r   )z(`Series.hist(bins=None, bin_count=...)`.Nr<   )rP   r   r   r<   r<   r=   hist_from_bin_count   r   z#CompliantSeries.hist_from_bin_countrL   r   )rL   r$   )rL   r"   )rV   r   rW   r*   rL   r$   )rL   r[   )r_   r   rL   r$   )rc   r)   rL   r$   )rL   r+   )rL   rf   )re   r   rh   ri   rL   r3   )rk   r   rL   rl   )ro   rp   rL   r   )rL   rs   )rL   ru   )rV   r-   rW   r*   rL   r$   )
rV   r?   rW   r*   rg   rf   re   r{   rL   r$   )rk   r   rL   r$   rL   rl   )r   rl   rL   r0   )r   r   rL   r$   )rL   r0   )r   ru   r   ru   rL   r$   )r   ru   rL   r$   )r   rl   rL   rl   )r   r   rL   r   )rL   r   )rL   r   )rL   r   )r   r   r   r1   rL   r   )
r   r   r   r   r   rl   r   r   rL   r$   )r   r   r   r   rL   r$   )r   rl   r   rl   rL   r$   )r   ru   rL   r   )rL   r   )r   rf   r   rl   rL   r   )rL   r   )rL   r   )rL   r   )rL   r   )r   rl   rL   r$   )
r   rl   r   rl   rg   r   r   rl   rL   r   )r   r   rk   r   rL   r$   )r   r   r   rl   rL   r   )r   ru   r   rl   rL   r   )Gr8   r9   r:   r;   propertyrQ   rS   rT   classmethodrZ   r`   rb   rd   re   rg   rj   rn   rr   rt   rw   ry   r|   r}   r~   r   r   r   r   r   r   r   r   r7   r   r   r   r   r   r   r   ro   r   rv   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=   rB   L   s   
 	










	











































rB   )r3   r-   r[   c                   @  s   e Zd ZU ded< ded< ded< ded< ed9ddZed:ddZd;ddZddd<ddZ	d=ddZ
d>d d!Zd?d#d$Zd@d'd(ZedAd*d+ZedBd-d.ZedCd0d1ZedDd3d4ZedEd6d7Zd8S )FrC   r   _native_seriesr(   rK   r)   r^   rl   
_broadcastrL   tuple[int, ...]c                 C  
   | j  S rN   )rK   _backend_versionrO   r<   r<   r=   r         
zEagerSeries._backend_versionr_   r$   Sequence[Self]c                 G  r   )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<   )rY   r_   r<   r<   r=   _align_full_broadcast   s   z!EagerSeries._align_full_broadcastvaluec                 C  s   | j |g| j| dS )N)rg   rW   )r|   rg   )rP   r   r<   r<   r=   _from_scalar   s   zEagerSeries._from_scalarF)preserve_broadcastr   r   c                C  r   )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<   )rP   r_   r   r<   r<   r=   rb      s   zEagerSeries._with_native2EagerNamespace[Any, Self, Any, Any, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   __narwhals_namespace__   r   z"EagerSeries.__narwhals_namespace__rows&SizedMultiIndexSelector[NativeSeriesT]c                 C  rM   rN   r<   rP   r   r<   r<   r=   _gather   rU   zEagerSeries._gather_SliceIndex | rangec                 C  rM   rN   r<   r   r<   r<   r=   _gather_slice   rU   zEagerSeries._gather_slicero   rp   c                 C  sJ   t |ttfr| |S t|r| |jS t|r| |S t| d S rN   )	
isinstancesliceranger   r   r   rQ   r   r   rq   r<   r<   r=   rr      s   

zEagerSeries.__getitem__/EagerSeriesStringNamespace[Self, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   rf     rR   zEagerSeries.str1EagerSeriesDateTimeNamespace[Self, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   dt  rR   zEagerSeries.dt,EagerSeriesCatNamespace[Self, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   cat
  rR   zEagerSeries.cat-EagerSeriesListNamespace[Self, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   list  rR   zEagerSeries.list/EagerSeriesStructNamespace[Self, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   struct  rR   zEagerSeries.structNrL   r   )r_   r$   rL   r   )r   r   rL   r$   )r_   r   r   rl   rL   r$   )rL   r   )r   r   rL   r$   )r   r   rL   r$   )ro   rp   rL   r$   )rL   r   )rL   r   )rL   r   )rL   r   )rL   r   )r8   r9   r:   r;   r   r   r   r   r   rb   r   r   r   rr   rf   r   r   r   r   r<   r<   r<   r=   rC      s4   
 




	rC   c                   @  sf   e Zd ZU ded< edddZedddZedd
dZedddZedddZ	dddZ
dS )_SeriesNamespacer   _compliant_seriesrL   c                 C  s   | j S rN   r   rO   r<   r<   r=   	compliant  s   z_SeriesNamespace.compliantr(   c                 C     | j jS rN   )r   rK   rO   r<   r<   r=   implementation     z_SeriesNamespace.implementationr   c                 C  r   rN   )r   r   rO   r<   r<   r=   backend_version!  r   z _SeriesNamespace.backend_versionr)   c                 C  r   rN   )r   r^   rO   r<   r<   r=   rc   %  r   z_SeriesNamespace.versionr   c                 C  r   rN   )r   rQ   rO   r<   r<   r=   rQ   )  r   z_SeriesNamespace.nativer_   r   c                C  s   | j |S rN   )r   rb   ra   r<   r<   r=   with_native-  r   z_SeriesNamespace.with_nativeN)rL   r   )rL   r(   r   )rL   r)   )rL   r   )r_   r   rL   r   )r8   r9   r:   r;   r   r   r   r   rc   rQ   r   r<   r<   r<   r=   r     s   
 r   c                   @  s    e Zd ZU ded< d	ddZdS )
rH   r   r   r_   rL   Nonec                C  s
   || _ d S rN   r   ra   r<   r<   r=   __init__7  rx   zEagerSeriesNamespace.__init__N)r_   r   rL   r  )r8   r9   r:   r;   r  r<   r<   r<   r=   rH   1  s   
 rH   c                   @     e Zd ZdS )rD   Nr8   r9   r:   r<   r<   r<   r=   rD   ;      rD   c                   @  r  )rE   Nr  r<   r<   r<   r=   rE   B  r  rE   c                   @  r  )rG   Nr  r<   r<   r<   r=   rG   I  r  rG   c                   @  r  )rI   Nr  r<   r<   r<   r=   rI   P  r  rI   c                   @  r  )rJ   Nr  r<   r<   r<   r=   rJ   W  r  rJ   c                   @  s   e Zd ZU ded< ded< ded< ed6d	d
Zed7ddZd8ddZddd9ddZ	d:dd Z
d;d!d"Zd<d%d&Zd=d)d*Zd>d,d-Zd?d/d0Zd@d1d2ZdAd3d4Zd5S )BrF   EagerSeries[NativeSeriesT]_seriesrl   _breakpoint$HistData[NativeSeriesT, _CountsT_co]_datarL   r   c                 C  r   rN   )r  rQ   rO   r<   r<   r=   rQ   c  r   zEagerSeriesHist.nativer_   r   r$   c                C  s   |  | }||_||_|S rN   )__new__r  r  )rY   r_   r   objr<   r<   r=   from_seriesg  s   
zEagerSeriesHist.from_seriesr   c                 C  rM   rN   r<   rO   r<   r<   r=   r   p  rU   zEagerSeriesHist.to_frameboth)closedstartr   endnum_samplesru   r  Literal['both', 'none']r3   c                C  rM   rN   r<   )rP   r  r  r  r  r<   r<   r=   _linear_spaceq  r   zEagerSeriesHist._linear_spacec                 C  rM   rN   r<   rO   r<   r<   r=   is_empty_series{  rU   zEagerSeriesHist.is_empty_seriesc                 C  s   | j rg g dS dg iS )N)r6   r7   r7   )r  rO   r<   r<   r=   
data_empty~  s   zEagerSeriesHist.data_emptyargint | list[float]c                C  rM   rN   r<   )rP   r  r<   r<   r=   series_empty  r   zEagerSeriesHist.series_emptyr   r   c                C  sB   t |dkr|  | _| S |  r| || _| S | || _| S )N   )rv   r  r
  r  r  _calculate_histrP   r   r<   r<   r=   	with_bins  s   
zEagerSeriesHist.with_binsr   c                C  sD   |dkr|   | _| S |  r| || _| S | | || _| S r   )r  r
  r  r  r  _calculate_binsrP   r   r<   r<   r=   with_bin_count  s   
zEagerSeriesHist.with_bin_countlist[float] | _1DArrayc                C  s,   t |tr| dd|d n|}|dd  S )Nr   r  )r   ru   r  )rP   r  r   r<   r<   r=   _calculate_breakpoint  s    z%EagerSeriesHist._calculate_breakpointc                 C  rM   rN   r<   r  r<   r<   r=   r    rU   zEagerSeriesHist._calculate_binsc                 C  rM   rN   r<   r  r<   r<   r=   r    r   zEagerSeriesHist._calculate_histNr   )r_   r  r   rl   rL   r$   )rL   r   )
r  r   r  r   r  ru   r  r  rL   r3   r   )rL   r	  )r  r  rL   r	  )r   r   rL   r$   )r   ru   rL   r$   )r  r  rL   r!  )r   ru   rL   r3   )r   r!  rL   r	  )r8   r9   r:   r;   r   rQ   r   r  r   r  r  r  r  r  r   r"  r  r  r<   r<   r<   r=   rF   ^  s&   
 






	
	
rF   )V
__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   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   r4   r5   r>   __all__rB   rC   r   rH   rD   rE   rG   rI   rJ   rF   r<   r<   r<   r=   <module>   s     (

G



















