o
    $&]i                     @  s
  U d dl mZ d dlZd dlZd dlmZmZmZmZ d dl	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 d d
lmZmZmZmZ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( d dl)m*Z*m+Z+ d dl,m-Z- erd dl.m/Z/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5Z6d dl7Z8d dl9Z:d dl;m<Z<m=Z=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZF d dlGmHZH d dlImJZJ d dl$mKZKmLZL d dlMmNZN d dlOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[ dZ\de]d< i ddd dd!d"d#d"d$d%d&d%d'd(d)d(d*d+d,d+d-d.d/d.d0d1d2d1d3d4d5d4d6d7d7d8d8d9Z^i dd7d d7d!d7d#d7d$d7d&d7d'd7d)d7d*d7d,d7d-d7d/d7d0d7d2d7d3d7d5d7d6d7d7d8d8d9Z_G d:d; d;ee Z`G d<d= d=ed> ZadS )?    )annotationsN)TYPE_CHECKINGAnyCallableLiteral)EagerSeriesEagerSeriesHistPandasLikeSeriesCatNamespace!PandasLikeSeriesDateTimeNamespace)PandasLikeSeriesListNamespacePandasLikeSeriesStringNamespace)PandasLikeSeriesStructNamespace)	align_and_extract_nativeget_dtype_backendimport_array_modulenarwhals_to_native_dtypenative_to_narwhals_dtypeobject_native_to_narwhals_dtyperenameselect_columns_by_name	set_index)assert_never)Implementation
is_list_of
no_defaultparse_version)is_numpy_array_1dis_pandas_like_series)InvalidOperationError)HashableIterableIteratorSequence)
ModuleType)Self	TypeAliasTypeIs)ChunkedArrayAny)HistDataPandasLikeDataFramePandasLikeNamespace)NativeSeriesT)	NoDefault)Version_LimitedContext)DType)ClosedIntervalFillNullStrategyInto1DArray	IntoDTypeModeKeepStrategyNonNestedLiteralPythonLiteral
RankMethodRollingInterpolationMethodSizedMultiIndexSelector_1DArray_SliceIndexz%HistData[pd.Series[Any], list[float]]r(   PandasHistDataInt64int64zint64[pyarrow]Int32int32zint32[pyarrow]Int16int16zint16[pyarrow]Int8int8zint8[pyarrow]UInt64uint64zuint64[pyarrow]UInt32uint32zuint32[pyarrow]UInt16uint16zuint16[pyarrow]UInt8uint8zuint8[pyarrow]Float64float64float32)zfloat64[pyarrow]Float32zfloat32[pyarrow]c                   @  s  e Zd Zdd	d
ZedddZdddZdddZdddZdddZ	dddZ
dddd"d#Zed$d%d%d&dd0d1Zedd4d5Zedd6d7Zedd9d:Zedd<d=Zedd>d?ZeddAdBZedCdD ZddNdOZddSdTZddUdVZddXdYZddd[d\Zdd^d_ZddadbZddgdhZddjdkZddldmZddndoZ ddpdqZ!ddsdtZ"ddvdwZ#ddxdyZ$dd|d}Z%dd~dZ&dddZ'dddZ(dddZ)dddZ*dddZ+dddZ,dddZ-dddZ.dddZ/dddZ0dddZ1dddZ2dddZ3dddZ4dddZ5dddZ6dddZ7dddZ8dddZ9dddZ:dddZ;dddZ<dddZ=dddZ>dddZ?dddZ@dddZAdddZBdddZCdddZDdddZEdddZFdddÄZGdddƄZHdddȄZIdddʄZJddd̄ZKddd΄ZLdddЄZMddd҄ZNdddلZOdddۄZPddd݄ZQddd߄ZRdddZSdddZTdddZUdddddZVdddZWdddZXdddZYdddZZdddZ[dddZ\dd%ddd	d
Z]dddZ^dddZ_dddZ`dddZadddZbdddZcdÐddZddĐdd ZedŐd$d%ZfdƐd'd(Zgdd)d*Zhdd+d,Zidǐd.d/Zjdd0d1Zkdd2d3ZldȐd6d7Zmdɐd9d:Zndʐd;d<Zodːd=d>Zpd̐d?d@Zqd͐dBdCZrdΐdFdGZsddHdIZtddJdKZuddLdMZvddNdOZwdϐdRdSZxdϐdTdUZydАdVdWZzdАdXdYZ{dѐd[d\Z|dҐd]d^Z}dd_d`Z~dӐdcddZdԐdhdiZdՐdkdlZd֐dndoZddpdqZddrdsZddtduZdאdwdxZdؐd}d~ZdِddZdڐddZedېddZedܐddZedݐddZedސddZedߐddZd%S (  PandasLikeSeriesnative_seriesr   implementationr   versionr2   returnNonec                C  s$   |j | _|| _|| _|| _d| _d S )NF)name_name_native_series_implementation_version
_broadcast)selfrW   rX   rY    rc   Z/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/narwhals/_pandas_like/series.py__init__q   s
   
zPandasLikeSeries.__init__c                 C     | j S N)r^   rb   rc   rc   rd   native      zPandasLikeSeries.nativer&   c                 C  s,   | j  r
| j  S dt| j  }t|)Nz!Expected pandas/modin/cudf, got: )r_   is_pandas_liketo_native_namespacetypeAssertionErrorrb   msgrc   rc   rd   __native_namespace__   s   

z%PandasLikeSeries.__native_namespace__r/   c                 C  s   ddl m} || j| jS )Nr   r.   )narwhals._pandas_like.namespacer/   r_   r`   )rb   r/   rc   rc   rd   __narwhals_namespace__   s   z'PandasLikeSeries.__narwhals_namespace__rows'SizedMultiIndexSelector[pd.Series[Any]]r'   c                 C  s(   t |tr	t|n|}| | jj| S rg   )
isinstancetuplelist_with_nativeri   ilocrb   rt   rc   rc   rd   _gather   s   zPandasLikeSeries._gather_SliceIndex | rangec                 C  s    |  | jjt|j|j|j S rg   )ry   ri   rz   slicestartstopstepr{   rc   rc   rd   _gather_slice   s   zPandasLikeSeries._gather_slicec                 C  s   | j | j| j|dS N)rX   rY   )	__class__ri   r_   )rb   rY   rc   rc   rd   _with_version   s   
zPandasLikeSeries._with_versionFpreserve_broadcastseriesr   boolc                C  s$   | j || j| jd}|r| j|_|S r   )r   r_   r`   ra   )rb   r   r   resultrc   rc   rd   ry      s   
zPandasLikeSeries._with_native N)r\   dtypeindexdataIterable[Any]contextr3   r\   strr   IntoDType | Noner   c          
      C  sx   |j }|j}| }i }	|rt|d |||	d< n| r d|	d< |d ur,t|r,||	d< | j|j|fd|i|	|dS )Nr   Fcopyr   r\   r   )r_   r`   rl   r   	is_pandaslenfrom_nativeSeries)
clsr   r   r\   r   r   rX   rY   nskwdsrc   rc   rd   from_iterable   s   
 zPandasLikeSeries.from_iterableobjTypeIs[Any]c                 C     t | S rg   )r    )r   rc   rc   rd   
_is_native      zPandasLikeSeries._is_nativec               C  s   | ||j |jdS r   )r_   r`   )r   r   r   rc   rc   rd   r      s   zPandasLikeSeries.from_nativer7   c               C  s8   |j }t|r	|n|g}| j|dd}| j||dS )Nr   r\   r   )r_   r   rl   r   r   )r   r   r   rX   arrri   rc   rc   rd   
from_numpy   s   zPandasLikeSeries.from_numpySequence[Self]c           
      G  s   |d   j}dd |D }tdd t||D }||| jj}g }|D ]6}|jrA||jjd ||j|jj	d}|
|}	n|jj|urVt|j||jd}|
|}	n|}	||	 q'|S )Nr   c                 S  s   g | ]}t |qS rc   )r   ).0src   rc   rd   
<listcomp>   s    z:PandasLikeSeries._align_full_broadcast.<locals>.<listcomp>c                 s  s    | ]
\}}|j s|V  qd S rg   )ra   )r   lengthr   rc   rc   rd   	<genexpr>   s    

z9PandasLikeSeries._align_full_broadcast.<locals>.<genexpr>)r   r\   r   rX   )rq   r   maxzipr   ri   ra   rz   r\   r   ry   r   r_   append)
r   r   r   lengthstarget_lengthidx	reindexedr   ri   	compliantrc   rc   rd   _align_full_broadcast   s&   z&PandasLikeSeries._align_full_broadcastc                 C  rf   rg   )r]   rh   rc   rc   rd   r\      rj   zPandasLikeSeries.namer4   c                 C  s2   | j j}|dkrt|| j| jS t| j | j| jS )Nobject)ri   r   r   r`   r_   r   )rb   native_dtyperc   rc   rd   r      s   zPandasLikeSeries.dtypec                 C  s   t rdd l}|S t| jS Nr   )r   numpyr   r_   )rb   nprc   rc   rd   _array_funcs   s   
zPandasLikeSeries._array_funcscomfloat | Nonespan	half_lifealphaadjustmin_samplesintignore_nullsc             	   C  s   | j }| }	| jtju r*|dkr|r|	 s$|j|||||d }
nd}t||j|||||||d }
d |
|	< | 	|
S )Nr   )r   r   halflifer   r   zscuDF only supports `ewm_mean` when there are no missing values or when both `min_period=0` and `ignore_nulls=False`)	ignore_na)
ri   isnar_   r   CUDFanyewmmeanNotImplementedErrorry   )rb   r   r   r   r   r   r   r   sermask_nar   rp   rc   rc   rd   ewm_mean   s&   

zPandasLikeSeries.ewm_meanindicesint | Sequence[int]valuesc                 C  sP   t || jrt|j| jj| | jd}| jjdd}||j|< | j|_| 	|S )Nr   T)deep)
rv   r   r   ri   r   r_   r   rz   r\   ry   )rb   r   r   r   rc   rc   rd   scatter  s   


zPandasLikeSeries.scatterc                 C  s   | j }| j}t|j| jj|j |d}|tju r"ttdk r"|	 }d}|tju r7||k r7|| jj
|jj< d S || jj
|j< d S )Nr   )   )   r   )r_   _backend_versionr   ri   r   r   PANDASr   r   r   rz   r   )rb   r   r   rX   backend_versionvalues_nativemin_pd_versionrc   rc   rd   _scatter_in_place$  s   z"PandasLikeSeries._scatter_in_placer8   c                 C  s\   | j |kr| jj dkr| j| jddS t|t| jj | j| j| jd}| j| j|ddS )Nr   Tr   )dtype_backendrX   rY   )r   ri   ry   r   r   r_   r`   astype)rb   r   pd_dtyperc   rc   rd   cast5  s   zPandasLikeSeries.cast
int | Nonec                 C  sD   |d u rt | dkrdt |  d}t|| jjd S | jj| S )Nr   zlcan only call '.item()' if the Series is of length 1, or an explicit index is provided (Series is of length )r   )r   
ValueErrorri   rz   )rb   r   rp   rc   rc   rd   itemC  s   zPandasLikeSeries.itemr-   c                 C  s&   ddl m} || j | j| jddS )Nr   r,   F)rX   rY   validate_column_names)narwhals._pandas_like.dataframer-   ri   to_framer_   r`   )rb   r-   rc   rc   rd   r   O  s   zPandasLikeSeries.to_frame	list[Any]c                 C  s&   | j  }|r| j  S | j S rg   )r_   is_cudfri   to_arrow	to_pylistto_list)rb   r   rc   rc   rd   r   Y  s   
zPandasLikeSeries.to_listlower_boundupper_boundclosedr5   c                 C  s   | j }t| |\}}t| |\}}|dkr ||||@ }n1|dkr/||||@ }n"|dkr>||||@ }n|dkrM||||@ }nt| | ||j	S )Nleftrightnoneboth)
ri   r   geltgtler   ry   aliasr\   )rb   r   r   r   r   _resrc   rc   rd   
is_between]  s   zPandasLikeSeries.is_betweenotherc                 C     |  | j|S rg   )ry   ri   isinrb   r   rc   rc   rd   is_ino     zPandasLikeSeries.is_inc                 C  s>   | j }t|}| j|}|j||j|jdj| }| |S )N)r\   r   )	ri   r   r   aranger   r\   r   locry   )rb   r   sizer   r   rc   rc   rd   arg_truer  s
   
zPandasLikeSeries.arg_truec                 C  
   | j  S rg   )ri   argminrh   rc   rc   rd   arg_miny     
zPandasLikeSeries.arg_minc                 C  r  rg   )ri   argmaxrh   rc   rc   rd   arg_max|  r  zPandasLikeSeries.arg_max	predicatec                 C  s8   t |tst| |\}}n|}| | jj| | jS rg   )r   r   r   ry   ri   r  r   r\   )rb   r  r   other_nativerc   rc   rd   filter  s   
zPandasLikeSeries.filterr;   c                 C     t | jr| jjd S d S r   r   ri   rz   rh   rc   rc   rd   first     zPandasLikeSeries.firstc                 C  r  )Nr  rh   rc   rc   rd   last  r  zPandasLikeSeries.lastopCallable[..., PandasLikeSeries]c                 C  s<   t | |\}}| jot|dd}| j||||d| jS )Nra   Tr   )r   ra   getattrry   r   r\   )rb   r  r   r   r  r   rc   rc   rd   _with_binary  s   
zPandasLikeSeries._with_binaryc                   s   |   fdd|| jS )Nc                   s
    || S rg   rc   )xyr  rc   rd   <lambda>  s   
 z5PandasLikeSeries._with_binary_right.<locals>.<lambda>)r  r   r\   )rb   r  r   rc   r  rd   _with_binary_right  s   z#PandasLikeSeries._with_binary_rightr   c                 C     |  tj|S rg   )r  operatoreqr   rc   rc   rd   __eq__     zPandasLikeSeries.__eq__c                 C  r  rg   )r  r  ner   rc   rc   rd   __ne__  r!  zPandasLikeSeries.__ne__c                 C  r  rg   )r  r  r   r   rc   rc   rd   __ge__  r!  zPandasLikeSeries.__ge__c                 C  r  rg   )r  r  r   r   rc   rc   rd   __gt__  r!  zPandasLikeSeries.__gt__c                 C  r  rg   )r  r  r   r   rc   rc   rd   __le__  r!  zPandasLikeSeries.__le__c                 C  r  rg   )r  r  r   r   rc   rc   rd   __lt__  r!  zPandasLikeSeries.__lt__c                 C  r  rg   )r  r  and_r   rc   rc   rd   __and__  r!  zPandasLikeSeries.__and__c                 C  r  rg   )r  r  r(  r   rc   rc   rd   __rand__  r!  zPandasLikeSeries.__rand__c                 C  r  rg   )r  r  or_r   rc   rc   rd   __or__  r!  zPandasLikeSeries.__or__c                 C  r  rg   )r  r  r+  r   rc   rc   rd   __ror__  r!  zPandasLikeSeries.__ror__c                 C  r  rg   )r  r  addr   rc   rc   rd   __add__  r!  zPandasLikeSeries.__add__c                 C  r  rg   )r  r  r.  r   rc   rc   rd   __radd__  r!  zPandasLikeSeries.__radd__c                 C  r  rg   )r  r  subr   rc   rc   rd   __sub__  r!  zPandasLikeSeries.__sub__c                 C  r  rg   )r  r  r1  r   rc   rc   rd   __rsub__  r!  zPandasLikeSeries.__rsub__c                 C  r  rg   )r  r  mulr   rc   rc   rd   __mul__  r!  zPandasLikeSeries.__mul__c                 C  r  rg   )r  r  r4  r   rc   rc   rd   __rmul__  r!  zPandasLikeSeries.__rmul__c                 C  r  rg   )r  r  truedivr   rc   rc   rd   __truediv__  r!  zPandasLikeSeries.__truediv__c                 C  r  rg   )r  r  r7  r   rc   rc   rd   __rtruediv__  r!  zPandasLikeSeries.__rtruediv__c                 C  r  rg   )r  r  floordivr   rc   rc   rd   __floordiv__  r!  zPandasLikeSeries.__floordiv__c                 C  r  rg   )r  r  r:  r   rc   rc   rd   __rfloordiv__  r!  zPandasLikeSeries.__rfloordiv__c                 C  r  rg   )r  r  powr   rc   rc   rd   __pow__  r!  zPandasLikeSeries.__pow__c                 C  r  rg   )r  r  r=  r   rc   rc   rd   __rpow__  r!  zPandasLikeSeries.__rpow__c                 C  r  rg   )r  r  modr   rc   rc   rd   __mod__  r!  zPandasLikeSeries.__mod__c                 C  r  rg   )r  r  r@  r   rc   rc   rd   __rmod__  r!  zPandasLikeSeries.__rmod__c                 C  s   |  | j S rg   )ry   ri   rh   rc   rc   rd   
__invert__  r!  zPandasLikeSeries.__invert__c                 C  r  rg   )ri   r   rh   rc   rc   rd   r     r  zPandasLikeSeries.anyc                 C  r  rg   )ri   allrh   rc   rc   rd   rD    r  zPandasLikeSeries.allc                 C  r  rg   )ri   minrh   rc   rc   rd   rE    r  zPandasLikeSeries.minc                 C  r  rg   )ri   r   rh   rc   rc   rd   r     r  zPandasLikeSeries.maxfloatc                 C  r  rg   )ri   sumrh   rc   rc   rd   rG    r  zPandasLikeSeries.sumc                 C  r  rg   )ri   countrh   rc   rc   rd   rH    r  zPandasLikeSeries.countc                 C  r  rg   )ri   r   rh   rc   rc   rd   r     r  zPandasLikeSeries.meanc                 C  s    | j  sd}t|| j S )Nz<`median` operation not supported for non-numeric input type.)r   
is_numericr!   ri   medianro   rc   rc   rd   rJ    s   

zPandasLikeSeries.medianddofc                C     | j j|dS NrK  )ri   stdrb   rK  rc   rc   rd   rO    r!  zPandasLikeSeries.stdc                C  rL  rM  )ri   varrP  rc   rc   rd   rQ    r!  zPandasLikeSeries.varc                 C  s~   | j  }t|dkrd S t|dkrtdS t|dkrdS ||  }|d  }|d  }|dkr;||d  S tdS )Nr   r   nanr   g           g      ?ri   dropnar   rF  r   )rb   ser_not_nullmm2m3rc   rc   rd   skew  s   
zPandasLikeSeries.skewc                 C  sr   | j  }t|dkrd S t|dkrtdS ||  }|d  }|d  }|dkr5||d  d S tdS )Nr   r   rR  r      g      @rT  )rb   rV  rW  rX  m4rc   rc   rd   kurtosis  s   
 zPandasLikeSeries.kurtosisc                 C  s
   t | jS rg   )r   ri   rh   rc   rc   rd   r      r  zPandasLikeSeries.lenc                 C  s   | j | j ddS )NTr   )ry   ri   r   rh   rc   rc   rd   is_null%     zPandasLikeSeries.is_nullc                 C  s8   | j }| j sd| j d}t|| j||kddS )Nz3`.is_nan` only supported for numeric dtype and not z, did you mean `.is_null`?Tr   )ri   r   rI  r!   ry   )rb   r   rp   rc   rc   rd   is_nan(  s
   
zPandasLikeSeries.is_nanvalueSelf | NonNestedLiteralstrategyFillNullStrategy | Nonelimitc           	      C  s   | j }| jtju r| jdk rddini }t Q tjddtd |d ur<t	| |\}}| j
|jdd|i|dd	}n%| j
|d
krL|jdd|i|n	|jdd|i|dd	}W d    |S W d    |S 1 slw   Y  |S )NrS  downcastFignorez&The 'downcast' keyword .*is deprecated)categoryra  Tr   forwardre  rc   )ri   r_   r   r   r   warningscatch_warningsfilterwarningsFutureWarningr   ry   fillnaffillbfill)	rb   ra  rc  re  r   kwargsr   native_valueres_serrc   rc   rd   	fill_null0  s8   



zPandasLikeSeries.fill_nullc                 C  s   | j  r|d u rd}t|| j sd| j d}t|| j}|d u r+|jjjn|}||k}|j	ddd | j
|||ddS )Nz6`fill_nan(value=None)` is not support for CuDF backendz5`.fill_nan` only supported for numeric dtype and not z, did you mean `.fill_null`?FT)inplacer   )r_   r   r   r   rI  r!   ri   arrayna_valuero  ry   mask)rb   ra  rp   r   fillry  rc   rc   rd   fill_nanO  s   
zPandasLikeSeries.fill_nanc                 C     |  | j S rg   )ry   ri   rU  rh   rc   rc   rd   
drop_nulls_     zPandasLikeSeries.drop_nullsc                 C  s   | j jddS )NF)rU  )ri   nuniquerh   rc   rc   rd   n_uniqueb  r!  zPandasLikeSeries.n_uniquenfractionwith_replacementseedc                C  s   |  | jj||||dS )N)r  fracreplacerandom_state)ry   ri   sample)rb   r  r  r  r  rc   rc   rd   r  e  s
   zPandasLikeSeries.samplec                 C  r|  rg   )ry   ri   absrh   rc   rc   rd   r  s  r~  zPandasLikeSeries.absreversec                C  >   |s	| j jddn| j d d d jddd d d }| |S NT)skipnar  )ri   cumsumry   rb   r  r   rc   rc   rd   cum_sumv  
    
zPandasLikeSeries.cum_sumTmaintain_orderr  c                C  s    |  t| j| j | jdS )zuPandas always maintains order, as per its docstring.

        > Uniques are returned in order of appearance.
        r   )ry   rm   ri   uniquer\   )rb   r  rc   rc   rd   r  ~  s    zPandasLikeSeries.uniquec                 C  r|  rg   )ry   ri   diffrh   rc   rc   rd   r    r~  zPandasLikeSeries.diffc                 C  r   rg   )ry   ri   shiftrb   r  rc   rc   rd   r    r   zPandasLikeSeries.shiftdefaultPandasLikeSeries | NoDefaultoldSequence[Any]newreturn_dtypec                C  s  |   }| j}| j}| j}t|j|}	|rt||	|| jnd }
||	|}|dk}|j
||
| jd}|d u rB|	d urB|j|	d}|j|||d }|j|_|tu r|| | @ }| ru| || jdd }d| }t|||d }nt| |\}}|||}| |S )Nr   )r   r\   )r   Fr  zYreplace_strict did not replace all non-null values.

The following did not get replaced: )rq   r   ri   r_   r   r   r   r`   Indexget_indexerr   r\   convert_dtypesrz   wherer   r   notnar   ry   r  r   r!   r   )rb   r  r  r  r  	namespacearray_funcsri   implr   r   idxswas_matched
new_seriesnative_resultunmatched_maskunmatched_valuesrp   r   default_nativerc   rc   rd   replace_strict  sB   
zPandasLikeSeries.replace_strict
descending
nulls_lastc                C  s,   |rdnd}|  | jj| |d| jS )Nr  r  )	ascendingna_position)ry   ri   sort_valuesr   r\   )rb   r  r  r  rc   rc   rd   sort  s   zPandasLikeSeries.sortstr | Hashablec                 C  s*   || j kr| jt| j|| jdddS | S )Nr   Tr   )r\   ry   r   ri   r_   )rb   r\   rc   rc   rd   r     s   
zPandasLikeSeries.aliasr   bool | Noner?   c                C  s   | j ||dS )N)r   r   )to_numpy)rb   r   r   rc   rc   rd   	__array__  s   zPandasLikeSeries.__array__)r   c                C  s   | j j}t| j|jr| jjd ur| jdjd j	}n| j	}|
  }d|p-| j i}|rJt|jtv rJ|dtdi |pItt|j }|s\t|jtv r\|p[tt|j }|jdd|i|S )NUTCr   rx  rR  r   rc   )r`   dtypesrv   r   Datetime	time_zonedtconvert_time_zonereplace_time_zoneri   r   r   r_   r   r   PANDAS_TO_NUMPY_DTYPE_MISSINGupdaterF   PANDAS_TO_NUMPY_DTYPE_NO_MISSINGr  )rb   r   r   r  r   has_missingrr  rc   rc   rd   r    s   zPandasLikeSeries.to_numpypd.Series[Any]c                 C  sR   | j tju r	| jS | j tju r| j S | j tju r| j S d| j  }t|)NzUnknown implementation: )	r_   r   r   ri   r   	to_pandasMODIN
_to_pandasrn   ro   rc   rc   rd   r    s   

zPandasLikeSeries.to_pandas	pl.Seriesc                 C  s   dd l }||  S r   )polarsfrom_pandasr  )rb   plrc   rc   rd   	to_polars  s   zPandasLikeSeries.to_polarsc                 C     |  | jjdd | jS )NFkeepry   ri   
duplicatedr   r\   rh   rc   rc   rd   	is_unique     zPandasLikeSeries.is_uniquec                 C  s   | j   S rg   )ri   r   rG  rh   rc   rc   rd   
null_count  r!  zPandasLikeSeries.null_countc                 C  r  )Nr  r  r  rh   rc   rc   rd   is_first_distinct  r  z"PandasLikeSeries.is_first_distinctc                 C  r  )Nr  r  r  rh   rc   rc   rd   is_last_distinct  r  z!PandasLikeSeries.is_last_distinctc                C  s4   t |tsdt| }t||r| jjS | jjS )Nz/argument 'descending' should be boolean, found )rv   r   rm   	TypeErrorri   is_monotonic_decreasingis_monotonic_increasing)rb   r  rp   rc   rc   rd   	is_sorted  s   
zPandasLikeSeries.is_sortedr  parallel
str | None	normalizec          	      C  sp   ddl m} | jdu rdn| j}|p|rdnd}| jjdd|d }||g|_|r1|j|dd	}|j|| d
S )z-Parallel is unused, exists for compatibility.r   r,   Nr   
proportionrH  F)rU  r  r  )r  r   )	r   r-   r]   ri   value_countsreset_indexcolumnsr  r   )	rb   r  r  r\   r  r-   index_name_value_name_	val_countrc   rc   rd   r    s   
zPandasLikeSeries.value_countsquantileinterpolationr=   c                 C  s   | j j||dS )N)qr  )ri   r  )rb   r  r  rc   rc   rd   r     s   zPandasLikeSeries.quantilery  c                 C  s8   | j }t| |\}}t| |\}}|||}| |S rg   )ri   r   r  ry   )rb   ry  r   r   r   r   rc   rc   rd   zip_with%  s
   
zPandasLikeSeries.zip_withc                 C  r   rg   )ry   ri   headr  rc   rc   rd   r  ,  r   zPandasLikeSeries.headc                 C  r   rg   )ry   ri   tailr  rc   rc   rd   r  /  r   zPandasLikeSeries.taildecimalsc                 C  s   |  | jj|dS )N)r  )ry   ri   round)rb   r  rc   rc   rd   r  2  r_  zPandasLikeSeries.roundc                 C  L   | j }| |jrdd lm} | ||j}n
| jj}| ||}| 	|S r   )
ri   is_native_dtype_pyarrowr   pyarrow.computecompute_apply_pyarrow_compute_funcfloorr   _apply_array_funcry   rb   ri   pcresult_native
array_funcrc   rc   rd   r  5     
zPandasLikeSeries.floorc                 C  r  r   )
ri   r  r   r  r  r  ceilr   r  ry   r  rc   rc   rd   r  @  r  zPandasLikeSeries.ceil	separator
drop_firstc                C  s   ddl m} |  }| j}| jrt| jnd}| | d}|  }|j|||||dd}	|rMt	|	j
^ }
}|g|
}tt|	|| j||i| jd}	|j|	| dS )	Nr   r,   r   nullrI   )prefix
prefix_sepr  dummy_nar   )r  rX   r   )r   r-   rq   ri   r]   r   r   r   get_dummiesrx   r  r   r   r_   r   )rb   r  r  r-   plxr   r\   null_col_pl	has_nullsr   colsnull_col_pdoutput_orderrc   rc   rd   
to_dummiesK  s.   	
zPandasLikeSeries.to_dummiesoffsetc                 C  s   |  | jj|d | S rg   )ry   ri   rz   )rb   r  r  rc   rc   rd   gather_everyh     zPandasLikeSeries.gather_everyc           	      C  s   t | |\}}t | |\}}| j}| rddini }| j}| s@| |r1|||k|}d }| |r@|||k|}d }| |j||fi |S Naxisr   	r   r_   is_modinri   r   r   r  ry   clip)	rb   r   r   r   lowerupperr  rr  r   rc   rc   rd   r  k  s   

zPandasLikeSeries.clipc                 C  sl   t | |\}}| j}| rddini }| j}| s*| |r*|||k|}d }| |j|fi |S r
  r  )rb   r   r   r  r  rr  r   rc   rc   rd   
clip_lower  s   zPandasLikeSeries.clip_lowerc                 C  sn   t | |\}}| j}| rddini }| j}| s*| |r*|||k|}d }| |jdd|i|S )Nr  r   r  rc   r  )rb   r   r   r  r  rr  r   rc   rc   rd   
clip_upper  s   zPandasLikeSeries.clip_upperpa.Array[Any]c                 C  s,   | j tju r| j S dd l}|j| jS r   )r_   r   r   ri   r   pyarrowArrayr  )rb   parc   rc   rd   r     s   
zPandasLikeSeries.to_arrowr  r9   c                C  s0   | j  }| j|_| |dkr|dS |S )Nr   r   )ri   moder\   ry   r  )rb   r  r   rc   rc   rd   r    s   
zPandasLikeSeries.modec                C  s:   | j   }|s| nt| |  | d }| |S Nr   )ri   r   r  r   ry   )rb   r  not_na_seriesr   rc   rc   rd   	cum_count  s   

zPandasLikeSeries.cum_countc                C  r  r  )ri   cumminry   r  rc   rc   rd   cum_min  r  zPandasLikeSeries.cum_minc                C  r  r  )ri   cummaxry   r  rc   rc   rd   cum_max  r  zPandasLikeSeries.cum_maxc                C  r  r  )ri   cumprodry   r  rc   rc   rd   cum_prod  r  zPandasLikeSeries.cum_prodwindow_sizecenterc                C      | j j|||d }| |S Nwindowmin_periodsr"  )ri   rollingrG  ry   rb   r!  r   r"  r   rc   rc   rd   rolling_sum     
zPandasLikeSeries.rolling_sumc                C  r#  r$  )ri   r(  r   ry   r)  rc   rc   rd   rolling_mean  r+  zPandasLikeSeries.rolling_meanc                C  $   | j j|||dj|d}| |S Nr%  rN  )ri   r(  rQ  ry   rb   r!  r   r"  rK  r   rc   rc   rd   rolling_var     
zPandasLikeSeries.rolling_varc                C  r-  r.  )ri   r(  rO  ry   r/  rc   rc   rd   rolling_std  r1  zPandasLikeSeries.rolling_stdIterator[Any]c                 c  s,    | j  rd}t|| j E d H  d S )NzIterating over a cuDF Series, DataFrame or Index is not supported. For more information see: https://docs.rapids.ai/api/cudf/stable/user_guide/pandas-comparison/#iteration)r_   r   r   ri   __iter__ro   rc   rc   rd   r4    s   
zPandasLikeSeries.__iter__c                 C  s$   |d u r| j   S | j |k S rg   )ri   r   r   r   rc   rc   rd   __contains__  s   $zPandasLikeSeries.__contains__c                 C  s$   | j }| |tdk|tdk @ S )Nz-infinf)ri   ry   rF  )rb   r   rc   rc   rd   	is_finite  s   zPandasLikeSeries.is_finitemethodr<   c          	      C  s   |dkrdn|}| j }| jtju r`| jdk r`t| jj| jdkr`| j r`| 	  }
 r`| d}|  }|  |j||j}| ||j|d| ddjd d d	f | j S | | jj|d| ddS )
Nordinalr  rf  numpy_nullable_is_nullr  F)r8  	na_optionr  pctr   )r\   r_   r   r   r   r   ri   r   
is_integerr^  r   rs   r   with_columns_expr_from_seriesr   ry   groupbyrankrz   )	rb   r8  r  	pd_methodr\   	null_mask	mask_namer   dfrc   rc   rd   rC    sF   

	

zPandasLikeSeries.rankbinslist[float]include_breakpointc                C     t j| |d| S N)rJ  )_PandasHistfrom_series	with_binsr   )rb   rH  rJ  rc   rc   rd   hist_from_bins     zPandasLikeSeries.hist_from_bins	bin_countc                C  rK  rL  )rM  rN  with_bin_countr   )rb   rR  rJ  rc   rc   rd   hist_from_bin_count&  rQ  z$PandasLikeSeries.hist_from_bin_countbasec                   sj   | j }| |jrdd lm d fdd}| ||}n| jjd fd	d
}| ||}| 	|S )Nr   car*   rZ   c                   s    |  S rg   )logb)rV  )rU  r  rc   rd   pc_log4  s   z$PandasLikeSeries.log.<locals>.pc_logr   r0   c                   s   |   S rg   rc   )r   )rU  log_funcrc   rd   	array_log;  r~  z'PandasLikeSeries.log.<locals>.array_log)rV  r*   rZ   r*   )r   r0   rZ   r0   )
ri   r  r   r  r  r  r   logr  ry   )rb   rU  ri   rX  r  rZ  rc   )rU  rY  r  rd   r[  /  s   
zPandasLikeSeries.logc                 C  r  r   )
ri   r  r   r  r  r  expr   r  ry   r  rc   rc   rd   r\  A  s   
zPandasLikeSeries.expc                 C  s   |  | jdS )N      ?)ry   ri   r=  rh   rc   rc   rd   sqrtM  r   zPandasLikeSeries.sqrtc                 C  r  r   )
ri   r  r   r  r  r  sinr   r  ry   r  rc   rc   rd   r_  P  s   
zPandasLikeSeries.sinr   c                 C  s   | j }t||ddkS )Nr   r  )r_   r   )rb   r   r  rc   rc   rd   r  _  s   z(PandasLikeSeries.is_native_dtype_pyarrowri   r0   pc_func,Callable[[ChunkedArrayAny], ChunkedArrayAny]c                 C  sT   ddl m} t|}||jj}||j| j}t|d| j| j}||||j|j	dS )Nr   )r   r  )r   r   r\   )
narwhals._arrow.utilsr   rm   rw  	_pa_arrayr`   r   r_   r   r\   )rb   ri   r`  r   
native_cls
result_arrnw_dtype	out_dtyperc   rc   rd   r  c  s   z,PandasLikeSeries._apply_pyarrow_compute_funcr  (Callable[[NativeSeriesT], NativeSeriesT]c                 C  s0   t |}||}| j r|||j|jdS |S )N)r   r\   )rm   r_   r   r   r\   )rb   ri   r  rd  re  rc   rc   rd   r  r  s   z"PandasLikeSeries._apply_array_funcc                C  s   |r|    S |  S rg   )r}  r  )rb   r   rc   rc   rd   	any_value}  r	  zPandasLikeSeries.any_valuer   c                 C  r   rg   r   rh   rc   rc   rd   r     r   zPandasLikeSeries.strr   c                 C  r   rg   r   rh   rc   rc   rd   r    r   zPandasLikeSeries.dtr
   c                 C  r   rg   r	   rh   rc   rc   rd   cat  r   zPandasLikeSeries.catr   c                 C      t | jdsd}t|t| S )Nrx   z>Series must be of PyArrow List type to support list namespace.)hasattrri   r  r   ro   rc   rc   rd   rx        zPandasLikeSeries.listr   c                 C  rk  )NstructzBSeries must be of PyArrow Struct type to support struct namespace.)rl  ri   r  r   ro   rc   rc   rd   rn    rm  zPandasLikeSeries.struct)rW   r   rX   r   rY   r2   rZ   r[   )rZ   r   )rZ   r&   )rZ   r/   )rt   ru   rZ   r'   )rt   r}   rZ   r'   )rY   r2   rZ   r'   )r   r   r   r   rZ   r'   )r   r   r   r3   r\   r   r   r   r   r   rZ   r'   )r   r   rZ   r   )r   r   r   r3   rZ   r'   )r   r7   r   r3   rZ   r'   )r   r'   rZ   r   )rZ   r   )rZ   r4   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   rZ   r'   )r   r   r   r   rZ   r'   )r   r'   r   r'   rZ   r[   )r   r8   rZ   r'   rg   )r   r   rZ   r   rZ   r-   )rZ   r   )r   r   r   r   r   r5   rZ   r'   )r   r   rZ   r'   )rZ   r'   )rZ   r   )r  r   rZ   r'   )rZ   r;   )r  r  r   r   rZ   r'   )r   r   rZ   r'   rZ   r   )rZ   rF  )rK  r   rZ   rF  )rZ   r   )ra  rb  rc  rd  re  r   rZ   r'   )ra  r   rZ   r'   )
r  r   r  r   r  r   r  r   rZ   r'   )r  r   rZ   r'   )r  r   rZ   r'   )r  r   rZ   r'   )
r  r  r  r  r  r  r  r   rZ   rV   )r  r   r  r   rZ   rV   )r\   r  rZ   r'   )r   r   r   r  rZ   r?   )rZ   r  )rZ   r  )r  r   rZ   r   )
r  r   r  r   r\   r  r  r   rZ   r-   )r  rF  r  r=   rZ   rF  )ry  r   r   r   rZ   r'   )r  r   rZ   r'   )r  r   r  r   rZ   r-   )r  r   r  r   rZ   r'   )r   r'   r   r'   rZ   r'   )r   r'   rZ   r'   )r   r'   rZ   r'   )rZ   r  )r  r9   rZ   r'   )r!  r   r   r   r"  r   rZ   r'   )
r!  r   r   r   r"  r   rK  r   rZ   r'   )rZ   r3  )r   r   rZ   r   )r8  r<   r  r   rZ   r'   )rH  rI  rJ  r   rZ   r-   )rR  r   rJ  r   rZ   r-   )rU  rF  rZ   r'   )r   r   rZ   r   )ri   r0   r`  ra  rZ   r0   )ri   r0   r  rh  rZ   r0   )r   r   rZ   r;   )rZ   r   )rZ   r   )rZ   r
   )rZ   r   )rZ   r   )__name__
__module____qualname__re   propertyri   rq   rs   r|   r   r   ry   classmethodr   staticmethodr   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-  r/  r0  r2  r3  r5  r6  r8  r9  r;  r<  r>  r?  rA  rB  rC  r   rD  rE  r   rG  rH  r   rJ  rO  rQ  rZ  r]  r   r^  r`  ru  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  r  r   r  r  r  r  r   r*  r,  r0  r2  r4  r5  r7  rC  rP  rT  r[  r\  r^  r_  r  r  r  ri  r   r  rj  rx   rn  rc   rc   rc   rd   rV   p   s6   


7
		
%		rV   c                   @  st   e Zd ZU ded< d.ddZd/dd	Zd0ddZd1ddZdddd2ddZddd3d&d'Z	d4d)d*Z
d5d,d-ZdS )6rM  rV   _seriesrZ   r-   c                 C  s.   | j  jj}| j  j}||| j| j dS )Nr   )rw  rs   
_dataframer   rq   	DataFrame_data)rb   r   ry  rc   rc   rd   r     s   z_PandasHist.to_framer   c                 C  s   | j  dk S r  )rw  rH  rh   rc   rc   rd   is_empty_series  r!  z_PandasHist.is_empty_seriesargint | list[float]rA   c                C  s(   |  |}| jr| ||dS d|iS )N
breakpointrH  rH  )_zeros_breakpoint_calculate_breakpoint)rb   r|  rH  rc   rc   rd   series_empty  s   
z_PandasHist.series_emptyr?   c                C  s,   | j jj}t|tr||S |t|d S r  )rw  r   zerosrv   r   r   )rb   r|  r  rc   rc   rd   r    s   
"z_PandasHist._zerosNr   )labelsr   breakslist[float] | _1DArrayr  Sequence[str] | Noner   Literal['left', 'right']r  c                C  s$   | j  j}|| j||dk|ddS )Nr   T)rH  r   r  include_lowest)rw  rq   cutri   )rb   r  r  r   r  rc   rc   rd   _cut  s   z_PandasHist._cutr   )r   r   rF  endnum_samplesr   Literal['both', 'none']c                C  s   | j jj||||dkdS )Nr   )r   r   numendpoint)rw  r   linspace)rb   r   r  r  r   rc   rc   rd   _linear_space  s   z_PandasHist._linear_spacerR  c                 C  s@   | j  | j  }}||kr|d8 }|d7 }| |||d S )z6Prepare bins for histogram calculation from bin_count.r]  r   )ri   rE  r   r  )rb   rR  r  r  rc   rc   rd   _calculate_bins  s
   z_PandasHist._calculate_binsrH  c                 C  sT   |  |}|jdddj|jjdd}|jddd | jr&|dd  |dS d	|iS )
NTF)rU  r  r   )
fill_value)droprv  r   r~  rH  )r  r  reindexrj  
categoriesr  r  )rb   rH  r  rH  rc   rc   rd   _calculate_hist  s   
z_PandasHist._calculate_histro  rp  )r|  r}  rZ   rA   )r|  r}  rZ   r?   )r  r  r  r  r   r  rZ   r  )
r   rF  r  rF  r  r   r   r  rZ   r?   )rR  r   rZ   r?   )rH  r  rZ   rA   )rq  rr  rs  __annotations__r   r{  r  r  r  r  r  r  rc   rc   rc   rd   rM    s   
 



	
rM  )r  rI  )b
__future__r   r  rk  typingr   r   r   r   r   r   narwhals._compliantr   r    narwhals._pandas_like.series_catr
   narwhals._pandas_like.series_dtr   !narwhals._pandas_like.series_listr    narwhals._pandas_like.series_strr   #narwhals._pandas_like.series_structr   narwhals._pandas_like.utilsr   r   r   r   r   r   r   r   r   narwhals._typing_compatr   narwhals._utilsr   r   r   r   narwhals.dependenciesr   r    narwhals.exceptionsr!   collections.abcr"   r#   r$   r%   typesr&   pandaspdr  r  r  r  typing_extensionsr'   r(   r)   narwhals._arrow.typingr*   narwhals._compliant.seriesr+   r   r-   rr   r/   narwhals._pandas_like.typingr0   narwhals._typingr1   r2   r3   narwhals.dtypesr4   narwhals.typingr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   r  r  r  rV   rM  rc   rc   rc   rd   <module>   s    ,8	
	
        3