o
    Lh5                  
   @  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 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.Z/d dl0m1Z1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8 d dl9m:Z: d dlm;Z;m<Z<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZCmDZDmEZEmFZFmGZGmHZHmIZI G dd de3eedf ZJeddddZKg dZLG dd ded eee ed eee ZMG dd  d eMe ee ZNG d!d" d"ee e e eeef ZOG d#d$ d$eOeef eeef ZPG d%d& d&eOeef e	e eeef ZQG d'd( d(eOeef e
e eeef ZRG d)d* d*eOeef ee eeef ZSG d+d, d,eOeef ee eeef ZTG d-d. d.eOeef ee eeef ZUG d/d0 d0eeeKf ZVdS )1    )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)CompliantExpr	EagerExpr)EagerNamespace)ImplementationVersion_LimitedContext)DType)Series)Into1DArray	IntoDTypeMultiIndexSelector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<   [/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/narwhals/_compliant/series.pyr5   7   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eddd	ZedddZdddZdddZ	dddZ
dddZdd d!Zdd#d$Zdd&d'Zdd)d*Zdd-d.Zdd0d1Zedd5d6Zedd8d9Zed:d;d<dd@dAZddCdDZddEdFZddGdHZddIdJZddKdLZddMdNZddOdPZddQdRZddSdTZddUdVZddWdXZ ddZd[Z!dd^d_Z"dd`daZ#ddbdcZ$ddedfZ%ddidjZ&ddldmZ'ddndoZ(ddpdqZ)ddsdtZ*ddudvZ+ddwdxZ,ddydzZ-dd{d|Z.dddZ/dddZ0dddZ1dddZ2dddZ3dddZ4dddZ5dddZ6dddZ7dddZ8dddZ9dddZ:dddZ;dddZ<dddZ=dddddZ>dddZ?dddZ@dddZAeBdddZCeBdddĄZDd;S )rB   r)   _implementationreturnr,   c                 C     d S Nr<   selfr<   r<   r=   dtypeU      zCompliantSeries.dtypestrc                 C  rM   rN   r<   rO   r<   r<   r=   nameW   rR   zCompliantSeries.namer   c                 C  rM   rN   r<   rO   r<   r<   r=   nativeY   rR   zCompliantSeries.nativer#   c                 C  s   | S rN   r<   rO   r<   r<   r=   __narwhals_series__[   rR   z#CompliantSeries.__narwhals_series__r!   c                 C  rM   rN   r<   rO   r<   r<   r=   __native_namespace__^       z$CompliantSeries.__native_namespace__rQ   r   copybool | Noner3   c                C  rM   rN   r<   )rP   rQ   rY   r<   r<   r=   	__array___   rX   zCompliantSeries.__array__otherboolc                 C  rM   rN   r<   rP   r\   r<   r<   r=   __contains__`   rX   zCompliantSeries.__contains__itemMultiIndexSelector[Self]c                 C  rM   rN   r<   rP   r`   r<   r<   r=   __getitem__a   rX   zCompliantSeries.__getitem__Iterator[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   __iter__b   rX   zCompliantSeries.__iter__intc                 C  s
   t | jS rN   )lenrU   rO   r<   r<   r=   __len__c      
zCompliantSeries.__len__seriesc                 C  rM   rN   r<   rP   rj   r<   r<   r=   _with_nativef   rX   zCompliantSeries._with_nativeversionr*   c                 C  rM   rN   r<   )rP   rm   r<   r<   r=   _with_versiong   rX   zCompliantSeries._with_versionCompliantExpr[Any, Self]c                 C  rM   rN   r<   rO   r<   r<   r=   _to_exprh   rX   zCompliantSeries._to_exprdatacontextr+   c               C  rM   rN   r<   clsrq   rr   r<   r<   r=   from_nativei   rR   zCompliantSeries.from_nativer.   c               C  rM   rN   r<   rs   r<   r<   r=   
from_numpyk   rR   zCompliantSeries.from_numpy N)rT   rQ   r?   rT   IntoDType | Nonec               C  rM   rN   r<   )rt   rq   rr   rT   rQ   r<   r<   r=   from_iterablem   s   	zCompliantSeries.from_iterableSeries[NativeSeriesT]c                 C  s   | j j| ddS )Nfull)level)_versionrj   rO   r<   r<   r=   to_narwhalsw      zCompliantSeries.to_narwhalsc                 C  rM   rN   r<   r^   r<   r<   r=   __radd__z   rX   zCompliantSeries.__radd__c                 C  rM   rN   r<   r^   r<   r<   r=   __rand__{   rX   zCompliantSeries.__rand__c                 C  rM   rN   r<   r^   r<   r<   r=   __rmul__|   rX   zCompliantSeries.__rmul__c                 C  rM   rN   r<   r^   r<   r<   r=   __ror__}   rX   zCompliantSeries.__ror__c                 C  rM   rN   r<   rO   r<   r<   r=   all~   rX   zCompliantSeries.allc                 C  rM   rN   r<   rO   r<   r<   r=   any   rX   zCompliantSeries.anyc                 C  rM   rN   r<   rO   r<   r<   r=   arg_max   rX   zCompliantSeries.arg_maxc                 C  rM   rN   r<   rO   r<   r<   r=   arg_min   rX   zCompliantSeries.arg_minc                 C  rM   rN   r<   rO   r<   r<   r=   arg_true   rX   zCompliantSeries.arg_truec                 C  rM   rN   r<   rO   r<   r<   r=   r7      rX   zCompliantSeries.count	predicatec                 C  rM   rN   r<   )rP   r   r<   r<   r=   filter   rX   zCompliantSeries.filternoffsetc                 C  rM   rN   r<   )rP   r   r   r<   r<   r=   gather_every   rX   zCompliantSeries.gather_everyc                 C  rM   rN   r<   rP   r   r<   r<   r=   head   rX   zCompliantSeries.headc                 C  s   |   dkS Nr   )rg   rO   r<   r<   r=   is_empty      zCompliantSeries.is_empty
descendingc                C  rM   rN   r<   )rP   r   r<   r<   r=   	is_sorted   rX   zCompliantSeries.is_sortedindex
int | Nonec                 C  rM   rN   r<   )rP   r   r<   r<   r=   r`      rX   zCompliantSeries.itemfloat | Nonec                 C  rM   rN   r<   rO   r<   r<   r=   kurtosis   rX   zCompliantSeries.kurtosisc                 C  rM   rN   r<   rO   r<   r<   r=   rg      rX   zCompliantSeries.lenc                 C  rM   rN   r<   rO   r<   r<   r=   max   rX   zCompliantSeries.maxfloatc                 C  rM   rN   r<   rO   r<   r<   r=   mean   rX   zCompliantSeries.meanc                 C  rM   rN   r<   rO   r<   r<   r=   median   rX   zCompliantSeries.medianc                 C  rM   rN   r<   rO   r<   r<   r=   min   rX   zCompliantSeries.minc                 C  rM   rN   r<   rO   r<   r<   r=   n_unique   rX   zCompliantSeries.n_uniquec                 C  rM   rN   r<   rO   r<   r<   r=   
null_count   rX   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   rX   zCompliantSeries.scatterc                 C  rM   rN   r<   r   r<   r<   r=   shift   rX   zCompliantSeries.shiftc                 C  rM   rN   r<   rO   r<   r<   r=   skew   rX   zCompliantSeries.skew
nulls_lastc                C  rM   rN   r<   )rP   r   r   r<   r<   r=   sort   rX   zCompliantSeries.sortddofc                C  rM   rN   r<   rP   r   r<   r<   r=   std   rX   zCompliantSeries.stdc                 C  rM   rN   r<   rO   r<   r<   r=   sum   rX   zCompliantSeries.sumc                 C  rM   rN   r<   r   r<   r<   r=   tail   rX   zCompliantSeries.tailpa.Array[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   to_arrow   rX   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   rX   zCompliantSeries.to_frame	list[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   to_list   rX   zCompliantSeries.to_listpd.Series[Any]c                 C  rM   rN   r<   rO   r<   r<   r=   	to_pandas   rX   zCompliantSeries.to_pandas	pl.Seriesc                 C  rM   rN   r<   rO   r<   r<   r=   	to_polars   rX   zCompliantSeries.to_polarsF)maintain_orderr   c                C  rM   rN   r<   )rP   r   r<   r<   r=   unique   rX   zCompliantSeries.uniquer   parallel
str | None	normalizec                C  rM   rN   r<   )rP   r   r   rT   r   r<   r<   r=   value_counts   r   zCompliantSeries.value_countsc                C  rM   rN   r<   r   r<   r<   r=   var   rX   zCompliantSeries.varmaskc                 C  rM   rN   r<   )rP   r   r\   r<   r<   r=   zip_with   rX   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   rS   rL   r   )rL   r#   )rL   r!   )rQ   r   rY   rZ   rL   r3   )r\   r   rL   r]   )r`   ra   rL   r   )rL   rd   )rL   rf   )rj   r   rL   r#   )rm   r*   rL   r#   )rL   ro   )rq   r   rr   r+   rL   r#   )rq   r.   rr   r+   rL   r#   )
rq   r?   rr   r+   rT   rS   rQ   rx   rL   r#   )rL   rz   )r\   r   rL   r#   rL   r]   )r   r   rL   r#   )r   rf   r   rf   rL   r#   )r   rf   rL   r#   )r   r]   rL   r]   )r   r   rL   r   )rL   r   )rL   r   )rL   r   )r   r   r   r1   rL   r   )
r   r   r   r   r   r]   r   r   rL   r#   )r   r   r   r   rL   r#   )r   r]   r   r]   rL   r#   )r   rf   rL   r   )rL   r   )r   rS   r   r]   rL   r   )rL   r   )rL   r   )rL   r   )rL   r   )r   r]   rL   r#   )
r   r]   r   r]   rT   r   r   r]   rL   r   )r   r   r\   r   rL   r#   )r   r   r   r]   rL   r   )r   rf   r   r]   rL   r   )Er8   r9   r:   r;   propertyrQ   rT   rU   rV   rW   r[   r_   rc   re   rh   rl   rn   rp   classmethodru   rv   ry   r~   r   r   r   r   r   r   r   r   r   r7   r   r   r   r   r   r`   r   rg   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   K   s   
 










	









































rB   )r3   r.   rz   c                   @  s   e Zd ZU ded< ded< ded< ded< ed<ddZed=ddZd>ddZddd?ddZ	d@ddZ
dAdd ZdBd#d$ZdCd&d'ZdDd*d+ZedEd-d.ZedFd0d1ZedGd3d4ZedHd6d7ZedId9d:Zd;S )JrC   r   _native_seriesr)   rK   r*   r}   r]   
_broadcastrL   tuple[int, ...]c                 C  
   | j  S rN   )rK   _backend_versionrO   r<   r<   r=   r         
zEagerSeries._backend_versionrj   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<   )rt   rj   r<   r<   r=   _align_full_broadcast   s   z!EagerSeries._align_full_broadcastvaluec                 C  s   | j |g| j| dS )N)rT   rr   )ry   rT   )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   rj   r   r<   r<   r=   rl      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__EagerExpr[Any, Any]c                 C  s   |   j| S rN   )r   _expr_from_seriesrO   r<   r<   r=   rp      r   zEagerSeries._to_exprrows&SizedMultiIndexSelector[NativeSeriesT]c                 C  rM   rN   r<   rP   r   r<   r<   r=   _gather   rX   zEagerSeries._gather_SliceIndex | rangec                 C  rM   rN   r<   r   r<   r<   r=   _gather_slice   rX   zEagerSeries._gather_slicer`   ra   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   rU   r   r   rb   r<   r<   r=   rc      s   

zEagerSeries.__getitem__/EagerSeriesStringNamespace[Self, NativeSeriesT]c                 C  rM   rN   r<   rO   r<   r<   r=   rS     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   )rj   r#   rL   r   )r   r   rL   r#   )rj   r   r   r]   rL   r#   )rL   r   )rL   r   )r   r   rL   r#   )r   r   rL   r#   )r`   ra   rL   r#   )rL   r   )rL   r   )rL   r   )rL   r   )rL   r   )r8   r9   r:   r;   r   r   r   r   r   rl   r   rp   r   r   rc   rS   r   r   r   r   r<   r<   r<   r=   rC      s6   
 





	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=   rm      r   z_SeriesNamespace.versionr   c                 C  r   rN   )r   rU   rO   r<   r<   r=   rU   $  r   z_SeriesNamespace.nativerj   r   c                C  s   | j |S rN   )r   rl   rk   r<   r<   r=   with_native(  r   z_SeriesNamespace.with_nativeN)rL   r   )rL   r)   r   )rL   r*   )rL   r   )rj   r   rL   r   )r8   r9   r:   r;   r   r   r   r  rm   rU   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   rj   rL   Nonec                C  s
   || _ d S rN   r   rk   r<   r<   r=   __init__2  ri   zEagerSeriesNamespace.__init__N)rj   r   rL   r  )r8   r9   r:   r;   r  r<   r<   r<   r=   rH   ,  s   
 rH   c                   @     e Zd ZdS )rD   Nr8   r9   r:   r<   r<   r<   r=   rD   6      rD   c                   @  r  )rE   Nr  r<   r<   r<   r=   rE   =  r  rE   c                   @  r  )rG   Nr  r<   r<   r<   r=   rG   D  r  rG   c                   @  r  )rI   Nr  r<   r<   r<   r=   rI   K  r  rI   c                   @  r  )rJ   Nr  r<   r<   r<   r=   rJ   R  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]_seriesr]   _breakpoint$HistData[NativeSeriesT, _CountsT_co]_datarL   r   c                 C  r   rN   )r	  rU   rO   r<   r<   r=   rU   ^  r   zEagerSeriesHist.nativerj   r   r#   c                C  s   |  | }||_||_|S rN   )__new__r	  r
  )rt   rj   r   objr<   r<   r=   from_seriesb  s   
zEagerSeriesHist.from_seriesr   c                 C  rM   rN   r<   rO   r<   r<   r=   r   k  rX   zEagerSeriesHist.to_frameboth)closedstartr   endnum_samplesrf   r  Literal['both', 'none']r3   c                C  rM   rN   r<   )rP   r  r  r  r  r<   r<   r=   _linear_spacel  r   zEagerSeriesHist._linear_spacec                 C  rM   rN   r<   rO   r<   r<   r=   is_empty_seriesv  rX   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_emptyy  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   )rg   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   rf   r  )rP   r  r   r<   r<   r=   _calculate_breakpoint  s    z%EagerSeriesHist._calculate_breakpointc                 C  rM   rN   r<   r!  r<   r<   r=   r     rX   zEagerSeriesHist._calculate_binsc                 C  rM   rN   r<   r  r<   r<   r=   r    r   zEagerSeriesHist._calculate_histNr   )rj   r  r   r]   rL   r#   )rL   r   )
r  r   r  r   r  rf   r  r  rL   r3   r   )rL   r  )r  r  rL   r  )r   r   rL   r#   )r   rf   rL   r#   )r  r  rL   r#  )r   rf   rL   r3   )r   r#  rL   r  )r8   r9   r:   r;   r   rU   r   r  r   r  r  r  r  r  r"  r$  r   r  r<   r<   r<   r=   rF   Y  s&   
 






	
	
rF   )W
__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.exprr&   r'   narwhals._compliant.namespacer(   r)   r*   r+   narwhals.dtypesr,   narwhals.seriesr-   narwhals.typingr.   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    $

x
J






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