
    T.hδ                      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 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 d dlmZ d dlmZ d dlmZ d dlmZ er*d dlmZ d dlZd dlZd dlZd dlmZ d dl m!Z! d dlm"Z" d dlm#Z#  G d dee         Z$ ede$e         Z% G d dee%         Z& G d dee%         Z' G d d ee%         Z( G d! d"ee%         Z)y)#    )annotations)TYPE_CHECKING)Any)Callable)Generic)Iterator)Literal)Mapping)Sequence)TypeVar)overload)is_numpy_scalar)_validate_dtype)IntoSeriesT)_validate_rolling_arguments)parse_version)
ModuleTypeN)Self	DataFrame)DType)Implementationc                  ~   e Zd ZdZedd       Z	 	 	 	 	 	 	 	 ddZedd       ZdddZe	dd       Z
e	dd       Z
dd	Z
dd
ZdddZddZddZedd       ZddZddZddZddZddZddZedd       Zedd       Zdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZddZdd Zdd!Zdd"Zdd#Z dd$Z!dd%Z"dd&Z#dd'Z$dd(Z%dd)Z&dd*dd+Z'	 d	 	 	 	 	 dd,Z(dd-Z)dd.Z*dd/Z+dd0Z,dd1dd2Z-dd3dd4Z.dd5Z/dd6Z0	 ddddd7	 	 	 	 	 	 	 	 	 	 	 dd8Z1dd9Z2dd:Z3	 ddd;	 	 	 	 	 	 	 	 	 dd<Z4ddd=dd>Z5dd?Z6	 	 	 d	 	 	 	 	 	 	 dd@Z7	 d	 	 	 	 	 	 	 ddAZ8ddBZ9ddCZ:ddDZ;ddEZ<ddFZ=ddGZ>ddHZ?ddIZ@ddJZAddKZBddLZCddMZDddNZEddOZFddPZGddQZHddRZIddSZJddTZKddUZLddVZMddWZNddXZOddYZPddZZQdd[ZRdd\ZSdd]ZTdd^ZUdd_ZVdd`ZWddaZXddbZYddcZZdddZ[ddeddfZ\dddddg	 	 	 	 	 	 	 	 	 	 	 ddhZ]	 	 	 	 	 	 ddiZ^ddjZ_dddkZ`dddlZadddmZbdddnZcdoddp	 	 	 	 	 	 	 ddqZddddrZeddsZfddtZgdduZhdd1ddvZidd1ddwZjdd1ddxZkdd1ddyZldddz	 	 	 	 	 	 	 	 	 dd{Zmdddz	 	 	 	 	 	 	 	 	 dd|Zndd}Zodd~Zpedd       Zqedd       Zredd       Zsedd       Zty)Seriesa  Narwhals Series, backed by a native series.

    The native series might be pandas.Series, polars.Series, ...

    This class is not meant to be instantiated directly - instead, use
    `narwhals.from_native`, making sure to pass `allow_series=True` or
    `series_only=True`.
    c                    ddl m} |S )Nr   r   )narwhals.dataframer   )selfr   s     c/var/www/html/School_Mangement_New/src/backend/venv/lib/python3.12/site-packages/narwhals/series.py
_dataframezSeries._dataframe+   s    0    c                   || _         t        |d      r|j                         | _        y dt	        |       d}t        |      )N__narwhals_series__zQExpected Polars Series or an object which implements `__narwhals_series__`, got: .)_levelhasattrr"   _compliant_seriestypeAssertionError)r   serieslevelmsgs       r   __init__zSeries.__init__1   sI     601%+%?%?%AD"efjkqfresstuC %%r    c                .    | j                   j                  S )a  Return implementation of native Series.

        This can be useful when you need to some special-casing for
        some libraries for features outside of Narwhals' scope - for
        example, when dealing with pandas' Period Dtype.

        Returns:
            Implementation.

        Examples:
            >>> import narwhals as nw
            >>> import pandas as pd
            >>> s_native = pd.Series([1, 2, 3])
            >>> s = nw.from_native(s_native, series_only=True)
            >>> s.implementation
            <Implementation.PANDAS: 1>
            >>> s.implementation.is_pandas()
            True
            >>> s.implementation.is_pandas_like()
            True
            >>> s.implementation.is_polars()
            False
        )r&   _implementationr   s    r   implementationzSeries.implementation>   s    2 %%555r    Nc                <    | j                   j                  ||      S )N)dtypecopy)r&   	__array__)r   r2   r3   s      r   r4   zSeries.__array__Y   s    %%//e$/GGr    c                     y N r   idxs     r   __getitem__zSeries.__getitem__\   s    25r    c                     y r6   r7   r8   s     r   r:   zSeries.__getitem___   s    EHr    c                    t        |t              s#t        |      r'|j                  j                  dv r| j
                  |   S | j                  | j
                  |         S )a)  Retrieve elements from the object using integer indexing or slicing.

        Arguments:
            idx: The index, slice, or sequence of indices to retrieve.

                - If `idx` is an integer, a single element is returned.
                - If `idx` is a slice or a sequence of integers,
                  a subset of the Series is returned.

        Returns:
            A single element if `idx` is an integer, else a subset of the Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> from typing import Any
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)
            >>> s_pa = pa.chunked_array([s])

            We define a library agnostic function:

            >>> def agnostic_get_first_item(s_native: IntoSeriesT) -> Any:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s[0]

            We can then pass either pandas, Polars, or any supported library:

            >>> agnostic_get_first_item(s_pd)
            np.int64(1)
            >>> agnostic_get_first_item(s_pl)
            1
            >>> agnostic_get_first_item(s_pa)
            1

            We can also make a function to slice the Series:

            >>> def agnostic_slice(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s[:2].to_native()

            >>> agnostic_slice(s_pd)
            0    1
            1    2
            dtype: int64
            >>> agnostic_slice(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i64]
            [
                1
                2
            ]
            >>> agnostic_slice(s_pa)
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                1,
                2
              ]
            ]
        )iu)
isinstanceintr   r2   kindr&   _from_compliant_seriesr8   s     r   r:   zSeries.__getitem__b   sS    D c3C SYY^^z%A))#..**4+A+A#+FGGr    c                6    | j                   j                         S r6   )r&   __native_namespace__r/   s    r   rD   zSeries.__native_namespace__   s    %%::<<r    c                   | j                   j                  }t        |d      r|j                  |      S 	 ddl}t        |j                        dk  rdt        |       }t        |       |j                  | j                         g      }|j                  |      S # t
        $ r}dt        |       }t        |      |d}~ww xY w)a  Export a Series via the Arrow PyCapsule Interface.

        Narwhals doesn't implement anything itself here:

        - if the underlying series implements the interface, it'll return that
        - else, it'll call `to_arrow` and then defer to PyArrow's implementation

        See [PyCapsule Interface](https://arrow.apache.org/docs/dev/format/CDataInterface/PyCapsuleInterface.html)
        for more.
        __arrow_c_stream__)requested_schemar   NzOPyArrow>=16.0.0 is required for `Series.__arrow_c_stream__` for object of type )   r   )r&   _native_seriesr%   rF   pyarrowModuleNotFoundErrorr'   r   __version__chunked_arrayto_arrow)r   rG   native_seriespaexcr+   cas          r   rF   zSeries.__arrow_c_stream__   s     ..==="67 33EU3VV	4  (72cdhivdwcxyC%c**Rt}}/0$$6F$GG # 	4cdhivdwcxyC%c*3	4s   B 	C'CCc                .    | j                   j                  S )a3  Convert Narwhals series to native series.

        Returns:
            Series of class that user started with.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    2
            2    3
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
                1
                2
                3
            ]
        )r&   rI   r/   s    r   	to_nativezSeries.to_native   s    J %%444r    c                v    | j                  | j                  j                  || j                  |                  S )u  Set value(s) at given position(s).

        Arguments:
            indices: Position(s) to set items at.
            values: Values to set.

        Note:
            This method always returns a new Series, without modifying the original one.
            Using this function in a for-loop is an anti-pattern, we recommend building
            up your positions and values beforehand and doing an update in one go.

            For example, instead of

            ```python
            for i in [1, 3, 2]:
                value = some_function(i)
                s = s.scatter(i, value)
            ```

            prefer

            ```python
            positions = [1, 3, 2]
            values = [some_function(x) for x in positions]
            s = s.scatter(positions, values)
            ```

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoFrameT
            >>> data = {"a": [1, 2, 3], "b": [4, 5, 6]}
            >>> df_pd = pd.DataFrame(data)
            >>> df_pl = pl.DataFrame(data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(df_native: IntoFrameT) -> IntoFrameT:
            ...     df = nw.from_native(df_native)
            ...     return df.with_columns(df["a"].scatter([0, 1], [999, 888])).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(df_pd)
                 a  b
            0  999  4
            1  888  5
            2    3  6
            >>> my_library_agnostic_function(df_pl)
            shape: (3, 2)
            ┌─────┬─────┐
            │ a   ┆ b   │
            │ --- ┆ --- │
            │ i64 ┆ i64 │
            ╞═════╪═════╡
            │ 999 ┆ 4   │
            │ 888 ┆ 5   │
            │ 3   ┆ 6   │
            └─────┴─────┘
        )rB   r&   scatter_extract_native)r   indicesvaluess      r   rV   zSeries.scatter   s9    | **""**7D4H4H4PQ
 	
r    c                .    | j                   j                  S )a  Get the shape of the Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> tuple[int]:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.shape

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            (3,)
            >>> my_library_agnostic_function(s_pl)
            (3,)
        )r&   shaper/   s    r   r[   zSeries.shape/      4 %%+++r    c                B    ddl m} t        ||      r|j                  S |S )Nr   )r   )narwhals.seriesr   r?   r&   )r   argr   s      r   rW   zSeries._extract_nativeK  s     *c6"(((
r    c                <    | j                  || j                        S )Nr*   )	__class__r$   r   r)   s     r   rB   zSeries._from_compliant_seriesR  s"    ~~++  
 	
r    c                     || g|i |S )a  Pipe function call.

        Examples:
            >>> import polars as pl
            >>> import pandas as pd
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s_pd = pd.Series([1, 2, 3, 4])
            >>> s_pl = pl.Series([1, 2, 3, 4])

            Lets define a function to pipe into
            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.pipe(lambda x: x + 2).to_native()

            Now apply it to the series

            >>> my_library_agnostic_function(s_pd)
            0    3
            1    4
            2    5
            3    6
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [i64]
            [
               3
               4
               5
               6
            ]


        r7   )r   functionargskwargss       r   pipezSeries.pipeX  s    H .t.v..r    c                ^    d}t        |      }dd|z  z   dz   d| dz   dz   dz   d|z  z   d	z   S )
Nz) Narwhals Series                         u   ┌u   ─u   ┐
|z|
z,| Use `.to_native()` to see native output |
u   └u   ┘)len)r   headerlengths      r   __repr__zSeries.__repr__~  sj    <Vfn &o >	>
  fn 		
r    c                ,    t        | j                        S r6   rk   r&   r/   s    r   __len__zSeries.__len__  s    4))**r    c                ,    t        | j                        S )ad  Return the number of elements in the Series.

        Null values count towards the total.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = [1, 2, None]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            Let's define a dataframe-agnostic function that computes the len of the series:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> int:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.len()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            3
            >>> my_library_agnostic_function(s_pl)
            3
        rp   r/   s    r   rk   z
Series.len  s    6 4))**r    c                .    | j                   j                  S )a  Get the data type of the Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> nw.dtypes.DType:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dtype

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            Int64
            >>> my_library_agnostic_function(s_pl)
            Int64
        )r&   r2   r/   s    r   r2   zSeries.dtype  r\   r    c                .    | j                   j                  S )a
  Get the name of the Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="foo")
            >>> s_pl = pl.Series("foo", s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> str:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.name

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            'foo'
            >>> my_library_agnostic_function(s_pl)
            'foo'
        )r&   namer/   s    r   ru   zSeries.name  s    4 %%***r    T   Fcomspan	half_lifealphaadjustmin_periodsignore_nullsc               d    | j                  | j                  j                  |||||||            S )a  Compute exponentially-weighted moving average.

        !!! warning
            This functionality is considered **unstable**. It may be changed at any point
            without it being considered a breaking change.

        Arguments:
            com: Specify decay in terms of center of mass, $\gamma$, with <br> $\alpha = \frac{1}{1+\gamma}\forall\gamma\geq0$
            span: Specify decay in terms of span, $\theta$, with <br> $\alpha = \frac{2}{\theta + 1} \forall \theta \geq 1$
            half_life: Specify decay in terms of half-life, $\tau$, with <br> $\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \tau } \right\} \forall \tau > 0$
            alpha: Specify smoothing factor alpha directly, $0 < \alpha \leq 1$.
            adjust: Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings

                - When `adjust=True` (the default) the EW function is calculated
                  using weights $w_i = (1 - \alpha)^i$
                - When `adjust=False` the EW function is calculated recursively by
                  $$
                  y_0=x_0
                  $$
                  $$
                  y_t = (1 - \alpha)y_{t - 1} + \alpha x_t
                  $$
            min_periods: Minimum number of observations in window required to have a value (otherwise result is null).
            ignore_nulls: Ignore missing values when calculating weights.

                - When `ignore_nulls=False` (default), weights are based on absolute
                  positions.
                  For example, the weights of $x_0$ and $x_2$ used in
                  calculating the final weighted average of $[x_0, None, x_2]$ are
                  $(1-\alpha)^2$ and $1$ if `adjust=True`, and
                  $(1-\alpha)^2$ and $\alpha$ if `adjust=False`.
                - When `ignore_nulls=True`, weights are based
                  on relative positions. For example, the weights of
                  $x_0$ and $x_2$ used in calculating the final weighted
                  average of $[x_0, None, x_2]$ are
                  $1-\alpha$ and $1$ if `adjust=True`,
                  and $1-\alpha$ and $\alpha$ if `adjust=False`.

        Returns:
            Series

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [1, 2, 3]
            >>> s_pd = pd.Series(name="a", data=data)
            >>> s_pl = pl.Series(name="a", values=data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.ewm_mean(com=1, ignore_nulls=False).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1.000000
            1    1.666667
            2    2.428571
            Name: a, dtype: float64

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: 'a' [f64]
            [
               1.0
               1.666667
               2.428571
            ]
        rw   )rB   r&   ewm_mean)r   rx   ry   rz   r{   r|   r}   r~   s           r   r   zSeries.ewm_mean  sF    h **""++#') , 

 
	
r    c                l    t        |       | j                  | j                  j                  |            S )aH  Cast between data types.

        Arguments:
            dtype: Data type that the object will be cast into.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [True, False, True]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cast(nw.Int64).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    0
            2    1
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               1
               0
               1
            ]
        )r   rB   r&   cast)r   r2   s     r   r   zSeries.castD  s/    J 	**4+A+A+F+Fu+MNNr    c                l    | j                  | j                  j                         | j                        S )u  Convert to dataframe.

        Returns:
            A new DataFrame.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries, IntoDataFrame
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="a")
            >>> s_pl = pl.Series("a", s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> IntoDataFrame:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_frame().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
               a
            0  1
            1  2
            2  3
            >>> my_library_agnostic_function(s_pl)
            shape: (3, 1)
            ┌─────┐
            │ a   │
            │ --- │
            │ i64 │
            ╞═════╡
            │ 1   │
            │ 2   │
            │ 3   │
            └─────┘
        ra   )r   r&   to_framer$   r/   s    r   r   zSeries.to_framel  s4    P ""++-++  
 	
r    c                6    | j                   j                         S )aC  Convert to list.

        Notes:
            This function converts to Python scalars. It's typically
            more efficient to keep your data in the format native to
            your original dataframe, so we recommend only calling this
            when you absolutely need to.

        Returns:
            A list of Python objects.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="a")
            >>> s_pl = pl.Series("a", s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_list()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            [1, 2, 3]
            >>> my_library_agnostic_function(s_pl)
            [1, 2, 3]
        )r&   to_listr/   s    r   r   zSeries.to_list  s    D %%--//r    c                6    | j                   j                         S )a  Reduce this Series to the mean value.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.mean()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.float64(2.0)
            >>> my_library_agnostic_function(s_pl)
            2.0
        )r&   meanr/   s    r   r   zSeries.mean  s    2 %%**,,r    c                6    | j                   j                         S )aW  Reduce this Series to the median value.

        Notes:
            Results might slightly differ across backends due to differences in the underlying algorithms used to compute the median.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [5, 3, 8]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)
            >>> s_pa = pa.chunked_array([s])

            Let's define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.median()

            We can then pass any supported library such as pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.float64(5.0)
            >>> my_library_agnostic_function(s_pl)
            5.0
            >>> my_library_agnostic_function(s_pa)
            5.0
        )r&   medianr/   s    r   r   zSeries.median  s    @ %%,,..r    c                6    | j                   j                         S )a  Calculate the sample skewness of the Series.

        Returns:
            The sample skewness of the Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> s = [1, 1, 2, 10, 100]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)
            >>> s_pa = pa.array(s)

            We define a library agnostic function:

            >>> @nw.narwhalify
            ... def func(s):
            ...     return s.skew()

            We can pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> func(s_pd)
            np.float64(1.4724267269058975)
            >>> func(s_pl)
            1.4724267269058975

        Notes:
            The skewness is a measure of the asymmetry of the probability distribution.
            A perfectly symmetric distribution has a skewness of 0.
        )r&   skewr/   s    r   r   zSeries.skew  s    B %%**,,r    c                6    | j                   j                         S )a  Returns the number of non-null elements in the Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.count()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.int64(3)
            >>> my_library_agnostic_function(s_pl)
            3

        )r&   countr/   s    r   r   zSeries.count  s    4 %%++--r    c                6    | j                   j                         S )a`  Return whether any of the values in the Series are True.

        Notes:
          Only works on Series of data type Boolean.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [False, True, False]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.any()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.True_
            >>> my_library_agnostic_function(s_pl)
            True
        )r&   anyr/   s    r   r   z
Series.any9  s    8 %%))++r    c                6    | j                   j                         S )a  Return whether all values in the Series are True.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [True, False, True]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.all()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.False_
            >>> my_library_agnostic_function(s_pl)
            False

        )r&   allr/   s    r   r   z
Series.allW  s    4 %%))++r    c                6    | j                   j                         S )a  Get the minimal value in this Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.min()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.int64(1)
            >>> my_library_agnostic_function(s_pl)
            1
        )r&   minr/   s    r   r   z
Series.mins      2 %%))++r    c                6    | j                   j                         S )a  Get the maximum value in this Series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.max()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.int64(3)
            >>> my_library_agnostic_function(s_pl)
            3
        )r&   maxr/   s    r   r   z
Series.max  r   r    c                6    | j                   j                         S )a  Returns the index of the minimum value.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)
            >>> s_pa = pa.chunked_array([s])

            We define a library agnostic function:

            >>> def agnostic_arg_min(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.arg_min()

            We can then pass either any supported library such as pandas, Polars,
            or PyArrow:

            >>> agnostic_arg_min(s_pd)
            np.int64(0)
            >>> agnostic_arg_min(s_pl)
            0
            >>> agnostic_arg_min(s_pa)
            0
        )r&   arg_minr/   s    r   r   zSeries.arg_min      < %%--//r    c                6    | j                   j                         S )a  Returns the index of the maximum value.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)
            >>> s_pa = pa.chunked_array([s])

            We define a library agnostic function:

            >>> def agnostic_arg_max(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.arg_max()

            We can then pass either any supported library such as pandas, Polars,
            or PyArrow:

            >>> agnostic_arg_max(s_pd)
            np.int64(2)
            >>> agnostic_arg_max(s_pl)
            2
            >>> agnostic_arg_max(s_pa)
            2
        )r&   arg_maxr/   s    r   r   zSeries.arg_max  r   r    c                6    | j                   j                         S )a  Reduce this Series to the sum value.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.sum()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.int64(6)
            >>> my_library_agnostic_function(s_pl)
            6
        )r&   sumr/   s    r   r   z
Series.sum  r   r    ddofc               :    | j                   j                  |      S )u  Get the standard deviation of this Series.

        Arguments:
            ddof: “Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof,
                     where N represents the number of elements.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.std()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            np.float64(1.0)
            >>> my_library_agnostic_function(s_pl)
            1.0
        r   )r&   std)r   r   s     r   r   z
Series.std  s    : %%))t)44r    c                Z    | j                  | j                  j                  ||            S )af
  Clip values in the Series.

        Arguments:
            lower_bound: Lower bound value.
            upper_bound: Upper bound value.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>>
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def clip_lower(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.clip(2).to_native()

            We can then pass either pandas or Polars to `clip_lower`:

            >>> clip_lower(s_pd)
            0    2
            1    2
            2    3
            dtype: int64
            >>> clip_lower(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               2
               2
               3
            ]

            We define another library agnostic function:

            >>> def clip_upper(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.clip(upper_bound=2).to_native()

            We can then pass either pandas or Polars to `clip_upper`:

            >>> clip_upper(s_pd)
            0    1
            1    2
            2    2
            dtype: int64
            >>> clip_upper(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               1
               2
               2
            ]

            We can have both at the same time

            >>> s = [-1, 1, -3, 3, -5, 5]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.clip(-1, 3).to_native()

            We can pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0   -1
            1    1
            2   -1
            3    3
            4   -1
            5    3
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (6,)
            Series: '' [i64]
            [
               -1
                1
               -1
                3
               -1
                3
            ]
        )lower_boundupper_bound)rB   r&   clip)r   r   r   s      r   r   zSeries.clip#  s1    B **""''K['Y
 	
r    c                t    | j                  | j                  j                  | j                  |                  S )a\  Check if the elements of this Series are in the other sequence.

        Arguments:
            other: Sequence of primitive type.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s_pd = pd.Series([1, 2, 3])
            >>> s_pl = pl.Series([1, 2, 3])

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_in([3, 2, 8]).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    False
            1     True
            2     True
            dtype: bool
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [bool]
            [
               false
               true
               true
            ]
        )rB   r&   is_inrW   r   others     r   r   zSeries.is_in  s7    H **""(()=)=e)DE
 	
r    c                T    | j                  | j                  j                               S )a  Find elements where boolean Series is True.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [1, None, None, 2]
            >>> s_pd = pd.Series(data, name="a")
            >>> s_pl = pl.Series("a", data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_null().arg_true().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            1    1
            2    2
            Name: a, dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: 'a' [u32]
            [
               1
               2
            ]
        )rB   r&   arg_truer/   s    r   r   zSeries.arg_true  s%    @ **4+A+A+J+J+LMMr    c                T    | j                  | j                  j                               S )a  Drop all null values.

        Notes:
          pandas and Polars handle null values differently. Polars distinguishes
          between NaN and Null, whereas pandas doesn't.

        Examples:
          >>> import pandas as pd
          >>> import polars as pl
          >>> import numpy as np
          >>> import narwhals as nw
          >>> from narwhals.typing import IntoSeriesT
          >>> s_pd = pd.Series([2, 4, None, 3, 5])
          >>> s_pl = pl.Series("a", [2, 4, None, 3, 5])

          Now define a dataframe-agnostic function with a `column` argument for the column to evaluate :

          >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
          ...     s = nw.from_native(s_native, series_only=True)
          ...     return s.drop_nulls().to_native()

          Then we can pass either Series (polars or pandas) to `func`:

          >>> my_library_agnostic_function(s_pd)
          0    2.0
          1    4.0
          3    3.0
          4    5.0
          dtype: float64
          >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
          shape: (4,)
          Series: 'a' [i64]
          [
             2
             4
             3
             5
          ]
        )rB   r&   
drop_nullsr/   s    r   r   zSeries.drop_nulls  s%    P **4+A+A+L+L+NOOr    c                T    | j                  | j                  j                               S )a  Calculate the absolute value of each element.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [2, -4, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.abs().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2
            1    4
            2    3
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               2
               4
               3
            ]
        )rB   r&   absr/   s    r   r   z
Series.abs  s%    D **4+A+A+E+E+GHHr    reversec               X    | j                  | j                  j                  |            S )a)  Calculate the cumulative sum.

        Arguments:
            reverse: reverse the operation

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [2, 4, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cum_sum().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2
            1    6
            2    9
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               2
               6
               9
            ]
        r   )rB   r&   cum_sumr   r   s     r   r   zSeries.cum_sum   s/    J **""**7*;
 	
r    maintain_orderc               X    | j                  | j                  j                  |            S )a  Returns unique values of the series.

        Arguments:
            maintain_order: Keep the same order as the original series. This may be more
                expensive to compute. Settings this to `True` blocks the possibility
                to run on the streaming engine for Polars.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [2, 4, 4, 6]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.unique(maintain_order=True).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2
            1    4
            2    6
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               2
               4
               6
            ]
        r   )rB   r&   unique)r   r   s     r   r   zSeries.uniqueI  s/    N **"")))H
 	
r    c                T    | j                  | j                  j                               S )a  Calculate the difference with the previous element, for each element.

        Notes:
            pandas may change the dtype here, for example when introducing missing
            values in an integer column. To ensure, that the dtype doesn't change,
            you may want to use `fill_null` and `cast`. For example, to calculate
            the diff and fill missing values with `0` in a Int64 column, you could
            do:

                s.diff().fill_null(0).cast(nw.Int64)

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [2, 4, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.diff().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    NaN
            1    2.0
            2   -1.0
            dtype: float64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               null
               2
               -1
            ]
        )rB   r&   diffr/   s    r   r   zSeries.difft  s%    V **4+A+A+F+F+HIIr    c                V    | j                  | j                  j                  |            S )a7  Shift values by `n` positions.

        Arguments:
            n: Number of indices to shift forward. If a negative value is passed,
                values are shifted in the opposite direction instead.

        Notes:
            pandas may change the dtype here, for example when introducing missing
            values in an integer column. To ensure, that the dtype doesn't change,
            you may want to use `fill_null` and `cast`. For example, to shift
            and fill missing values with `0` in a Int64 column, you could
            do:

                s.shift(1).fill_null(0).cast(nw.Int64)

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [2, 4, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.shift(1).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    NaN
            1    2.0
            2    4.0
            dtype: float64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               null
               2
               4
            ]
        )rB   r&   shiftr   ns     r   r   zSeries.shift  s'    ^ **4+A+A+G+G+JKKr    )fractionwith_replacementseedc               ^    | j                  | j                  j                  ||||            S )az  Sample randomly from this Series.

        Arguments:
            n: Number of items to return. Cannot be used with fraction.
            fraction: Fraction of items to return. Cannot be used with n.
            with_replacement: Allow values to be sampled more than once.
            seed: Seed for the random number generator. If set to None (default), a random
                seed is generated for each sample operation.

        Notes:
            The `sample` method returns a Series with a specified number of
            randomly selected items chosen from this Series.
            The results are not consistent across libraries.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl

            >>> s_pd = pd.Series([1, 2, 3, 4])
            >>> s_pl = pl.Series([1, 2, 3, 4])

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.sample(fraction=1.0, with_replacement=True).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +SKIP
               a
            2  3
            1  2
            3  4
            3  4
            >>> my_library_agnostic_function(s_pl)  # doctest: +SKIP
            shape: (4,)
            Series: '' [i64]
            [
               1
               4
               3
               4
            ]
        )r   r   r   r   )rB   r&   sample)r   r   r   r   r   s        r   r   zSeries.sample  s<    n **""))h9IPT * 
 	
r    c                X    | j                  | j                  j                  |            S )aT  Rename the Series.

        Notes:
            This method is very cheap, but does not guarantee that data
            will be copied. For example:

            ```python
            s1: nw.Series
            s2 = s1.alias("foo")
            arr = s2.to_numpy()
            arr[0] = 999
            ```

            may (depending on the backend, and on the version) result in
            `s1`'s data being modified. We recommend:

                - if you need to alias an object and don't need the original
                  one around any more, just use `alias` without worrying about it.
                - if you were expecting `alias` to copy data, then explicily call
                  `.clone` before calling `alias`.

        Arguments:
            name: The new name.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="foo")
            >>> s_pl = pl.Series("foo", s)
            >>> s_pa = pa.chunked_array([s])

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.alias("bar").to_native()

            We can then pass any supported library such as pandas, Polars, or PyArrow:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    2
            2    3
            Name: bar, dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: 'bar' [i64]
            [
               1
               2
               3
            ]
            >>> my_library_agnostic_function(s_pa)  # doctest: +ELLIPSIS
            <pyarrow.lib.ChunkedArray object at 0x...>
            [
              [
                1,
                2,
                3
              ]
            ]
        ru   )rB   r&   aliasr   ru   s     r   r   zSeries.alias  s*    F **4+A+A+G+GT+G+RSSr    c                &    | j                  |      S )a  Rename the Series.

        Alias for `Series.alias()`.

        Notes:
            This method is very cheap, but does not guarantee that data
            will be copied. For example:

            ```python
            s1: nw.Series
            s2 = s1.rename("foo")
            arr = s2.to_numpy()
            arr[0] = 999
            ```

            may (depending on the backend, and on the version) result in
            `s1`'s data being modified. We recommend:

                - if you need to rename an object and don't need the original
                  one around any more, just use `rename` without worrying about it.
                - if you were expecting `rename` to copy data, then explicily call
                  `.clone` before calling `rename`.

        Arguments:
            name: The new name.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="foo")
            >>> s_pl = pl.Series("foo", s)
            >>> s_pa = pa.chunked_array([s])

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.rename("bar").to_native()

            We can then pass any supported library such as pandas, Polars, or PyArrow:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    2
            2    3
            Name: bar, dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: 'bar' [i64]
            [
               1
               2
               3
            ]
            >>> my_library_agnostic_function(s_pa)  # doctest: +ELLIPSIS
            <pyarrow.lib.ChunkedArray object at 0x...>
            [
              [
                1,
                2,
                3
              ]
            ]
        r   )r   r   s     r   renamezSeries.renameT  s    J zztz$$r    return_dtypec                   |Ot        |t              sd}t        |      t        |j	                               }t        |j                               }| j                  | j                  j                  |||            S )a  Replace all values by different values.

        This function must replace all non-null input values (else it raises an error).

        Arguments:
            old: Sequence of values to replace. It also accepts a mapping of values to
                their replacement as syntactic sugar for
                `replace_all(old=list(mapping.keys()), new=list(mapping.values()))`.
            new: Sequence of values to replace by. Length must match the length of `old`.
            return_dtype: The data type of the resulting expression. If set to `None`
                (default), the data type is determined automatically based on the other
                inputs.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> df_pd = pd.DataFrame({"a": [3, 0, 1, 2]})
            >>> df_pl = pl.DataFrame({"a": [3, 0, 1, 2]})
            >>> df_pa = pa.table({"a": [3, 0, 1, 2]})

            Let's define dataframe-agnostic functions:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.replace_strict(
            ...         [0, 1, 2, 3], ["zero", "one", "two", "three"], return_dtype=nw.String
            ...     ).to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(df_pd["a"])
            0    three
            1     zero
            2      one
            3      two
            Name: a, dtype: object
            >>> my_library_agnostic_function(df_pl["a"])  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: 'a' [str]
            [
                "three"
                "zero"
                "one"
                "two"
            ]
            >>> my_library_agnostic_function(df_pa["a"])
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                "three",
                "zero",
                "one",
                "two"
              ]
            ]
        zB`new` argument is required if `old` argument is not a Mapping typer   )	r?   r
   	TypeErrorlistrY   keysrB   r&   replace_strict)r   oldnewr   r+   s        r   r   zSeries.replace_strict  sq    D ;c7+Zn$szz|$Csxxz"C**""11#s1V
 	
r    
descending
nulls_lastc               Z    | j                  | j                  j                  ||            S )a  Sort this Series. Place null values first.

        Arguments:
            descending: Sort in descending order.
            nulls_last: Place null values last instead of first.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [5, None, 1, 2]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define library agnostic functions:

            >>> def agnostic_sort(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.sort().to_native()

            >>> def agnostic_sort_descending(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.sort(descending=True).to_native()

            We can then pass either pandas or Polars to `agnostic_sort`:

            >>> agnostic_sort(s_pd)
            1    NaN
            2    1.0
            3    2.0
            0    5.0
            dtype: float64
            >>> agnostic_sort(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [i64]
            [
               null
               1
               2
               5
            ]
            >>> agnostic_sort_descending(s_pd)
            1    NaN
            0    5.0
            3    2.0
            2    1.0
            dtype: float64
            >>> agnostic_sort_descending(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [i64]
            [
               null
               5
               2
               1
            ]
        r   )rB   r&   sort)r   r   r   s      r   r   zSeries.sort  s1    v **""'':*'U
 	
r    c                T    | j                  | j                  j                               S )a  Returns a boolean Series indicating which values are null.

        Notes:
            pandas and Polars handle null values differently. Polars distinguishes
            between NaN and Null, whereas pandas doesn't.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [1, 2, None]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_null().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    False
            1    False
            2     True
            dtype: bool
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [bool]
            [
               false
               false
               true
            ]
        )rB   r&   is_nullr/   s    r   r   zSeries.is_null(  s%    L **4+A+A+I+I+KLLr    c                    ||d}t        |      ||d}t        |      ||dvrd| }t        |      | j                  | j                  j                  |||            S )a  Fill null values using the specified value.

        Arguments:
            value: Value used to fill null values.

            strategy: Strategy used to fill null values.

            limit: Number of consecutive null values to fill when using the 'forward' or 'backward' strategy.

        Notes:
            pandas and Polars handle null values differently. Polars distinguishes
            between NaN and Null, whereas pandas doesn't.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [1, 2, None]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.fill_null(5).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1.0
            1    2.0
            2    5.0
            dtype: float64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               1
               2
               5
            ]

            Using a strategy:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.fill_null(strategy="forward", limit=1).to_native()

            >>> my_library_agnostic_function(s_pd)
            0    1.0
            1    2.0
            2    2.0
            dtype: float64

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               1
               2
               2
            ]
        z*cannot specify both `value` and `strategy`z0must specify either a fill `value` or `strategy`>   forwardbackwardzstrategy not supported: )valuestrategylimit)
ValueErrorrB   r&   	fill_null)r   r   r   r   r+   s        r   r   zSeries.fill_nullP  s    N !5>CS/!=X-DCS/!H4K$K,XJ7CS/!**"",,58SX,Y
 	
r    c                \    | j                  | j                  j                  |||            S )a  Get a boolean mask of the values that are between the given lower/upper bounds.

        Arguments:
            lower_bound: Lower bound value.

            upper_bound: Upper bound value.

            closed: Define which sides of the interval are closed (inclusive).

        Notes:
            If the value of the `lower_bound` is greater than that of the `upper_bound`,
            then the values will be False, as no value can satisfy the condition.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s_pd = pd.Series([1, 2, 3, 4, 5])
            >>> s_pl = pl.Series([1, 2, 3, 4, 5])

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_between(2, 4, "right").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    False
            1    False
            2     True
            3     True
            4    False
            dtype: bool
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: '' [bool]
            [
               false
               false
               true
               true
               false
            ]
        )closed)rB   r&   
is_between)r   r   r   r   s       r   r   zSeries.is_between  s3    d **""--k;v-V
 	
r    c                6    | j                   j                         S )a  Count the number of unique values.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 2, 3]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.n_unique()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            3
            >>> my_library_agnostic_function(s_pl)
            3
        )r&   n_uniquer/   s    r   r   zSeries.n_unique  s    2 %%..00r    c                6    | j                   j                         S )aH  Convert to numpy.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> import numpy as np
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="a")
            >>> s_pl = pl.Series("a", s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> np.ndarray:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_numpy()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            array([1, 2, 3]...)
            >>> my_library_agnostic_function(s_pl)
            array([1, 2, 3]...)
        )r&   to_numpyr/   s    r   r   zSeries.to_numpy  s    4 %%..00r    c                6    | j                   j                         S )a  Convert to pandas.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> s = [1, 2, 3]
            >>> s_pd = pd.Series(s, name="a")
            >>> s_pl = pl.Series("a", s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> pd.Series:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_pandas()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    2
            2    3
            Name: a, dtype: int64
            >>> my_library_agnostic_function(s_pl)
            0    1
            1    2
            2    3
            Name: a, dtype: int64
        )r&   	to_pandasr/   s    r   r   zSeries.to_pandas  s    > %%//11r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __add__rW   r   s     r   r   zSeries.__add__2  4    **""**4+?+?+FG
 	
r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __radd__rW   r   s     r   r   zSeries.__radd__7  4    **""++D,@,@,GH
 	
r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __sub__rW   r   s     r   r   zSeries.__sub__<  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rsub__rW   r   s     r   r   zSeries.__rsub__A  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __mul__rW   r   s     r   r   zSeries.__mul__F  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rmul__rW   r   s     r   r   zSeries.__rmul__K  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __truediv__rW   r   s     r   r   zSeries.__truediv__P  s4    **""..t/C/CE/JK
 	
r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rtruediv__rW   r   s     r   r   zSeries.__rtruediv__U  4    **""//0D0DU0KL
 	
r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __floordiv__rW   r   s     r   r   zSeries.__floordiv__Z  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rfloordiv__rW   r   s     r   r  zSeries.__rfloordiv___  s4    **""001E1Ee1LM
 	
r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __pow__rW   r   s     r   r  zSeries.__pow__d  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rpow__rW   r   s     r   r  zSeries.__rpow__i  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __mod__rW   r   s     r   r  zSeries.__mod__n  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rmod__rW   r   s     r   r
  zSeries.__rmod__s  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __eq__rW   r   s     r   r  zSeries.__eq__x  4    **""))$*>*>u*EF
 	
r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __ne__rW   r   s     r   r  zSeries.__ne__}  r  r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __gt__rW   r   s     r   r  zSeries.__gt__  r  r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __ge__rW   r   s     r   r  zSeries.__ge__  r  r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __lt__rW   r   s     r   r  zSeries.__lt__  r  r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __le__rW   r   s     r   r  zSeries.__le__  r  r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __and__rW   r   s     r   r  zSeries.__and__  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __rand__rW   r   s     r   r  zSeries.__rand__  r   r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __or__rW   r   s     r   r  zSeries.__or__  r  r    c                t    | j                  | j                  j                  | j                  |                  S r6   )rB   r&   __ror__rW   r   s     r   r  zSeries.__ror__  r   r    c                T    | j                  | j                  j                               S r6   )rB   r&   
__invert__r/   s    r   r!  zSeries.__invert__  s"    **4+A+A+L+L+NOOr    c                t    | j                  | j                  j                  | j                  |                  S )a  Filter elements in the Series based on a condition.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> s = [4, 10, 15, 34, 50]
            >>> s_pd = pd.Series(s)
            >>> s_pl = pl.Series(s)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.filter(s > 10).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            2    15
            3    34
            4    50
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               15
               34
               50
            ]
        )rB   r&   filterrW   r   s     r   r#  zSeries.filter  s7    D **""))$*>*>u*EF
 	
r    c                T    | j                  | j                  j                               S )a  Get a mask of all duplicated rows in the Series.

        Returns:
            A new Series.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> s_pd = pd.Series([1, 2, 3, 1])
            >>> s_pl = pl.Series([1, 2, 3, 1])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_duplicated().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0     True
            1    False
            2    False
            3     True
            dtype: bool
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [bool]
            [
                true
                false
                false
                true
            ]
        )rB   r&   is_duplicatedr/   s    r   r%  zSeries.is_duplicated  s%    L **4+A+A+O+O+QRRr    c                6    | j                   j                         S )a*  Check if the series is empty.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pandas as pd
            >>> import polars as pl

            Let's define a dataframe-agnostic function that filters rows in which "foo"
            values are greater than 10, and then checks if the result is empty or not:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.filter(s > 10).is_empty()

            We can then pass either pandas or Polars to `func`:

            >>> s_pd = pd.Series([1, 2, 3])
            >>> s_pl = pl.Series([1, 2, 3])
            >>> my_library_agnostic_function(s_pd), my_library_agnostic_function(s_pl)
            (True, True)

            >>> s_pd = pd.Series([100, 2, 3])
            >>> s_pl = pl.Series([100, 2, 3])
            >>> my_library_agnostic_function(s_pd), my_library_agnostic_function(s_pl)
            (False, False)
        )r&   is_emptyr/   s    r   r'  zSeries.is_empty  s    8 %%..00r    c                T    | j                  | j                  j                               S )aa  Get a mask of all unique rows in the Series.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> s_pd = pd.Series([1, 2, 3, 1])
            >>> s_pl = pl.Series([1, 2, 3, 1])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_unique().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0    False
            1     True
            2     True
            3    False
            dtype: bool

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [bool]
            [
                false
                 true
                 true
                false
            ]
        )rB   r&   	is_uniquer/   s    r   r)  zSeries.is_unique	  s%    H **4+A+A+K+K+MNNr    c                6    | j                   j                         S )a  Create a new Series that shows the null counts per column.

        Notes:
            pandas and Polars handle null values differently. Polars distinguishes
            between NaN and Null, whereas pandas doesn't.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pandas as pd
            >>> import polars as pl
            >>> s_pd = pd.Series([1, None, 3])
            >>> s_pl = pl.Series([1, None, None])

            Let's define a dataframe-agnostic function that returns the null count of
            the series:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.null_count()

            We can then pass either pandas or Polars to `func`:
            >>> my_library_agnostic_function(s_pd)
            np.int64(1)
            >>> my_library_agnostic_function(s_pl)
            2
        )r&   
null_countr/   s    r   r+  zSeries.null_countA	  s    8 %%0022r    c                T    | j                  | j                  j                               S )a  Return a boolean mask indicating the first occurrence of each distinct value.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> s_pd = pd.Series([1, 1, 2, 3, 2])
            >>> s_pl = pl.Series([1, 1, 2, 3, 2])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_first_distinct().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0     True
            1    False
            2     True
            3     True
            4    False
            dtype: bool

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: '' [bool]
            [
                true
                false
                true
                true
                false
            ]
        )rB   r&   is_first_distinctr/   s    r   r-  zSeries.is_first_distinct_	  s%    L **4+A+A+S+S+UVVr    c                T    | j                  | j                  j                               S )a  Return a boolean mask indicating the last occurrence of each distinct value.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> s_pd = pd.Series([1, 1, 2, 3, 2])
            >>> s_pl = pl.Series([1, 1, 2, 3, 2])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_last_distinct().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0    False
            1     True
            2    False
            3     True
            4     True
            dtype: bool

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: '' [bool]
            [
                false
                true
                false
                true
                true
            ]
        )rB   r&   is_last_distinctr/   s    r   r/  zSeries.is_last_distinct	  s%    L **4+A+A+R+R+TUUr    r   c               :    | j                   j                  |      S )a  Check if the Series is sorted.

        Arguments:
            descending: Check if the Series is sorted in descending order.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pandas as pd
            >>> import polars as pl
            >>> unsorted_data = [1, 3, 2]
            >>> sorted_data = [3, 2, 1]

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(
            ...     s_native: IntoSeries, descending: bool = False
            ... ):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_sorted(descending=descending)

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(pl.Series(unsorted_data))
            False
            >>> my_library_agnostic_function(pl.Series(sorted_data), descending=True)
            True
            >>> my_library_agnostic_function(pd.Series(unsorted_data))
            False
            >>> my_library_agnostic_function(pd.Series(sorted_data), descending=True)
            True
        r0  )r&   	is_sorted)r   r   s     r   r2  zSeries.is_sorted	  s    B %%//:/FFr    r   parallelru   	normalizec               v    | j                  | j                  j                  ||||      | j                        S )u  Count the occurrences of unique values.

        Arguments:
            sort: Sort the output by count in descending order. If set to False (default),
                the order of the output is random.
            parallel: Execute the computation in parallel. Used for Polars only.
            name: Give the resulting count column a specific name; if `normalize` is True
                defaults to "proportion", otherwise defaults to "count".
            normalize: If true gives relative frequencies of the unique values

        Returns:
            A new DataFrame.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries, IntoDataFrame
            >>> import pandas as pd
            >>> import polars as pl
            >>> s_pd = pd.Series([1, 1, 2, 3, 2], name="s")
            >>> s_pl = pl.Series(values=[1, 1, 2, 3, 2], name="s")

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> IntoDataFrame:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.value_counts(sort=True).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
               s  count
            0  1      2
            1  2      2
            2  3      1

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3, 2)
            ┌─────┬───────┐
            │ s   ┆ count │
            │ --- ┆ ---   │
            │ i64 ┆ u32   │
            ╞═════╪═══════╡
            │ 1   ┆ 2     │
            │ 2   ┆ 2     │
            │ 3   ┆ 1     │
            └─────┴───────┘
        r3  ra   )r   r&   value_countsr$   )r   r   r4  ru   r5  s        r   r7  zSeries.value_counts	  sF    n ""//H49 0  ++	  
 	
r    c                <    | j                   j                  ||      S )a  Get quantile value of the series.

        Note:
            pandas and Polars may have implementation differences for a given interpolation method.

        Arguments:
            quantile: Quantile between 0.0 and 1.0.
            interpolation: Interpolation method.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = list(range(50))
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeries):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return [
            ...         s.quantile(quantile=q, interpolation="nearest")
            ...         for q in (0.1, 0.25, 0.5, 0.75, 0.9)
            ...     ]

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            [np.int64(5), np.int64(12), np.int64(24), np.int64(37), np.int64(44)]

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            [5.0, 12.0, 25.0, 37.0, 44.0]
        )quantileinterpolation)r&   r9  )r   r9  r:  s      r   r9  zSeries.quantile
  s(    P %%..] / 
 	
r    c                    | j                  | j                  j                  | j                  |      | j                  |                  S )aP  Take values from self or other based on the given mask.

        Where mask evaluates true, take values from self. Where mask evaluates false,
        take values from other.

        Arguments:
            mask: Boolean Series
            other: Series of same type.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> s1_pl = pl.Series([1, 2, 3, 4, 5])
            >>> s2_pl = pl.Series([5, 4, 3, 2, 1])
            >>> mask_pl = pl.Series([True, False, True, False, True])
            >>> s1_pd = pd.Series([1, 2, 3, 4, 5])
            >>> s2_pd = pd.Series([5, 4, 3, 2, 1])
            >>> mask_pd = pd.Series([True, False, True, False, True])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(
            ...     s1_native: IntoSeriesT, mask_native: IntoSeriesT, s2_native: IntoSeriesT
            ... ) -> IntoSeriesT:
            ...     s1 = nw.from_native(s1_native, series_only=True)
            ...     mask = nw.from_native(mask_native, series_only=True)
            ...     s2 = nw.from_native(s2_native, series_only=True)
            ...     return s1.zip_with(mask, s2).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(
            ...     s1_pl, mask_pl, s2_pl
            ... )  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: '' [i64]
            [
               1
               4
               3
               2
               5
            ]
            >>> my_library_agnostic_function(s1_pd, mask_pd, s2_pd)
            0    1
            1    4
            2    3
            3    2
            4    5
            dtype: int64
        )rB   r&   zip_withrW   )r   maskr   s      r   r<  zSeries.zip_with<
  sG    l **""++$$T*D,@,@,G
 	
r    c                :    | j                   j                  |      S )a  Return the Series as a scalar, or return the element at the given index.

        If no index is provided, this is equivalent to `s[0]`, with a check
        that the shape is (1,). With an index, this is equivalent to `s[index]`.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pandas as pd
            >>> import polars as pl

            Let's define a dataframe-agnostic function that returns item at given index

            >>> def my_library_agnostic_function(s_native: IntoSeries, index=None):
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.item(index)

            We can then pass either pandas or Polars to `func`:

            >>> (
            ...     my_library_agnostic_function(pl.Series("a", [1]), None),
            ...     my_library_agnostic_function(pd.Series([1]), None),
            ... )
            (1, np.int64(1))

            >>> (
            ...     my_library_agnostic_function(pl.Series("a", [9, 8, 7]), -1),
            ...     my_library_agnostic_function(pl.Series([9, 8, 7]), -2),
            ... )
            (7, 8)
        )index)r&   item)r   r?  s     r   r@  zSeries.itemx
  s    @ %%***77r    c                V    | j                  | j                  j                  |            S )ar  Get the first `n` rows.

        Arguments:
            n: Number of rows to return.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = list(range(10))
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            Let's define a dataframe-agnostic function that returns the first 3 rows:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.head(3).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0    0
            1    1
            2    2
            dtype: int64

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               0
               1
               2
            ]
        )rB   r&   headr   s     r   rB  zSeries.head
  s'    L **4+A+A+F+Fq+IJJr    c                V    | j                  | j                  j                  |            S )ao  Get the last `n` rows.

        Arguments:
            n: Number of rows to return.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = list(range(10))
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            Let's define a dataframe-agnostic function that returns the last 3 rows:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.tail(3).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            7    7
            8    8
            9    9
            dtype: int64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
               7
               8
               9
            ]
        )rB   r&   tailr   s     r   rD  zSeries.tail
  s'    J **4+A+A+F+Fq+IJJr    c                V    | j                  | j                  j                  |            S )aQ  Round underlying floating point data by `decimals` digits.

        Arguments:
            decimals: Number of decimals to round by.

        Notes:
            For values exactly halfway between rounded decimal values pandas behaves differently than Polars and Arrow.

            pandas rounds to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5 round to 2.0, 3.5 and
            4.5 to 4.0, etc..).

            Polars and Arrow round away from 0 (e.g. -0.5 to -1.0, 0.5 to 1.0, 1.5 to 2.0, 2.5 to 3.0, etc..).

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = [1.12345, 2.56789, 3.901234]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            Let's define a dataframe-agnostic function that rounds to the first decimal:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.round(1).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0    1.1
            1    2.6
            2    3.9
            dtype: float64

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [f64]
            [
               1.1
               2.6
               3.9
            ]
        )rB   r&   round)r   decimalss     r   rF  zSeries.round
  s'    \ **4+A+A+G+G+QRRr    _	separator
drop_firstc               r    | j                  | j                  j                  ||      | j                        S )u	  Get dummy/indicator variables.

        Arguments:
            separator: Separator/delimiter used when generating column names.
            drop_first: Remove the first category from the variable being encoded.

        Notes:
            pandas and Polars handle null values differently. Polars distinguishes
            between NaN and Null, whereas pandas doesn't.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries, IntoDataFrame
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = [1, 2, 3]
            >>> s_pd = pd.Series(data, name="a")
            >>> s_pl = pl.Series("a", data)

            Let's define a dataframe-agnostic function that rounds to the first decimal:

            >>> def my_library_agnostic_function(
            ...     s_native: IntoSeries, drop_first: bool = False
            ... ) -> IntoDataFrame:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_dummies(drop_first=drop_first).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
               a_1  a_2  a_3
            0    1    0    0
            1    0    1    0
            2    0    0    1

            >>> my_library_agnostic_function(s_pd, drop_first=True)
               a_2  a_3
            0    0    0
            1    1    0
            2    0    1

            >>> my_library_agnostic_function(s_pl)
            shape: (3, 3)
            ┌─────┬─────┬─────┐
            │ a_1 ┆ a_2 ┆ a_3 │
            │ --- ┆ --- ┆ --- │
            │ i8  ┆ i8  ┆ i8  │
            ╞═════╪═════╪═════╡
            │ 1   ┆ 0   ┆ 0   │
            │ 0   ┆ 1   ┆ 0   │
            │ 0   ┆ 0   ┆ 1   │
            └─────┴─────┴─────┘
            >>> my_library_agnostic_function(s_pl, drop_first=True)
            shape: (3, 2)
            ┌─────┬─────┐
            │ a_2 ┆ a_3 │
            │ --- ┆ --- │
            │ i8  ┆ i8  │
            ╞═════╪═════╡
            │ 0   ┆ 0   │
            │ 1   ┆ 0   │
            │ 0   ┆ 1   │
            └─────┴─────┘
        rI  ra   )r   r&   
to_dummiesr$   )r   rJ  rK  s      r   rM  zSeries.to_dummies  s;    F ""--	j-Y++  
 	
r    c                Z    | j                  | j                  j                  ||            S )a  Take every nth value in the Series and return as new Series.

        Arguments:
            n: Gather every *n*-th row.
            offset: Starting index.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = [1, 2, 3, 4]
            >>> s_pd = pd.Series(name="a", data=data)
            >>> s_pl = pl.Series(name="a", values=data)

            Let's define a dataframe-agnostic function in which gather every 2 rows,
            starting from a offset of 1:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.gather_every(n=2, offset=1).to_native()

            >>> my_library_agnostic_function(s_pd)
            1    2
            3    4
            Name: a, dtype: int64

            >>> my_library_agnostic_function(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (2,)
            Series: 'a' [i64]
            [
               2
               4
            ]
        )r   offset)rB   r&   gather_every)r   r   rO  s      r   rP  zSeries.gather_everya  s1    H **""//!F/C
 	
r    c                6    | j                   j                         S )aw  Convert to arrow.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeries
            >>> import pyarrow as pa
            >>> import pandas as pd
            >>> import polars as pl
            >>> data = [1, 2, 3, 4]
            >>> s_pd = pd.Series(name="a", data=data)
            >>> s_pl = pl.Series(name="a", values=data)

            Let's define a dataframe-agnostic function that converts to arrow:

            >>> def my_library_agnostic_function(s_native: IntoSeries) -> pa.Array:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.to_arrow()

            >>> my_library_agnostic_function(s_pd)  # doctest:+NORMALIZE_WHITESPACE
            <pyarrow.lib.Int64Array object at ...>
            [
                1,
                2,
                3,
                4
            ]

            >>> my_library_agnostic_function(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            <pyarrow.lib.Int64Array object at ...>
            [
                1,
                2,
                3,
                4
            ]
        )r&   rN   r/   s    r   rN   zSeries.to_arrow  s    J %%..00r    c                T    | j                  | j                  j                               S )a.  Compute the most occurring value(s).

        Can return multiple values.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT

            >>> data = [1, 1, 2, 2, 3]
            >>> s_pd = pd.Series(name="a", data=data)
            >>> s_pl = pl.Series(name="a", values=data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.mode().sort().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    2
            Name: a, dtype: int64

            >>> my_library_agnostic_function(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (2,)
            Series: 'a' [i64]
            [
               1
               2
            ]
        )rB   r&   moder/   s    r   rS  zSeries.mode  s%    H **4+A+A+F+F+HIIr    c                T    | j                  | j                  j                               S )a+  Returns a boolean Series indicating which values are finite.

        Warning:
            Different backend handle null values differently. `is_finite` will return
            False for NaN and Null's in the Dask and pandas non-nullable backend, while
            for Polars, PyArrow and pandas nullable backends null values are kept as such.

        Returns:
            Expression of `Boolean` data type.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [float("nan"), float("inf"), 2.0, None]

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.is_finite().to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(pd.Series(data))
            0    False
            1    False
            2     True
            3    False
            dtype: bool

            >>> my_library_agnostic_function(
            ...     pl.Series(data)
            ... )  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [bool]
            [
               false
               false
               true
               null
            ]

            >>> my_library_agnostic_function(pa.chunked_array([data]))  # doctest: +ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                false,
                false,
                true,
                null
              ]
            ]
        )rB   r&   	is_finiter/   s    r   rU  zSeries.is_finite  s%    r **4+A+A+K+K+MNNr    c               X    | j                  | j                  j                  |            S )a  Return the cumulative count of the non-null values in the series.

        Arguments:
            reverse: reverse the operation

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = ["x", "k", None, "d"]

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cum_count(reverse=True).to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(pd.Series(data))
            0    3
            1    2
            2    1
            3    1
            dtype: int64
            >>> my_library_agnostic_function(pl.Series(data))  # doctest:+NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [u32]
            [
                3
                2
                1
                1
            ]
            >>> my_library_agnostic_function(pa.chunked_array([data]))  # doctest:+ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                3,
                2,
                1,
                1
              ]
            ]

        r   )rB   r&   	cum_countr   s     r   rW  zSeries.cum_count  s/    b **"",,W,=
 	
r    c               X    | j                  | j                  j                  |            S )a  Return the cumulative min of the non-null values in the series.

        Arguments:
            reverse: reverse the operation

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [3, 1, None, 2]

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cum_min().to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(pd.Series(data))
            0    3.0
            1    1.0
            2    NaN
            3    1.0
            dtype: float64
            >>> my_library_agnostic_function(pl.Series(data))  # doctest:+NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [i64]
            [
               3
               1
               null
               1
            ]
            >>> my_library_agnostic_function(pa.chunked_array([data]))  # doctest:+ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                3,
                1,
                null,
                1
              ]
            ]

        r   )rB   r&   cum_minr   s     r   rY  zSeries.cum_minF  /    b **""**7*;
 	
r    c               X    | j                  | j                  j                  |            S )a  Return the cumulative max of the non-null values in the series.

        Arguments:
            reverse: reverse the operation

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [1, 3, None, 2]

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cum_max().to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(pd.Series(data))
            0    1.0
            1    3.0
            2    NaN
            3    3.0
            dtype: float64
            >>> my_library_agnostic_function(pl.Series(data))  # doctest:+NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [i64]
            [
               1
               3
               null
               3
            ]
            >>> my_library_agnostic_function(pa.chunked_array([data]))  # doctest:+ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                1,
                3,
                null,
                3
              ]
            ]

        r   )rB   r&   cum_maxr   s     r   r\  zSeries.cum_max{  rZ  r    c               X    | j                  | j                  j                  |            S )a  Return the cumulative product of the non-null values in the series.

        Arguments:
            reverse: reverse the operation

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [1, 3, None, 2]

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cum_prod().to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> my_library_agnostic_function(pd.Series(data))
            0    1.0
            1    3.0
            2    NaN
            3    6.0
            dtype: float64
            >>> my_library_agnostic_function(pl.Series(data))  # doctest:+NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [i64]
            [
               1
               3
               null
               6
            ]
            >>> my_library_agnostic_function(pa.chunked_array([data]))  # doctest:+ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                1,
                3,
                null,
                6
              ]
            ]

        r   )rB   r&   cum_prodr   s     r   r^  zSeries.cum_prod  s/    b **""++G+<
 	
r    )r}   centerc                   t        ||      \  }}t        |       dk(  r| S | j                  | j                  j	                  |||            S )a	  Apply a rolling sum (moving sum) over the values.

        !!! warning
            This functionality is considered **unstable**. It may be changed at any point
            without it being considered a breaking change.

        A window of length `window_size` will traverse the values. The resulting values
        will be aggregated to their sum.

        The window at a given row will include the row itself and the `window_size - 1`
        elements before it.

        Arguments:
            window_size: The length of the window in number of elements. It must be a
                strictly positive integer.
            min_periods: The number of values in the window that should be non-null before
                computing a result. If set to `None` (default), it will be set equal to
                `window_size`. If provided, it must be a strictly positive integer, and
                less than or equal to `window_size`
            center: Set the labels at the center of the window.

        Returns:
            A new expression.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [1.0, 2.0, 3.0, 4.0]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)
            >>> s_pa = pa.chunked_array([data])

            We define a library agnostic function:

            >>> def agnostic_rolling_sum(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.rolling_sum(window_size=2).to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> agnostic_rolling_sum(s_pd)
            0    NaN
            1    3.0
            2    5.0
            3    7.0
            dtype: float64

            >>> agnostic_rolling_sum(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [f64]
            [
               null
               3.0
               5.0
               7.0
            ]

            >>> agnostic_rolling_sum(s_pa)  # doctest:+ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                null,
                3,
                5,
                7
              ]
            ]
        window_sizer}   r   rb  r}   r_  )r   rk   rB   r&   rolling_sumr   rb  r}   r_  s       r   rd  zSeries.rolling_sum  s`    \ $?#$
 [ t9>K**""..'' / 
 	
r    c                   t        ||      \  }}t        |       dk(  r| S | j                  | j                  j	                  |||            S )a	  Apply a rolling mean (moving mean) over the values.

        !!! warning
            This functionality is considered **unstable**. It may be changed at any point
            without it being considered a breaking change.

        A window of length `window_size` will traverse the values. The resulting values
        will be aggregated to their mean.

        The window at a given row will include the row itself and the `window_size - 1`
        elements before it.

        Arguments:
            window_size: The length of the window in number of elements. It must be a
                strictly positive integer.
            min_periods: The number of values in the window that should be non-null before
                computing a result. If set to `None` (default), it will be set equal to
                `window_size`. If provided, it must be a strictly positive integer, and
                less than or equal to `window_size`
            center: Set the labels at the center of the window.

        Returns:
            A new expression.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [1.0, 2.0, 3.0, 4.0]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)
            >>> s_pa = pa.chunked_array([data])

            We define a library agnostic function:

            >>> def agnostic_rolling_mean(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.rolling_mean(window_size=2).to_native()

            We can then pass any supported library such as Pandas, Polars, or PyArrow to `func`:

            >>> agnostic_rolling_mean(s_pd)
            0    NaN
            1    1.5
            2    2.5
            3    3.5
            dtype: float64

            >>> agnostic_rolling_mean(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [f64]
            [
               null
               1.5
               2.5
               3.5
            ]

            >>> agnostic_rolling_mean(s_pa)  # doctest:+ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                null,
                1.5,
                2.5,
                3.5
              ]
            ]
        ra  r   rc  )r   rk   rB   r&   rolling_meanre  s       r   rg  zSeries.rolling_meanB  s`    \ $?#$
 [ t9>K**""//'' 0 
 	
r    c              #  T   K   | j                   j                         E d {    y 7 wr6   )r&   __iter__r/   s    r   ri  zSeries.__iter__  s     ))22444s   (&(c                8    | j                   j                  |      S r6   )r&   __contains__r   s     r   rk  zSeries.__contains__  s    %%22599r    c                    t        |       S r6   )SeriesStringNamespacer/   s    r   strz
Series.str  s    $T**r    c                    t        |       S r6   )SeriesDateTimeNamespacer/   s    r   dtz	Series.dt  s    &t,,r    c                    t        |       S r6   )SeriesCatNamespacer/   s    r   catz
Series.cat  s    !$''r    c                    t        |       S r6   )SeriesListNamespacer/   s    r   r   zSeries.list  s    "4((r    )returnztype[DataFrame[Any]])r   r   r)   r   r*   z&Literal['full', 'lazy', 'interchange']rw  None)rw  r   )NN)r   r   r2   r   r3   zbool | Nonerw  
np.ndarray)r   r   r9   r@   rw  r   )r   r   r9   zslice | Sequence[int]rw  r   )r   r   r9   zint | slice | Sequence[int]rw  z
Any | Self)r   r   rw  r   r6   )rG   zobject | Nonerw  object)rw  r   )rX   zint | Sequence[int]rY   r   rw  r   )rw  z
tuple[int])r_   r   rw  r   )r)   r   rw  r   )re   zCallable[[Any], Self]rf   r   rg   r   rw  r   )rw  rn  )rw  r@   )r   r   rw  r   )r   r   rx   float | Nonery   r{  rz   r{  r{   r{  r|   boolr}   r@   r~   r|  rw  r   )r   r   r2   zDType | type[DType]rw  r   )rw  DataFrame[Any])rw  z	list[Any])rw  r   )r   r   rw  r   )r   r@   rw  r   )r   
Any | Noner   r~  rw  r   )r   r   rw  r   )rw  r   )r   r   r   r|  rw  r   )r   r|  rw  r   )r   r@   rw  r   )r   r   r   
int | Noner   r{  r   r|  r   r  rw  r   )ru   rn  rw  r   )
r   r   r   z!Sequence[Any] | Mapping[Any, Any]r   zSequence[Any] | Noner   zDType | type[DType] | Nonerw  r   )r   r|  r   r|  rw  r   )NNN)r   r~  r   z%Literal['forward', 'backward'] | Noner   r  rw  r   )both)r   r   r   r   r   rn  rw  r   )rw  ry  )rw  z	pd.Series)r   rz  rw  r   )r   r   rw  r   )r   r   rw  r|  )r   r   rw  r@   )r   r   r   r|  rw  r|  )r   r   r   r|  r4  r|  ru   
str | Noner5  r|  rw  r}  )r9  floatr:  z;Literal['nearest', 'higher', 'lower', 'midpoint', 'linear']rw  r   )r   r   r=  r   r   r   rw  r   )r   r   r?  r  rw  r   )
   )r   r   r   r@   rw  r   )r   )r   r   rG  r@   rw  r   )r   r   rJ  rn  rK  r|  rw  r}  )r   r   r   r@   rO  r@   rw  r   )r   r   rw  zpa.Array)
r   r   rb  r@   r}   r  r_  r|  rw  r   )r   r   rw  zIterator[Any])r   r   r   r   rw  r|  )r   r   rw  zSeriesStringNamespace[Self])r   r   rw  zSeriesDateTimeNamespace[Self])r   r   rw  zSeriesCatNamespace[Self])r   r   rw  zSeriesListNamespace[Self])u__name__
__module____qualname____doc__propertyr   r,   r0   r4   r   r:   rD   rF   rT   rV   r[   rW   rB   rh   rn   rq   rk   r2   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   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/  r2  r7  r9  r<  r@  rB  rD  rF  rM  rP  rN   rS  rU  rW  rY  r\  r^  rd  rg  ri  rk  rn  rq  rt  r   r7   r    r   r   r   !   s     
&&& 6	&
 
& 6 64H 5 5H HFHP=H2%5N@
D , ,6
$/L
++: , ,6 + +< !!"&""^
^
 ^
 	^

  ^
 ^
 ^
 ^
 ^
 
^
@&OP+
Z"0H-6 /D!-F.8,<,8,6,60@0@,6 "# 5@ IMc
%c
;Ec
	c
J&
P ND(PT"IH 05 '
R 05 )
V+JZ/Lf ;
 "&!&;
;
;
 	;

 ;
 ;
 
;
zCTJE%T %)L

 48L
L
.L
 "L

 1L
 
L
\ */5 =
~&MT !:> 	R
R
 8R
 	R

 
R
j AG4
4
-04
:=4
	4
l16182B














































P$
N&SP1<$OL3<&WP&VP 5: !GL <
<
 <
 	<

 <
 <
 
<
|*
*
 S*
 
	*
X:
x 8D&KP%KN.Sb ),F
F
"%F
9=F
	F
P&
P%1N$JL9Ov 27 3
j 05 3
j 05 3
j 16 3
r #'[
[
[
  	[

 [
 
[
B #'[
[
[
  	[

 [
 
[
z5: + + - - ( ( ) )r    r   SeriesT)boundc                      e Zd ZddZddZy)rs  c                    || _         y r6   _narwhals_seriesrc   s     r   r,   zSeriesCatNamespace.__init__  
     &r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Get unique categories from column.

        Examples:
            Let's create some series:

            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["apple", "mango", "mango"]
            >>> s_pd = pd.Series(data, dtype="category")
            >>> s_pl = pl.Series(data, dtype=pl.Categorical)

            We define a dataframe-agnostic function to get unique categories
            from column 'fruits':

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.cat.get_categories().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    apple
            1    mango
            dtype: object
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [str]
            [
               "apple"
               "mango"
            ]
        )r  rB   r&   rt  get_categoriesr/   s    r   r  z!SeriesCatNamespace.get_categories  s<    F $$;;!!3377FFH
 	
r    Nr   r   r)   r  rw  rx  r   r   rw  r  )r  r  r  r,   r  r7   r    r   rs  rs    s    '%
r    rs  c                      e Zd ZddZddZddd	 	 	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 	 	 ddZddd
ZddZddZ	ddddZ
dddZdddZdddZd dZd dZdd!dZy	)"rm  c                    || _         y r6   r  rc   s     r   r,   zSeriesStringNamespace.__init__  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )u  Return the length of each string as the number of characters.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["foo", "Café", "345", "東京", None]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.len_chars().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    3.0
            1    4.0
            2    3.0
            3    2.0
            4    NaN
            dtype: float64

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: '' [u32]
            [
               3
               4
               3
               2
               null
            ]
        )r  rB   r&   rn  	len_charsr/   s    r   r  zSeriesStringNamespace.len_chars  s<    N $$;;!!3377AAC
 	
r    Frv   literalr   c                   | j                   j                  | j                   j                  j                  j	                  ||||            S )aA  Replace first matching regex/literal substring with a new string value.

        Arguments:
            pattern: A valid regular expression pattern.
            value: String that will replace the matched substring.
            literal: Treat `pattern` as a literal string.
            n: Number of matches to replace.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["123abc", "abc abc123"]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     s = s.str.replace("abc", "")
            ...     return s.to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0        123
            1     abc123
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [str]
            [
                "123"
                " abc123"
            ]
        r  )r  rB   r&   rn  replace)r   patternr   r  r   s        r   r  zSeriesStringNamespace.replace  sM    T $$;;!!3377??1 @ 
 	
r    r  c                   | j                   j                  | j                   j                  j                  j	                  |||            S )a  Replace all matching regex/literal substring with a new string value.

        Arguments:
            pattern: A valid regular expression pattern.
            value: String that will replace the matched substring.
            literal: Treat `pattern` as a literal string.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["123abc", "abc abc123"]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     s = s.str.replace_all("abc", "")
            ...     return s.to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0     123
            1     123
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest:+NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [str]
            [
                "123"
                " 123"
            ]
        r  )r  rB   r&   rn  replace_all)r   r  r   r  s       r   r  z!SeriesStringNamespace.replace_allD  sK    R $$;;!!3377CC D 
 	
r    Nc                    | j                   j                  | j                   j                  j                  j	                  |            S )a#  Remove leading and trailing characters.

        Arguments:
            characters: The set of characters to be removed. All combinations of this set of characters will be stripped from the start and end of the string. If set to None (default), all leading and trailing whitespace is removed instead.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["apple", "\nmango"]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     s = s.str.strip_chars()
            ...     return s.to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    apple
            1    mango
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [str]
            [
                "apple"
                "mango"
            ]
        )r  rB   r&   rn  strip_chars)r   
characterss     r   r  z!SeriesStringNamespace.strip_charss  s>    J $$;;!!3377CCJO
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  |            S )ar  Check if string values start with a substring.

        Arguments:
            prefix: prefix substring

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["apple", "mango", None]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.starts_with("app").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0     True
            1    False
            2     None
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [bool]
            [
               true
               false
               null
            ]
        )r  rB   r&   rn  starts_with)r   prefixs     r   r  z!SeriesStringNamespace.starts_with  s>    L $$;;!!3377CCFK
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  |            S )an  Check if string values end with a substring.

        Arguments:
            suffix: suffix substring

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["apple", "mango", None]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.ends_with("ngo").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    False
            1     True
            2     None
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [bool]
            [
               false
               true
               null
            ]
        )r  rB   r&   rn  	ends_with)r   suffixs     r   r  zSeriesStringNamespace.ends_with  s>    L $$;;!!3377AA&I
 	
r    c                   | j                   j                  | j                   j                  j                  j	                  ||            S )a  Check if string contains a substring that matches a pattern.

        Arguments:
            pattern: A Character sequence or valid regular expression pattern.
            literal: If True, treats the pattern as a literal string.
                     If False, assumes the pattern is a regular expression.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> pets = ["cat", "dog", "rabbit and parrot", "dove", None]
            >>> s_pd = pd.Series(pets)
            >>> s_pl = pl.Series(pets)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.contains("parrot|dove").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    False
            1    False
            2     True
            3     True
            4     None
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: '' [bool]
            [
               false
               false
               true
               true
               null
            ]
        r  )r  rB   r&   rn  contains)r   r  r  s      r   r  zSeriesStringNamespace.contains  sD    X $$;;!!3377@@RY@Z
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  ||            S )a  Create subslices of the string values of a Series.

        Arguments:
            offset: Start index. Negative indexing is supported.
            length: Length of the slice. If set to `None` (default), the slice is taken to the
                end of the string.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["pear", None, "papaya", "dragonfruit"]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.slice(4, length=3).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0
            1    None
            2      ya
            3     onf
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [str]
            [
               ""
               null
               "ya"
               "onf"
            ]

            Using negative indexes:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.slice(-3).to_native()

            >>> my_library_agnostic_function(s_pd)  # doctest: +NORMALIZE_WHITESPACE
            0     ear
            1    None
            2     aya
            3     uit
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [str]
            [
                "ear"
                null
                "aya"
                "uit"
            ]
        rO  rm   r  rB   r&   rn  slice)r   rO  rm   s      r   r  zSeriesStringNamespace.slice   sH    B $$;;!!3377==f > 
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  d|            S )a1  Take the first n elements of each string.

        Arguments:
            n: Number of elements to take. Negative indexing is supported (see note (1.))

        Notes:
            1. When the `n` input is negative, `head` returns characters up to the n-th from the end of the string.
                For example, if `n = -3`, then all characters except the last three are returned.
            2. If the length of the string has fewer than `n` characters, the full string is returned.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> lyrics = ["Atatata", "taata", "taatatata", "zukkyun"]
            >>> s_pd = pd.Series(lyrics)
            >>> s_pl = pl.Series(lyrics)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.head().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    Atata
            1    taata
            2    taata
            3    zukky
            dtype: object
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [str]
            [
               "Atata"
               "taata"
               "taata"
               "zukky"
            ]
        r   r  r  r   s     r   rB  zSeriesStringNamespace.headg  sC    X $$;;!!3377==Qq=Q
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  | d            S )a?  Take the last n elements of each string.

        Arguments:
            n: Number of elements to take. Negative indexing is supported (see note (1.))

        Notes:
            1. When the `n` input is negative, `tail` returns characters starting from the n-th from the beginning of
                the string. For example, if `n = -3`, then all characters except the first three are returned.
            2. If the length of the string has fewer than `n` characters, the full string is returned.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> lyrics = ["Atatata", "taata", "taatatata", "zukkyun"]
            >>> s_pd = pd.Series(lyrics)
            >>> s_pl = pl.Series(lyrics)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.tail().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    atata
            1    taata
            2    atata
            3    kkyun
            dtype: object
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [str]
            [
               "atata"
               "taata"
               "atata"
               "kkyun"
            ]
        Nr  r  r   s     r   rD  zSeriesStringNamespace.tail  sF    X $$;;!!3377==aRPT=U
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )u>  Transform string to uppercase variant.

        Notes:
            The PyArrow backend will convert 'ß' to 'ẞ' instead of 'SS'.
            For more info see: https://github.com/apache/arrow/issues/34599
            There may be other unicode-edge-case-related variations across implementations.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoFrameT
            >>> data = {"fruits": ["apple", "mango", None]}
            >>> df_pd = pd.DataFrame(data)
            >>> df_pl = pl.DataFrame(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(df_native: IntoFrameT) -> IntoFrameT:
            ...     df = nw.from_native(df_native)
            ...     return df.with_columns(
            ...         upper_col=nw.col("fruits").str.to_uppercase()
            ...     ).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(df_pd)  # doctest: +NORMALIZE_WHITESPACE
             fruits  upper_col
            0  apple      APPLE
            1  mango      MANGO
            2   None       None

            >>> my_library_agnostic_function(df_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3, 2)
            ┌────────┬───────────┐
            │ fruits ┆ upper_col │
            │ ---    ┆ ---       │
            │ str    ┆ str       │
            ╞════════╪═══════════╡
            │ apple  ┆ APPLE     │
            │ mango  ┆ MANGO     │
            │ null   ┆ null      │
            └────────┴───────────┘

        )r  rB   r&   rn  to_uppercaser/   s    r   r  z"SeriesStringNamespace.to_uppercase  s<    \ $$;;!!3377DDF
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )uD  Transform string to lowercase variant.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT, IntoFrameT
            >>> data = {"fruits": ["APPLE", "MANGO", None]}
            >>> df_pd = pd.DataFrame(data)
            >>> df_pl = pl.DataFrame(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(df_native: IntoFrameT) -> IntoFrameT:
            ...     df = nw.from_native(df_native)
            ...     return df.with_columns(
            ...         lower_col=nw.col("fruits").str.to_lowercase()
            ...     ).to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(df_pd)  # doctest: +NORMALIZE_WHITESPACE
              fruits lower_col
            0  APPLE     apple
            1  MANGO     mango
            2   None      None


            >>> my_library_agnostic_function(df_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3, 2)
            ┌────────┬───────────┐
            │ fruits ┆ lower_col │
            │ ---    ┆ ---       │
            │ str    ┆ str       │
            ╞════════╪═══════════╡
            │ APPLE  ┆ apple     │
            │ MANGO  ┆ mango     │
            │ null   ┆ null      │
            └────────┴───────────┘
        )r  rB   r&   rn  to_lowercaser/   s    r   r  z"SeriesStringNamespace.to_lowercase  s<    R $$;;!!3377DDF
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  |            S )ue  Parse Series with strings to a Series with Datetime dtype.

        Notes:
            pandas defaults to nanosecond time unit, Polars to microsecond.
            Prior to pandas 2.0, nanoseconds were the only time unit supported
            in pandas, with no ability to set any other one. The ability to
            set the time unit in pandas, if the version permits, will arrive.

        Warning:
            As different backends auto-infer format in different ways, if `format=None`
            there is no guarantee that the result will be equal.

        Arguments:
            format: Format to use for conversion. If set to None (default), the format is
                inferred from the data.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["2020-01-01", "2020-01-02"]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)
            >>> s_pa = pa.chunked_array([data])

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.str.to_datetime(format="%Y-%m-%d").to_native()

            We can then pass any supported library such as pandas, Polars, or PyArrow::

            >>> my_library_agnostic_function(s_pd)
            0   2020-01-01
            1   2020-01-02
            dtype: datetime64[ns]
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [datetime[μs]]
            [
               2020-01-01 00:00:00
               2020-01-02 00:00:00
            ]
            >>> my_library_agnostic_function(s_pa)  # doctest: +ELLIPSIS
            <pyarrow.lib.ChunkedArray object at 0x...>
            [
              [
                2020-01-01 00:00:00.000000,
                2020-01-02 00:00:00.000000
              ]
            ]
        )format)r  rB   r&   rn  to_datetimer   r  s     r   r  z!SeriesStringNamespace.to_datetime&  sA    p $$;;!!3377CC6CR
 	
r    r  r  )r   r   r  rn  r   rn  r  r|  r   r@   rw  r  )
r   r   r  rn  r   rn  r  r|  rw  r  r6   )r   r   r  r  rw  r  )r   r   r  rn  rw  r  )r   r   r  rn  rw  r  )r   r   r  rn  r  r|  rw  r  )r   r   rO  r@   rm   r  rw  r  )   )r   r   r   r@   rw  r  )rw  r  )r   r   r  r  rw  r  )r  r  r  r,   r  r  r  r  r  r  r  r  rB  rD  r  r  r  r7   r    r   rm  rm    s    ')
X BGQR.
.
 .
),.
:>.
KN.
	.
b BG-
-
 -
),-
:>-
	-
^'
R(
T(
T ?D .
`E
N.
`.
`0
d+
Z:
r    rm  c                      e Zd ZddZddZddZddZddZddZddZ	ddZ
dd	Zdd
ZddZddZddZddZddZddZddZddZddZddZdddZy)rp  c                    || _         y r6   r  rc   s     r   r,   z SeriesDateTimeNamespace.__init__d  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Get the date in a datetime series.

        Raises:
            NotImplementedError: If pandas default backend is being used.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2012, 1, 7, 10, 20), datetime(2023, 3, 10, 11, 32)]
            >>> s_pd = pd.Series(dates).convert_dtypes(dtype_backend="pyarrow")
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.date().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2012-01-07
            1    2023-03-10
            dtype: date32[day][pyarrow]

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [date]
            [
               2012-01-07
               2023-03-10
            ]
        )r  rB   r&   rq  dater/   s    r   r  zSeriesDateTimeNamespace.dateg  s<    J $$;;!!3366;;=
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a4  Get the year in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2012, 1, 7), datetime(2023, 3, 10)]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.year().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2012
            1    2023
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i32]
            [
               2012
               2023
            ]
        )r  rB   r&   rq  yearr/   s    r   r  zSeriesDateTimeNamespace.year  <    B $$;;!!3366;;=
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a)  Gets the month in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2023, 2, 1), datetime(2023, 8, 3)]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.month().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2
            1    8
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i8]
            [
               2
               8
            ]
        )r  rB   r&   rq  monthr/   s    r   r  zSeriesDateTimeNamespace.month  s<    B $$;;!!3366<<>
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a)  Extracts the day in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2022, 1, 1), datetime(2022, 1, 5)]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.day().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    1
            1    5
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i8]
            [
               1
               5
            ]
        )r  rB   r&   rq  dayr/   s    r   r  zSeriesDateTimeNamespace.day  s<    B $$;;!!3366::<
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a8  Extracts the hour in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2022, 1, 1, 5, 3), datetime(2022, 1, 5, 9, 12)]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.hour().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    5
            1    9
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i8]
            [
               5
               9
            ]
        )r  rB   r&   rq  hourr/   s    r   r  zSeriesDateTimeNamespace.hour  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )a?  Extracts the minute in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2022, 1, 1, 5, 3), datetime(2022, 1, 5, 9, 12)]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.minute().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0     3
            1    12
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i8]
            [
               3
               12
            ]
        )r  rB   r&   rq  minuter/   s    r   r  zSeriesDateTimeNamespace.minute$  <    B $$;;!!3366==?
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )aH  Extracts the seconds in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [datetime(2022, 1, 1, 5, 3, 10), datetime(2022, 1, 5, 9, 12, 4)]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.second().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    10
            1     4
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i8]
            [
               10
                4
            ]
        )r  rB   r&   rq  secondr/   s    r   r  zSeriesDateTimeNamespace.secondI  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Extracts the milliseconds in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [
            ...     datetime(2023, 5, 21, 12, 55, 10, 400000),
            ...     datetime(2023, 5, 21, 12, 55, 10, 600000),
            ...     datetime(2023, 5, 21, 12, 55, 10, 800000),
            ...     datetime(2023, 5, 21, 12, 55, 11, 0),
            ...     datetime(2023, 5, 21, 12, 55, 11, 200000),
            ... ]

            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.millisecond().alias("datetime").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    400
            1    600
            2    800
            3      0
            4    200
            Name: datetime, dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: 'datetime' [i32]
            [
                400
                600
                800
                0
                200
            ]
        )r  rB   r&   rq  millisecondr/   s    r   r  z#SeriesDateTimeNamespace.millisecondn  <    \ $$;;!!3366BBD
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Extracts the microseconds in a datetime series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [
            ...     datetime(2023, 5, 21, 12, 55, 10, 400000),
            ...     datetime(2023, 5, 21, 12, 55, 10, 600000),
            ...     datetime(2023, 5, 21, 12, 55, 10, 800000),
            ...     datetime(2023, 5, 21, 12, 55, 11, 0),
            ...     datetime(2023, 5, 21, 12, 55, 11, 200000),
            ... ]

            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.microsecond().alias("datetime").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    400000
            1    600000
            2    800000
            3         0
            4    200000
            Name: datetime, dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (5,)
            Series: 'datetime' [i32]
            [
               400000
               600000
               800000
               0
               200000
            ]
        )r  rB   r&   rq  microsecondr/   s    r   r  z#SeriesDateTimeNamespace.microsecond  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Extract the nanoseconds in a date series.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> dates = [
            ...     datetime(2022, 1, 1, 5, 3, 10, 500000),
            ...     datetime(2022, 1, 5, 9, 12, 4, 60000),
            ... ]
            >>> s_pd = pd.Series(dates)
            >>> s_pl = pl.Series(dates)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.nanosecond().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    500000000
            1     60000000
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i32]
            [
               500000000
               60000000
            ]
        )r  rB   r&   rq  
nanosecondr/   s    r   r  z"SeriesDateTimeNamespace.nanosecond  s<    H $$;;!!3366AAC
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Get ordinal day.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import datetime
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [datetime(2020, 1, 1), datetime(2020, 8, 3)]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.ordinal_day().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0      1
            1    216
            dtype: int32
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i16]
            [
               1
               216
            ]
        )r  rB   r&   rq  ordinal_dayr/   s    r   r  z#SeriesDateTimeNamespace.ordinal_day  s<    B $$;;!!3366BBD
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a*  Get total minutes.

        Notes:
            The function outputs the total minutes in the int dtype by default,
            however, pandas may change the dtype to float when there are missing values,
            consider using `fill_null()` in this case.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import timedelta
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [timedelta(minutes=10), timedelta(minutes=20, seconds=40)]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.total_minutes().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    10
            1    20
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i64]
            [
                    10
                    20
            ]
        )r  rB   r&   rq  total_minutesr/   s    r   r  z%SeriesDateTimeNamespace.total_minutes  <    L $$;;!!3366DDF
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a/  Get total seconds.

        Notes:
            The function outputs the total seconds in the int dtype by default,
            however, pandas may change the dtype to float when there are missing values,
            consider using `fill_null()` in this case.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import timedelta
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [timedelta(seconds=10), timedelta(seconds=20, milliseconds=40)]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.total_seconds().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    10
            1    20
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i64]
            [
                    10
                    20
            ]
        )r  rB   r&   rq  total_secondsr/   s    r   r  z%SeriesDateTimeNamespace.total_secondsI  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Get total milliseconds.

        Notes:
            The function outputs the total milliseconds in the int dtype by default,
            however, pandas may change the dtype to float when there are missing values,
            consider using `fill_null()` in this case.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import timedelta
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [
            ...     timedelta(milliseconds=10),
            ...     timedelta(milliseconds=20, microseconds=40),
            ... ]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.total_milliseconds().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    10
            1    20
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i64]
            [
                    10
                    20
            ]
        )r  rB   r&   rq  total_millisecondsr/   s    r   r  z*SeriesDateTimeNamespace.total_millisecondss  <    R $$;;!!3366IIK
 	
r    c                    | j                   j                  | j                   j                  j                  j	                               S )a  Get total microseconds.

        Notes:
            The function outputs the total microseconds in the int dtype by default,
            however, pandas may change the dtype to float when there are missing values,
            consider using `fill_null()` in this case.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import timedelta
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [
            ...     timedelta(microseconds=10),
            ...     timedelta(milliseconds=1, microseconds=200),
            ... ]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.total_microseconds().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0      10
            1    1200
            dtype: int...
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i64]
            [
                    10
                    1200
            ]
        )r  rB   r&   rq  total_microsecondsr/   s    r   r  z*SeriesDateTimeNamespace.total_microseconds  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )ay  Get total nanoseconds.

        Notes:
            The function outputs the total nanoseconds in the int dtype by default,
            however, pandas may change the dtype to float when there are missing values,
            consider using `fill_null()` in this case.

        Examples:
            >>> import pandas as pd
            >>> import polars as pl
            >>> from datetime import timedelta
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = ["2024-01-01 00:00:00.000000001", "2024-01-01 00:00:00.000000002"]
            >>> s_pd = pd.to_datetime(pd.Series(data))
            >>> s_pl = pl.Series(data).str.to_datetime(time_unit="ns")

            We define a library agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.diff().dt.total_nanoseconds().to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    NaN
            1    1.0
            dtype: float64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [i64]
            [
                    null
                    1
            ]
        )r  rB   r&   rq  total_nanosecondsr/   s    r   r  z)SeriesDateTimeNamespace.total_nanoseconds  s<    L $$;;!!3366HHJ
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  |            S )a
  Convert a Date/Time/Datetime series into a String series with the given format.

        Notes:
            Unfortunately, different libraries interpret format directives a bit
            differently.

            - Chrono, the library used by Polars, uses `"%.f"` for fractional seconds,
              whereas pandas and Python stdlib use `".%f"`.
            - PyArrow interprets `"%S"` as "seconds, including fractional seconds"
              whereas most other tools interpret it as "just seconds, as 2 digits".

            Therefore, we make the following adjustments:

            - for pandas-like libraries, we replace `"%S.%f"` with `"%S%.f"`.
            - for PyArrow, we replace `"%S.%f"` with `"%S"`.

            Workarounds like these don't make us happy, and we try to avoid them as
            much as possible, but here we feel like it's the best compromise.

            If you just want to format a date/datetime Series as a local datetime
            string, and have it work as consistently as possible across libraries,
            we suggest using:

            - `"%Y-%m-%dT%H:%M:%S%.f"` for datetimes
            - `"%Y-%m-%d"` for dates

            though note that, even then, different tools may return a different number
            of trailing zeros. Nonetheless, this is probably consistent enough for
            most applications.

            If you have an application where this is not enough, please open an issue
            and let us know.

        Examples:
            >>> from datetime import datetime
            >>> import pandas as pd
            >>> import polars as pl
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> data = [
            ...     datetime(2020, 3, 1),
            ...     datetime(2020, 4, 1),
            ...     datetime(2020, 5, 1),
            ... ]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)

            We define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.to_string("%Y/%m/%d").to_native()

            We can then pass either pandas or Polars to `func`:

            >>> my_library_agnostic_function(s_pd)
            0    2020/03/01
            1    2020/04/01
            2    2020/05/01
            dtype: object

            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [str]
            [
               "2020/03/01"
               "2020/04/01"
               "2020/05/01"
            ]
        )r  rB   r&   rq  	to_stringr  s     r   r  z!SeriesDateTimeNamespace.to_string  s>    N $$;;!!3366@@H
 	
r    c                    | j                   j                  | j                   j                  j                  j	                  |            S )u  Replace time zone.

        Arguments:
            time_zone: Target time zone.

        Examples:
            >>> from datetime import datetime, timezone
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [
            ...     datetime(2024, 1, 1, tzinfo=timezone.utc),
            ...     datetime(2024, 1, 2, tzinfo=timezone.utc),
            ... ]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)
            >>> s_pa = pa.chunked_array([data])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.replace_time_zone("Asia/Kathmandu").to_native()

            We can then pass pandas / PyArrow / Polars / any other supported library:

            >>> my_library_agnostic_function(s_pd)
            0   2024-01-01 00:00:00+05:45
            1   2024-01-02 00:00:00+05:45
            dtype: datetime64[ns, Asia/Kathmandu]
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [datetime[μs, Asia/Kathmandu]]
            [
                2024-01-01 00:00:00 +0545
                2024-01-02 00:00:00 +0545
            ]
            >>> my_library_agnostic_function(s_pa)
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                2023-12-31 18:15:00.000000Z,
                2024-01-01 18:15:00.000000Z
              ]
            ]
        )r  rB   r&   rq  replace_time_zone)r   	time_zones     r   r  z)SeriesDateTimeNamespace.replace_time_zoneB  s>    b $$;;!!3366HHS
 	
r    c                    |d}t        |      | j                  j                  | j                  j                  j                  j                  |            S )uM  Convert time zone.

        If converting from a time-zone-naive column, then conversion happens
        as if converting from UTC.

        Arguments:
            time_zone: Target time zone.

        Examples:
            >>> from datetime import datetime, timezone
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [
            ...     datetime(2024, 1, 1, tzinfo=timezone.utc),
            ...     datetime(2024, 1, 2, tzinfo=timezone.utc),
            ... ]
            >>> s_pd = pd.Series(data)
            >>> s_pl = pl.Series(data)
            >>> s_pa = pa.chunked_array([data])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.convert_time_zone("Asia/Kathmandu").to_native()

            We can then pass pandas / PyArrow / Polars / any other supported library:

            >>> my_library_agnostic_function(s_pd)
            0   2024-01-01 05:45:00+05:45
            1   2024-01-02 05:45:00+05:45
            dtype: datetime64[ns, Asia/Kathmandu]
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (2,)
            Series: '' [datetime[μs, Asia/Kathmandu]]
            [
                2024-01-01 05:45:00 +0545
                2024-01-02 05:45:00 +0545
            ]
            >>> my_library_agnostic_function(s_pa)
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                2024-01-01 00:00:00.000000Z,
                2024-01-02 00:00:00.000000Z
              ]
            ]
        zTarget `time_zone` cannot be `None` in `convert_time_zone`. Please use `replace_time_zone(None)` if you want to remove the time zone.)r   r  rB   r&   rq  convert_time_zone)r   r  r+   s      r   r  z)SeriesDateTimeNamespace.convert_time_zonew  sV    h  ZCC. $$;;!!3366HHS
 	
r    c                    |dvrd|d}t        |      | j                  j                  | j                  j                  j                  j                  |            S )as  Return a timestamp in the given time unit.

        Arguments:
            time_unit: {'ns', 'us', 'ms'}
                Time unit.

        Examples:
            >>> from datetime import date
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [date(2001, 1, 1), None, date(2001, 1, 3)]
            >>> s_pd = pd.Series(data, dtype="datetime64[ns]")
            >>> s_pl = pl.Series(data)
            >>> s_pa = pa.chunked_array([data])

            Let's define a dataframe-agnostic function:

            >>> def my_library_agnostic_function(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.dt.timestamp("ms").to_native()

            We can then pass pandas / PyArrow / Polars / any other supported library:

            >>> my_library_agnostic_function(s_pd)
            0    9.783072e+11
            1             NaN
            2    9.784800e+11
            dtype: float64
            >>> my_library_agnostic_function(s_pl)  # doctest: +NORMALIZE_WHITESPACE
            shape: (3,)
            Series: '' [i64]
            [
                    978307200000
                    null
                    978480000000
            ]
            >>> my_library_agnostic_function(s_pa)
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                978307200000,
                null,
                978480000000
              ]
            ]
        >   msnsusz=invalid `time_unit`

Expected one of {'ns', 'us', 'ms'}, got r#   )r   r  rB   r&   rq  	timestamp)r   	time_unitr+   s      r   r  z!SeriesDateTimeNamespace.timestamp  sk    d ..AAJQP  S/!$$;;!!3366@@K
 	
r    Nr  r  )r   r   r  rn  rw  r  )r   r   r  r  rw  r  )r   r   r  rn  rw  r  )r  )r   r   r  zLiteral['ns', 'us', 'ms']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  r7   r    r   rp  rp  c  s    ''
R#
J#
J#
J#
J#
J#
J0
d0
d&
P#
J(
T(
T+
Z+
Z(
TI
V3
j9
v:
r    rp  c                      e Zd ZddZddZy)rv  c                    || _         y r6   r  rc   s     r   r,   zSeriesListNamespace.__init__  r  r    c                    | j                   j                  | j                   j                  j                  j	                               S )a
  Return the number of elements in each list.

        Null values count towards the total.

        Returns:
            A new series.

        Examples:
            >>> import narwhals as nw
            >>> from narwhals.typing import IntoSeriesT
            >>> import pandas as pd
            >>> import polars as pl
            >>> import pyarrow as pa
            >>> data = [[1, 2], [3, 4, None], None, []]

            Let's define a dataframe-agnostic function:

            >>> def agnostic_list_len(s_native: IntoSeriesT) -> IntoSeriesT:
            ...     s = nw.from_native(s_native, series_only=True)
            ...     return s.list.len().to_native()

            We can then pass pandas / PyArrow / Polars / any other supported library:

            >>> agnostic_list_len(
            ...     pd.Series(data, dtype=pd.ArrowDtype(pa.list_(pa.int64())))
            ... )  # doctest: +SKIP
            0       2
            1       3
            2    <NA>
            3       0
            dtype: int32[pyarrow]

            >>> agnostic_list_len(pl.Series(data))  # doctest: +NORMALIZE_WHITESPACE
            shape: (4,)
            Series: '' [u32]
            [
               2
               3
               null
               0
            ]

            >>> agnostic_list_len(pa.chunked_array([data]))  # doctest: +ELLIPSIS
            <pyarrow.lib.ChunkedArray object at ...>
            [
              [
                2,
                3,
                null,
                0
              ]
            ]
        )r  rB   r&   r   rk   r/   s    r   rk   zSeriesListNamespace.len  s<    l $$;;!!3388<<>
 	
r    Nr  r  )r  r  r  r,   rk   r7   r    r   rv  rv    s    '8
r    rv  )*
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   narwhals.dependenciesr   narwhals.dtypesr   narwhals.typingr   narwhals.utilsr   r   typesr   numpynppandaspdrJ   rP   typing_extensionsr   r   r   r   r   r   r  rs  rm  rp  rv  r7   r    r   <module>r     s    "            1 + ' 6 ( &,%-R6)W[! R6)jl )6#;
/)
) )
X{	
GG, {	
|I
gg. I
X<
''* <
r    