o
    篪g@                    @  s\  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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) 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 m0Z1 d d"l2m3Z4 d d#l5m6Z7 d d$l8m9Z9 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:mAZA d d,l:mBZB d d-l:mCZC d d.l:mDZD d d/l:mEZE d d0l:mFZF d d1l:mGZG d d2l:mHZH d d3l:mIZI d d4l:mJZJ d d5l:mKZK d d6l:mLZL d d7l:mMZM d d8l:mNZN d d9l:mOZO d d:l:mPZP d d;l:mQZQ d d<l:mRZR d d=l:mSZS d d>l:mTZT d d?lUmVZV d d@lUmWZW d dAlUmXZX d dBlYmZZZ d dClYm[Z[ d dDl\m]Z] d dEl\m^Z^ d dFl\m_Z_ d dGl\m`Z` d dHl\maZa d dIl\mbZb d dJl\mcZc d dKl\mdZd d dLl\meZe d dMl\mfZf d dNl\mgZg d dOl\mhZh erd dPlimjZj d dQlkmlZl d dRlmmnZn d dSl moZo d dTlYmpZp d dUlYmqZq d dVlYmrZr d dWlYmsZs d dXlYmtZt edYZuG dZd[ d[eeZ ZG d\d] d]ee[ ZG d^d_ d_e7e Z6G d`da daeZG dbdc dce4Z3edIdhdiZvedJdldiZvedKdndiZvedLdpdiZvedMdrdiZvdNdudiZvedvdvdwdOddZwedvdvddPddZwedvdvdvddQddZwedvdvdvddRddZwedvdvdvddSddZwedvdvdvddTddZwedvdvdvddUddZwedvdvdvddVddZwedvdvdvdvddWddZwedvdvdvdvddXddZwedvdvdvdvddYddZwedvdvdvdvddZddZwedvdvdvdvdd[ddZwedvdvdvdvdd\ddZwedvdvdvdvdvdd]ddZwedvdvdwd^ddZwedvdvdd_ddZwedvdvdvdd`ddZwedvdvdvddaddZwedvdvdvddbddZwedvdvdvddcddZwedvdvdvdddddZwedvdvdvddeddZwedvdvdvdvddfddZwedvdvdvdvddgddZwedvdvdvdvddhddZwedvdvdvdvddiddZwedvdvdvdvddjddZwedvdvdvdvddkddZwedvdvdvdvdvddlddZwedddmddZwddddddddnddZwedvdƜdoddɄZxedvdƜdpddɄZxedvdƜdqddɄZxedrddɄZxedvd͜dsddɄZxedvd͜dtddɄZxedvd͜duddɄZxedvddɄZxdddҜdwddɄZx	dxddddddddyddۄZydzdd݄Zzd{ddZ{d|ddZ|dzddZ}dxd}ddZ~d~ddZd~ddZd~ddZd~ddZd~ddZdddZdddZddd ZdddZdddZdddZedddddZedddddZedddddZdddddZddddddZG dd de$Z#G dd  d e"eZ!dd"d#Z0	dxdd(d)Zdd-d.Z,	dxddd/dd7d8Z	dxdd;d<Zdd?d@ZddBdCZddDdEZddFdGZg dHZdS (      )annotationswraps)TYPE_CHECKING)Any)Callable)Iterable)Literal)Sequence)TypeVar)overload)warnN)dependencies)
exceptions)	selectors	DataFrame	LazyFrame)
get_polars)InvalidIntoExprErrorExpr)Then)When)_from_dict_impl)_from_numpy_impl)_new_series_impl)_read_csv_impl)_read_parquet_impl)_scan_csv_impl)_scan_parquet_impl)
from_arrow)	get_level)show_versions)when)SchemaSeries)dtypes)Array)Boolean)Categorical)Date)Datetime)Decimal)Duration)Enum)Field)Float32)Float64)Int8)Int16)Int32)Int64)Int128)List)Object)String)Struct)UInt8)UInt16)UInt32)UInt64)UInt128)Unknown)_from_native_impl)get_native_namespace)to_py_scalar)IntoDataFrameT)
IntoFrameT)Implementation)Versionfind_stacklevel)generate_temporary_column_name)is_ordered_categorical)maybe_align_index)maybe_convert_dtypes)maybe_get_index)maybe_reset_index)maybe_set_index)%validate_native_namespace_and_backendvalidate_strict_and_pass_though)
ModuleType)Self)DType)ArrowStreamExportable)IntoExpr)	IntoFrame)
IntoSeries)_1DArray)_2DArrayTc                      s   e Zd ZdZed/ddZed0d	d
Zed1ddZed2ddZd3 fddZ	d4d5 fddZ	eddd6dd Z
ed7d#d Z
ed8d&d Z
d'dd8 fd(d Z
d9 fd)d*Zd9 fd+d,Zd:d-d.Z  ZS );r   a  Narwhals DataFrame, backed by a native eager dataframe.

    !!! warning
        This class is not meant to be instantiated directly - instead:

        - If the native object is a eager dataframe from one of the supported
            backend (e.g. pandas.DataFrame, polars.DataFrame, pyarrow.Table),
            you can use [`narwhals.from_native`][]:
            ```py
            narwhals.from_native(native_dataframe)
            narwhals.from_native(native_dataframe, eager_only=True)
            ```

        - If the object is a dictionary of column names and generic sequences mapping
            (e.g. `dict[str, list]`), you can create a DataFrame via
            [`narwhals.from_dict`][]:
            ```py
            narwhals.from_dict(
                data={"a": [1, 2, 3]},
                native_namespace=narwhals.get_native_namespace(another_object),
            )
            ```
    selfrX   returntype[Series]c                 C     t S Nr'   ra    rg   W/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/narwhals/stable/v1/__init__.py_series      zDataFrame._seriestype[LazyFrame[Any]]c                 C  rd   re   r   rf   rg   rg   rh   
_lazyframe   rj   zDataFrame._lazyframeitem8str | tuple[slice | Sequence[int] | _1DArray, int | str]r(   c                 C     d S re   rg   ra   rm   rg   rg   rh   __getitem__   s   zDataFrame.__getitem__int | slice | _1DArray | Sequence[int] | Sequence[str] | tuple[slice | Sequence[int] | _1DArray, slice | Sequence[int] | Sequence[str]]c                 C  ro   re   rg   rp   rg   rg   rh   rq      s   r   c                      t  |S re   )superrq   rp   	__class__rg   rh   rq      s   Nbackend(ModuleType | Implementation | str | NoneLazyFrame[Any]c                      t  j|dS )a  Restrict available API methods to lazy-only ones.

        If `backend` is specified, then a conversion between different backends
        might be triggered.

        If a library does not support lazy execution and `backend` is not specified,
        then this is will only restrict the API to lazy-only operations. This is useful
        if you want to ensure that you write dataframe-agnostic code which all has
        the possibility of running entirely lazily.

        Arguments:
            backend: Which lazy backend collect to. This will be the underlying
                backend for the resulting Narwhals LazyFrame. If not specified, and the
                given library does not support lazy execution, then this will restrict
                the API to lazy-only operations.

                `backend` can be specified in various ways:

                - As `Implementation.<BACKEND>` with `BACKEND` being `DASK`, `DUCKDB`
                    or `POLARS`.
                - As a string: `"dask"`, `"duckdb"` or `"polars"`
                - Directly as a module `dask.dataframe`, `duckdb` or `polars`.

        Returns:
            A new LazyFrame.
        rw   )rt   lazy)ra   rw   ru   rg   rh   r|      s   zDataFrame.lazy.	as_seriesr~   Literal[True]dict[str, Series]c                C  ro   re   rg   ra   r~   rg   rg   rh   to_dict      zDataFrame.to_dictLiteral[False]dict[str, list[Any]]c                C  ro   re   rg   r   rg   rg   rh   r      r   bool(dict[str, Series] | dict[str, list[Any]]c                C  ro   re   rg   r   rg   rg   rh   r         Tc                  rz   )a1  Convert DataFrame to a dictionary mapping column name to values.

        Arguments:
            as_series: If set to true ``True``, then the values are Narwhals Series,
                    otherwise the values are Any.

        Returns:
            A mapping from column name to values / Series.
        r}   )rt   r   r   ru   rg   rh   r         c                   
   t   S )ziGet a mask of all duplicated rows in this DataFrame.

        Returns:
            A new Series.
        )rt   is_duplicatedrf   ru   rg   rh   r         
zDataFrame.is_duplicatedc                   r   )zeGet a mask of all unique rows in this DataFrame.

        Returns:
            A new Series.
        )rt   	is_uniquerf   ru   rg   rh   r      r   zDataFrame.is_uniquec                 C     |  t  S )zbPrivate, just used to test the stable API.

        Returns:
            A new DataFrame.
        selectall_l1_normrf   rg   rg   rh   r         zDataFrame._l1_norm)ra   rX   rb   rc   )ra   rX   rb   rk   )ra   rX   rm   rn   rb   r(   )ra   rX   rm   rr   rb   rX   )ra   rX   rm   r   rb   r   re   )ra   rX   rw   rx   rb   ry   )ra   rX   r~   r   rb   r   )ra   rX   r~   r   rb   r   )ra   rX   r~   r   rb   r   )ra   rX   rb   r(   ra   rX   rb   rX   )__name__
__module____qualname____doc__propertyri   rl   r   rq   r|   r   r   r   r   __classcell__rg   rg   ru   rh   r   c   s0    "r   c                      sX   e Zd ZdZedddZdd
dZ	dd fddZdddZdd  fddZ	  Z
S )!r   a  Narwhals LazyFrame, backed by a native lazyframe.

    !!! warning
        This class is not meant to be instantiated directly - instead use
        [`narwhals.from_native`][] with a native
        object that is a lazy dataframe from one of the supported
        backend (e.g. polars.LazyFrame, dask_expr._collection.DataFrame):
        ```py
        narwhals.from_native(native_lazyframe)
        ```
    ra   rX   rb   type[DataFrame[Any]]c                 C  rd   re   r   rf   rg   rg   rh   
_dataframe   rj   zLazyFrame._dataframeargr   c                 C  s   ddl m} ddlm} ddlm} t||r|jS t||r%d}t|t||r1|	| 
 S t d urJdtt|v rJdt| d}t|tt|)	Nr   	BaseFramer   r'   z.Mixing Series with LazyFrame is not supported.polarszExpected Narwhals object, got: z[.

Perhaps you:
- Forgot a `nw.from_native` somewhere?
- Used `pl.col` instead of `nw.col`?)narwhals.dataframer   narwhals.exprr   narwhals.seriesr(   
isinstance_compliant_frame	TypeError_to_compliant_expr__narwhals_namespace__r   strtyper   from_invalid_type)ra   r   r   r   r(   msgrg   rg   rh   _extract_compliant   s   


zLazyFrame._extract_compliantNrw   rx   kwargsDataFrame[Any]c                   s   t  jdd|i|S )a  Materialize this LazyFrame into a DataFrame.

        As each underlying lazyframe has different arguments to set when materializing
        the lazyframe into a dataframe, we allow to pass them as kwargs (see examples
        below for how to generalize the specification).

        Arguments:
            backend: specifies which eager backend collect to. This will be the underlying
                backend for the resulting Narwhals DataFrame. If None, then the following
                default conversions will be applied:

                - `polars.LazyFrame` -> `polars.DataFrame`
                - `dask.DataFrame` -> `pandas.DataFrame`
                - `duckdb.PyRelation` -> `pyarrow.Table`
                - `pyspark.DataFrame` -> `pyarrow.Table`

                `backend` can be specified in various ways:

                - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`
                    or `POLARS`.
                - As a string: `"pandas"`, `"pyarrow"` or `"polars"`
                - Directly as a module `pandas`, `pyarrow` or `polars`.
            kwargs: backend specific kwargs to pass along. To know more please check the
                backend specific documentation:

                - [polars.LazyFrame.collect](https://docs.pola.rs/api/python/dev/reference/lazyframe/api/polars.LazyFrame.collect.html)
                - [dask.dataframe.DataFrame.compute](https://docs.dask.org/en/stable/generated/dask.dataframe.DataFrame.compute.html)

        Returns:
            DataFrame
        rw   Nrg   )rt   collect)ra   rw   r   ru   rg   rh   r     s   $zLazyFrame.collectc                 C  r   )zbPrivate, just used to test the stable API.

        Returns:
            A new lazyframe.
        r   rf   rg   rg   rh   r   ?  r   zLazyFrame._l1_norm   nintc                   rs   )zGet the last `n` rows.

        Arguments:
            n: Number of rows to return.

        Returns:
            A subset of the LazyFrame of shape (n, n_columns).
        )rt   tailra   r   ru   rg   rh   r   G  s   	zLazyFrame.tailra   rX   rb   r   )ra   rX   r   r   rb   r   re   )ra   rX   rw   rx   r   r   rb   r   r   )r   )r   r   rb   rX   )r   r   r   r   r   r   r   r   r   r   r   rg   rg   ru   rh   r      s    

&r   c                      s   e Zd ZdZed9ddZd: fd	d
Zdddddd; fddZddddddddd< fd"d#Zddd$d= fd(d)Z	ddd$d= fd*d+Z
dddd,d> fd.d/Zdddd,d> fd0d1Z	d?ddd2d@ fd7d8Z  ZS )Ar(   ai  Narwhals Series, backed by a native series.

    !!! warning
        This class is not meant to be instantiated directly - instead:

        - If the native object is a series from one of the supported backend (e.g.
            pandas.Series, polars.Series, pyarrow.ChunkedArray), you can use
            [`narwhals.from_native`][]:
            ```py
            narwhals.from_native(native_series, allow_series=True)
            narwhals.from_native(native_series, series_only=True)
            ```

        - If the object is a generic sequence (e.g. a list or a tuple of values), you can
            create a series via [`narwhals.new_series`][]:
            ```py
            narwhals.new_series(
                name=name,
                values=values,
                native_namespace=narwhals.get_native_namespace(another_object),
            )
            ```
    ra   rX   rb   r   c                 C  rd   re   r   rf   rg   rg   rh   r   o  rj   zSeries._dataframer   c                   r   )zsConvert to dataframe.

        Returns:
            A DataFrame containing this Series as a single column.
        )rt   to_framerf   ru   rg   rh   r   s  r   zSeries.to_frameFNsortparallelname	normalizer   r   r   r   
str | Noner   c                  s   t  j||||dS )a  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 DataFrame with two columns:
            - The original values as first column
            - Either count or proportion as second column, depending on normalize parameter.
        r   )rt   value_counts)ra   r   r   r   r   ru   rg   rh   r   {  s   zSeries.value_countsT   comspan	half_lifealphaadjustmin_samplesignore_nullsr   float | Noner   r   r   r   r   r   r   c             	     F   ddl m} ddlm}	 d}
t|
||	 d t j|||||||d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_samples: 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
        r   NarwhalsUnstableWarningrK   z^`Series.ewm_mean` is being called from the stable API although considered an unstable feature.messagecategory
stacklevelr   narwhals.exceptionsr   narwhals.utilsrL   r   rt   ewm_meanra   r   r   r   r   r   r   r   r   rL   r   ru   rg   rh   r        4zSeries.ewm_meanr   centerwindow_size
int | Noner   c                  >   ddl m} ddlm} d}t||| d t j|||d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_samples: 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 series.
        r   r   rK   za`Series.rolling_sum` is being called from the stable API although considered an unstable feature.r   r   r   r   r   r   r   rL   r   rt   rolling_sumra   r   r   r   r   rL   r   ru   rg   rh   r        zSeries.rolling_sumc                  r   )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_samples: 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 series.
        r   r   rK   zb`Series.rolling_mean` is being called from the stable API although considered an unstable feature.r   r   r   r   r   rL   r   rt   rolling_meanr   ru   rg   rh   r   	  r   zSeries.rolling_meanr   r   ddofr   c                  @   ddl m} ddlm} d}t||| d t j||||dS )a  Apply a rolling variance (moving variance) 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 variance.

        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_samples: 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.
            ddof: Delta Degrees of Freedom; the divisor for a length N window is N - ddof.

        Returns:
            A new series.
        r   r   rK   za`Series.rolling_var` is being called from the stable API although considered an unstable feature.r   r   r   r   r   r   r   r   rL   r   rt   rolling_varra   r   r   r   r   r   rL   r   ru   rg   rh   r   6     !zSeries.rolling_varc                  r   )a  Apply a rolling standard deviation (moving standard deviation) 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 standard deviation.

        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_samples: 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.
            ddof: Delta Degrees of Freedom; the divisor for a length N window is N - ddof.

        Returns:
            A new series.
        r   r   rK   za`Series.rolling_std` is being called from the stable API although considered an unstable feature.r   r   r   r   r   rL   r   rt   rolling_stdr   ru   rg   rh   r   f  r   zSeries.rolling_std)	bin_countinclude_breakpointbinslist[float | int] | Noner   r   c                  r   )ak  Bin values into buckets and count their occurrences.

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

        Arguments:
            bins: A monotonically increasing sequence of values.
            bin_count: If no bins provided, this will be used to determine the distance of the bins.
            include_breakpoint: Include a column that shows the intervals as categories.

        Returns:
            A new DataFrame containing the counts of values that occur within each passed bin.
        r   r   rK   zZ`Series.hist` is being called from the stable API although considered an unstable feature.r   )r   r   r   )r   r   r   rL   r   rt   hist)ra   r   r   r   r   rL   r   ru   rg   rh   r     s   zSeries.histr   )ra   rX   rb   r   )ra   rX   r   r   r   r   r   r   r   r   rb   r   ra   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rb   rX   
ra   rX   r   r   r   r   r   r   rb   rX   ra   rX   r   r   r   r   r   r   r   r   rb   rX   re   )
ra   rX   r   r   r   r   r   r   rb   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg   rg   ru   rh   r(   S  sJ    J1142r(   c                      s  e Zd ZdA fddZddddddd	d
dB fddZdd	ddC fddZdd	ddC fddZdd	dddD fd!d"Zdd	dddD fd#d$ZdEdFd'd(Z	dEdFd)d*Z
dGdHd-d.Zdd/dId2d3Zd	d	d4dJd7d8ZdAd9d:Z	dKdd	dd;dLd?d@Z  ZS )Mr   ra   rX   rb   c                   r   re   )rt   _taxicab_normrf   ru   rg   rh   r     s   
zExpr._l1_normNTr   Fr   r   r   r   r   r   r   r   r   r   r   c             	     r   )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_samples: 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:
            Expr
        r   r   rK   z\`Expr.ewm_mean` is being called from the stable API although considered an unstable feature.r   r   r   r   ru   rg   rh   r     r   zExpr.ewm_meanr   r   r   r   c                  r   )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_samples: 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.
        r   r   rK   z_`Expr.rolling_sum` is being called from the stable API although considered an unstable feature.r   r   r   r   ru   rg   rh   r     r   zExpr.rolling_sumc                  r   )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_samples: 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.
        r   r   rK   z``Expr.rolling_mean` is being called from the stable API although considered an unstable feature.r   r   r   r   ru   rg   rh   r   1  r   zExpr.rolling_meanr   r   c                  r   )a  Apply a rolling variance (moving variance) 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 variance.

        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_samples: 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.
            ddof: Delta Degrees of Freedom; the divisor for a length N window is N - ddof.

        Returns:
            A new expression.
        r   r   rK   z_`Expr.rolling_var` is being called from the stable API although considered an unstable feature.r   r   r   r   ru   rg   rh   r   ^  s   !zExpr.rolling_varc                  r   )a  Apply a rolling standard deviation (moving standard deviation) 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 standard deviation.

        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_samples: 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.
            ddof: Delta Degrees of Freedom; the divisor for a length N window is N - ddof.

        Returns:
            A new expression.
        r   r   rK   z_`Expr.rolling_std` is being called from the stable API although considered an unstable feature.r   r   r   r   ru   rg   rh   r     r   zExpr.rolling_std
   r   c                      j  fddddjdS )zGet the first `n` rows.

        Arguments:
            n: Number of rows to return.

        Returns:
            A new expression.
        c                       |  S re   )r   headplxr   ra   rg   rh   <lambda>      zExpr.head.<locals>.<lambda>Tis_order_dependentchanges_length
aggregatesrv   _aggregatesr   rg   r   rh   r        	z	Expr.headc                   r   )zGet the last `n` rows.

        Arguments:
            n: Number of rows to return.

        Returns:
            A new expression.
        c                   r   re   )r   r   r   r   rg   rh   r     r   zExpr.tail.<locals>.<lambda>Tr   r  r   rg   r   rh   r     r  z	Expr.tailr   offsetc                   s    j  fddddjdS )zTake every nth value in the Series and return as new Series.

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

        Returns:
            A new expression.
        c                       | j dS )N)r   r  )r   gather_everyr   r   r  ra   rg   rh   r     s    z#Expr.gather_every.<locals>.<lambda>Tr   r  )ra   r   r  rg   r  rh   r    s   
zExpr.gather_every)maintain_orderr	  bool | Nonec                  s:   |durd}t |tt d  j fdd jd jdS )aT  Return unique values of this expression.

        Arguments:
            maintain_order: Keep the same order as the original expression.
                This is deprecated and will be removed in a future version,
                but will still be kept around in `narwhals.stable.v1`.

        Returns:
            A new expression.
        Nzx`maintain_order` has no effect and is only kept around for backwards-compatibility. You can safely remove this argument.r   c                        |  S re   )r   uniquer   rf   rg   rh   r         zExpr.unique.<locals>.<lambda>T)r   r  )r   UserWarningrL   rv   _is_order_dependentr  )ra   r	  r   rg   rf   rh   r    s   
zExpr.unique
descending
nulls_lastr  r  c                  s"   j  fdddjjdS )zSort this column. Place null values first.

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

        Returns:
            A new expression.
        c                   r  )Nr  )r   r   r   r  r  ra   rg   rh   r     s   
 zExpr.sort.<locals>.<lambda>Tr   )rv   _changes_lengthr  )ra   r  r  rg   r  rh   r     s   
z	Expr.sortc                   s    j  fdddd jdS )zhFind elements where boolean expression is True.

        Returns:
            A new expression.
        c                   r  re   )r   arg_truer   rf   rg   rh   r     r  zExpr.arg_true.<locals>.<lambda>Tr   r  rf   rg   rf   rh   r    s   
zExpr.arg_truefractionwith_replacementseedr  r  r  c                  s$   j  fddddjdS )aR  Sample randomly from this expression.

        !!! warning
            `Expr.sample` is deprecated and will be removed in a future version.
            Hint: instead of `df.select(nw.col('a').sample())`, use
            `df.select(nw.col('a')).sample()` instead.
            Note: this will remain available in `narwhals.stable.v1`.
            See [stable api](../backcompat.md/) for more information.

        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.

        Returns:
            A new expression.
        c                   s    | j dS )Nr  )r   sampler   r  r   r  ra   r  rg   rh   r   @  s   
 zExpr.sample.<locals>.<lambda>Tr   r  )ra   r   r  r  r  rg   r  rh   r  $  s   zExpr.sampler   r   r   r   )r   )ra   rX   r   r   rb   rX   )r   )ra   rX   r   r   r  r   rb   rX   )ra   rX   r	  r
  rb   rX   )ra   rX   r  r   r  r   rb   rX   re   )ra   rX   r   r   r  r   r  r   r  r   rb   rX   )r   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r  r   rg   rg   ru   rh   r     sH    J1110
r   c                   @  s   e Zd ZdZejZdS )r&   a:  Ordered mapping of column names to their data type.

    Arguments:
        schema: Mapping[str, DType] | Iterable[tuple[str, DType]] | None
            The schema definition given by column names and their associated.
            *instantiated* Narwhals data type. Accepts a mapping or an iterable of tuples.
    N)r   r   r   r   rJ   V1_versionrg   rg   rg   rh   r&   I  s    
r&   objNwDataFrame[IntoFrameT]rb   DataFrame[IntoFrameT]c                 C  ro   re   rg   r  rg   rg   rh   
_stableifyU  r   r"  NwLazyFrame[IntoFrameT]LazyFrame[IntoFrameT]c                 C  ro   re   rg   r!  rg   rg   rh   r"  W  r   NwSeries[Any]c                 C  ro   re   rg   r!  rg   rg   rh   r"  Y  r   NwExprc                 C  ro   re   rg   r!  rg   rg   rh   r"  [  r   r   c                 C  ro   re   rg   r!  rg   rg   rh   r"  ]  r   PNwDataFrame[IntoFrameT] | NwLazyFrame[IntoFrameT] | NwSeries[Any] | NwExpr | AnyCDataFrame[IntoFrameT] | LazyFrame[IntoFrameT] | Series | Expr | Anyc                 C  s   t | trt| jtj| jdS t | tr"t	| jtj| jdS t | t
r3t| jtj| jdS t | trDt| j| j| j| jdS | S )N)levelr   )r   NwDataFramer   r   _change_versionrJ   r  _levelNwLazyFramer   NwSeriesr(   _compliant_seriesr&  r   r   r  r  r  r!  rg   rg   rh   r"  a  s.   



.)
eager_onlyseries_onlynative_objectIntoDataFrameT | IntoSeriesstrictr   r0  eager_or_interchange_onlyr   r1  allow_series"DataFrame[IntoDataFrameT] | Seriesc                C  ro   re   rg   r2  r4  r0  r5  r1  r6  rg   rg   rh   from_native}     	r9  )r5  r1  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r0  r1  r6  rG   NoneDataFrame[IntoDataFrameT]c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r5  r1  r6  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r0  r5  r1  IntoFrameT | IntoSeries6DataFrame[IntoFrameT] | LazyFrame[IntoFrameT] | Seriesc                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r0  r5  r6  r]   c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r0  r5  r1  r6  rH   -DataFrame[IntoFrameT] | LazyFrame[IntoFrameT]c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r4  r0  r1  r6  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r4  r5  r1  r6  c                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r4  r0  r5  r1  IntoFrame | IntoSeries(DataFrame[Any] | LazyFrame[Any] | Seriesc                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r4  r0  r5  r6  IntoSeries | Anyc                C  ro   re   rg   r8  rg   rg   rh   r9    r:  )r4  r0  r5  r1  r6  c                C  ro   re   rg   r8  rg   rg   rh   r9  %  r:  pass_throughc                C  ro   re   rg   r2  rC  r0  r5  r1  r6  rg   rg   rh   r9  1  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9  =  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9  I  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9  U  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9  a  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9  m  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9  y  r:  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  )rC  r0  r1  r6  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  )rC  r5  r1  r6  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  )rC  r0  r5  r1  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  )rC  r0  r5  r6  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  rC  r0  r5  r1  r6  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  F)r5  r   r
  c                C  ro   re   rg   rD  rg   rg   rh   r9    r:  )r4  rC  r0  r5  r1  r6  'IntoFrameT | IntoFrame | IntoSeries | T:LazyFrame[IntoFrameT] | DataFrame[IntoFrameT] | Series | Tc             	   C  s\   t | ttfr|s| S t | tr|s|r| S t||ddd}t| |||||tjd}t|S )a	  Convert `native_object` to Narwhals Dataframe, Lazyframe, or Series.

    Arguments:
        native_object: Raw object from user.
            Depending on the other arguments, input object can be:

            - a Dataframe / Lazyframe / Series supported by Narwhals (pandas, Polars, PyArrow, ...)
            - an object which implements `__narwhals_dataframe__`, `__narwhals_lazyframe__`,
              or `__narwhals_series__`
        strict: Determine what happens if the object can't be converted to Narwhals:

            - `True` or `None` (default): raise an error
            - `False`: pass object through as-is

            **Deprecated** (v1.13.0):
                Please use `pass_through` instead. Note that `strict` is still available
                (and won't emit a deprecation warning) if you use `narwhals.stable.v1`,
                see [perfect backwards compatibility policy](../backcompat.md/).
        pass_through: Determine what happens if the object can't be converted to Narwhals:

            - `False` or `None` (default): raise an error
            - `True`: pass object through as-is
        eager_only: Whether to only allow eager objects:

            - `False` (default): don't require `native_object` to be eager
            - `True`: only convert to Narwhals if `native_object` is eager
        eager_or_interchange_only: Whether to only allow eager objects or objects which
            have interchange-level support in Narwhals:

            - `False` (default): don't require `native_object` to either be eager or to
              have interchange-level support in Narwhals
            - `True`: only convert to Narwhals if `native_object` is eager or has
              interchange-level support in Narwhals

            See [interchange-only support](../extending.md/#interchange-only-support)
            for more details.
        series_only: Whether to only allow Series:

            - `False` (default): don't require `native_object` to be a Series
            - `True`: only convert to Narwhals if `native_object` is a Series
        allow_series: Whether to allow Series (default is only Dataframe / Lazyframe):

            - `False` or `None` (default): don't convert to Narwhals if `native_object` is a Series
            - `True`: allow `native_object` to be a Series

    Returns:
        DataFrame, LazyFrame, Series, or original object, depending
            on which combination of parameters was passed.
    Fpass_through_defaultemit_deprecation_warning)rC  r0  r5  r1  r6  version)	r   r   r   r(   rV   rD   rJ   r  r"  )r2  r4  rC  r0  r5  r1  r6  resultrg   rg   rh   r9    s"   <	)r4  narwhals_objectc                C  ro   re   rg   rM  r4  rg   rg   rh   	to_nativeC  r   rO  c                C  ro   re   rg   rN  rg   rg   rh   rO  G  r   c                C  ro   re   rg   rN  rg   rg   rh   rO  K  r   c                C  ro   re   rg   rN  rg   rg   rh   rO  M  r   rC  c                C  ro   re   rg   rM  rC  rg   rg   rh   rO  O  r   c                C  ro   re   rg   rQ  rg   rg   rh   rO  S  r   c                C  ro   re   rg   rQ  rg   rg   rh   rO  W  r   c                C  ro   re   rg   rQ  rg   rg   rh   rO  Y  r   )r4  rC  :DataFrame[IntoDataFrameT] | LazyFrame[IntoFrameT] | SeriesIntoFrameT | Anyc                C  sx   ddl m} ddlm} ddlm} |||ddd}t| |r#| jjS t| |r,| j	j
S |s:dt|  d}t|| S )	a<  Convert Narwhals object to native one.

    Arguments:
        narwhals_object: Narwhals object.
        strict: Determine what happens if `narwhals_object` isn't a Narwhals class:

            - `True` (default): raise an error
            - `False`: pass object through as-is

            **Deprecated** (v1.13.0):
                Please use `pass_through` instead. Note that `strict` is still available
                (and won't emit a deprecation warning) if you use `narwhals.stable.v1`,
                see [perfect backwards compatibility policy](../backcompat.md/).
        pass_through: Determine what happens if `narwhals_object` isn't a Narwhals class:

            - `False` (default): raise an error
            - `True`: pass object through as-is

    Returns:
        Object of class that user started with.
    r   r   r'   rU   FrH  zExpected Narwhals object, got .)r   r   r   r(   r   rV   r   r   _native_framer/  _native_seriesr   r   )rM  r4  rC  r   r(   rV   r   rg   rg   rh   rO  ]  s   

TfuncCallable[..., Any] | NoneCallable[..., Any]c                  s:   t |dddd
 fdd}| d	u r|S || S )a
  Decorate function so it becomes dataframe-agnostic.

    This will try to convert any dataframe/series-like object into the Narwhals
    respective DataFrame/Series, while leaving the other parameters as they are.
    Similarly, if the output of the function is a Narwhals DataFrame or Series, it will be
    converted back to the original dataframe/series type, while if the output is another
    type it will be left as is.
    By setting `pass_through=False`, then every input and every output will be required to be a
    dataframe/series-like object.

    Arguments:
        func: Function to wrap in a `from_native`-`to_native` block.
        strict: **Deprecated** (v1.13.0):
            Please use `pass_through` instead. Note that `strict` is still available
            (and won't emit a deprecation warning) if you use `narwhals.stable.v1`,
            see [perfect backwards compatibility policy](../backcompat.md/).

            Determine what happens if the object can't be converted to Narwhals:

            - `True` or `None` (default): raise an error
            - `False`: pass object through as-is
        pass_through: Determine what happens if the object can't be converted to Narwhals:

            - `False` or `None` (default): raise an error
            - `True`: pass object through as-is
        eager_only: Whether to only allow eager objects:

            - `False` (default): don't require `native_object` to be eager
            - `True`: only convert to Narwhals if `native_object` is eager
        eager_or_interchange_only: Whether to only allow eager objects or objects which
            have interchange-level support in Narwhals:

            - `False` (default): don't require `native_object` to either be eager or to
              have interchange-level support in Narwhals
            - `True`: only convert to Narwhals if `native_object` is eager or has
              interchange-level support in Narwhals

            See [interchange-only support](../extending.md/#interchange-only-support)
            for more details.
        series_only: Whether to only allow Series:

            - `False` (default): don't require `native_object` to be a Series
            - `True`: only convert to Narwhals if `native_object` is a Series
        allow_series: Whether to allow Series (default is only Dataframe / Lazyframe):

            - `False` or `None`: don't convert to Narwhals if `native_object` is a Series
            - `True` (default): allow `native_object` to be a Series

    Returns:
        Decorated function.
    TFrH  rW  rY  rb   c                   s$   t  d fdd}|S )Nargsr   r   rb   c                    s   fdd| D } fdd|  D } fddg | | R D }| dkr8d}t|| i |}t|d	S )
Nc              
     s    g | ]}t | d qS rE  r9  ).0r   r6  r0  r5  rC  r1  rg   rh   
<listcomp>  s    	zBnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>c                   s&   i | ]\}}|t | d qS r[  r\  )r]  r   valuer^  rg   rh   
<dictcomp>  s    	zBnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<dictcomp>c                   s"   h | ]}t |d d  r  qS )__native_namespace__N)getattr)r]  vbrg   rh   	<setcomp>  s    zAnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<setcomp>r   z_Found multiple backends. Make sure that all dataframe/series inputs come from the same backend.rP  )itemsvalues__len__
ValueErrorrO  )rZ  r   backendsr   rL  )r6  r0  r5  rW  rC  r1  re  rh   wrapper  s   		
z.narwhalify.<locals>.decorator.<locals>.wrapper)rZ  r   r   r   rb   r   r   )rW  rm  r^  )rW  rh   	decorator  s   'znarwhalify.<locals>.decoratorN)rW  rY  rb   rY  rU   )rW  r4  rC  r0  r5  r1  r6  rn  rg   r^  rh   
narwhalify  s   =+ro  c                   C     t t S )z`Instantiate an expression representing all columns.

    Returns:
        A new expression.
    )r"  nwr   rg   rg   rg   rh   r        r   namesstr | Iterable[str]c                  G     t tj|  S )zCreates an expression that references one or more columns by their name(s).

    Arguments:
        names: Name(s) of the columns to use.

    Returns:
        A new expression.
    )r"  rq  col)rs  rg   rg   rh   rv    s   	rv  indicesint | Sequence[int]c                  G  ru  )aI  Creates an expression that references one or more columns by their index(es).

    Notes:
        `nth` is not supported for Polars version<1.0.0. Please use
        [`narwhals.col`][] instead.

    Arguments:
        indices: One or more indices representing the columns to retrieve.

    Returns:
        A new expression.
    )r"  rq  nth)rw  rg   rg   rh   ry       ry  c                   C  rp  )zGReturn the number of rows.

    Returns:
        A new expression.
    )r"  rq  lenrg   rg   rg   rh   r{  #  rr  r{  r`  dtypeDType | type[DType] | Nonec                 C  s   t t| |S )a  Return an expression representing a literal value.

    Arguments:
        value: The value to use as literal.
        dtype: The data type of the literal value. If not provided, the data type will
            be inferred.

    Returns:
        A new expression.
    )r"  rq  lit)r`  r|  rg   rg   rh   r~  ,  s   r~  columnsr   c                  G  ru  )zReturn the minimum value.

    Note:
       Syntactic sugar for ``nw.col(columns).min()``.

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function.

    Returns:
        A new expression.
    )r"  rq  minr  rg   rg   rh   r  :  r   r  c                  G  ru  )zReturn the maximum value.

    Note:
       Syntactic sugar for ``nw.col(columns).max()``.

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function.

    Returns:
        A new expression.
    )r"  rq  maxr  rg   rg   rh   r  I  r   r  c                  G  ru  )zGet the mean value.

    Note:
        Syntactic sugar for ``nw.col(columns).mean()``

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function

    Returns:
        A new expression.
    )r"  rq  meanr  rg   rg   rh   r  X  r   r  c                  G  ru  )at  Get the median value.

    Notes:
        - Syntactic sugar for ``nw.col(columns).median()``
        - Results might slightly differ across backends due to differences in the
            underlying algorithms used to compute the median.

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function

    Returns:
        A new expression.
    )r"  rq  medianr  rg   rg   rh   r  g  s   r  c                  G  ru  )zSum all values.

    Note:
        Syntactic sugar for ``nw.col(columns).sum()``

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function

    Returns:
        A new expression.
    )r"  rq  sumr  rg   rg   rh   r  x  r   r  exprsIntoExpr | Iterable[IntoExpr]c                  G  ru  )a2  Sum all values horizontally across columns.

    Warning:
        Unlike Polars, we support horizontal sum over numeric columns only.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.

    Returns:
        A new expression.
    )r"  rq  sum_horizontalr  rg   rg   rh   r    rz  r  c                  G  ru  )zCompute the bitwise AND horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.

    Returns:
        A new expression.
    )r"  rq  all_horizontalr  rg   rg   rh   r       
r  c                  G  ru  )zCompute the bitwise OR horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.

    Returns:
        A new expression.
    )r"  rq  any_horizontalr  rg   rg   rh   r    r  r  c                  G  ru  )zCompute the mean of all values horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.

    Returns:
        A new expression.
    )r"  rq  mean_horizontalr  rg   rg   rh   r    r  r  c                  G  ru  )a*  Get the minimum value horizontally across columns.

    Notes:
        We support `min_horizontal` over numeric columns only.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.

    Returns:
        A new expression.
    )r"  rq  min_horizontalr  rg   rg   rh   r    rz  r  c                  G  ru  )a*  Get the maximum value horizontally across columns.

    Notes:
        We support `max_horizontal` over numeric columns only.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.

    Returns:
        A new expression.
    )r"  rq  max_horizontalr  rg   rg   rh   r    rz  r  verticalhowrh  #Iterable[DataFrame[IntoDataFrameT]]r  -Literal['horizontal', 'vertical', 'diagonal']c                C  ro   re   rg   rh  r  rg   rg   rh   concat     r  Iterable[LazyFrame[IntoFrameT]]c                C  ro   re   rg   r  rg   rg   rh   r    r  ;Iterable[DataFrame[IntoDataFrameT] | LazyFrame[IntoFrameT]]1DataFrame[IntoDataFrameT] | LazyFrame[IntoFrameT]c                C  ro   re   rg   r  rg   rg   rh   r    r  c                C  s   t tj| |dS )a  Concatenate multiple DataFrames, LazyFrames into a single entity.

    Arguments:
        items: DataFrames, LazyFrames to concatenate.
        how: concatenating strategy:

            - vertical: Concatenate vertically. Column names must match.
            - horizontal: Concatenate horizontally. If lengths don't match, then
                missing rows are filled with null values.
            - diagonal: Finds a union between the column schemas and fills missing column
                values with null.

    Returns:
        A new DataFrame, Lazyframe resulting from the concatenation.

    Raises:
        TypeError: The items to concatenate should either all be eager, or all lazy
    r  )r"  rq  r  r  rg   rg   rh   r    s    	separatorr   
more_exprsr[   r  r   c                G  s   t tj| g|R ||dS )a  Horizontally concatenate columns into a single string column.

    Arguments:
        exprs: Columns to concatenate into a single string column. Accepts expression
            input. Strings are parsed as column names, other non-expression inputs are
            parsed as literals. Non-`String` columns are cast to `String`.
        *more_exprs: Additional columns to concatenate into a single string column,
            specified as positional arguments.
        separator: String that will be used to separate the values of each column.
        ignore_nulls: Ignore null values (default is `False`).
            If set to `False`, null values will be propagated and if the row contains any
            null values, the output is null.

    Returns:
        A new expression.
    r  )r"  rq  
concat_str)r  r  r   r  rg   rg   rh   r    s   r  c                      ,   e Zd ZedddZd fddZ  ZS )r   clsr   r%   NwWhenrb   c                 C  s
   | |j  S re   )_predicates)r  r%   rg   rg   rh   	from_when,  s   
zWhen.from_whenra   rX   r`  r   r   c                   s   t t |S re   )r   	from_thenrt   thenra   r`  ru   rg   rh   r  0  s   z	When.then)r  r   r%   r  rb   r   )ra   rX   r`  r   rb   r   )r   r   r   classmethodr  r  r   rg   rg   ru   rh   r   +  s    r   c                      r  )r   r  r   r  NwThenrb   c                 C  s   | |j |j|j|jdS )Nr   )r   r  r  r  )r  r  rg   rg   rh   r  5  s   zThen.from_thenra   rX   r`  r   r   c                   s   t t |S re   )r"  rt   	otherwiser  ru   rg   rh   r  >  s   zThen.otherwise)r  r   r  r  rb   r   )ra   rX   r`  r   rb   r   )r   r   r   r  r  r  r   rg   rg   ru   rh   r   4  s    r   
predicatesc                  G  s   t t|  S )a  Start a `when-then-otherwise` expression.

    Expression similar to an `if-else` statement in Python. Always initiated by a
    `pl.when(<condition>).then(<value if condition>)`, and optionally followed by
    chaining one or more `.when(<condition>).then(<value>)` statements.
    Chained when-then operations should be read as Python `if, elif, ... elif`
    blocks, not as `if, if, ... if`, i.e. the first condition that evaluates to
    `True` will be picked.
    If none of the conditions are `True`, an optional
    `.otherwise(<value if all statements are false>)` can be appended at the end.
    If not appended, and none of the conditions are `True`, `None` will be returned.

    Arguments:
        predicates: Condition(s) that must be met in order to apply the subsequent
            statement. Accepts one or more boolean expressions, which are implicitly
            combined with `&`. String input is parsed as a column name.

    Returns:
        A "when" object, which `.then` can be called on.
    )r   r  nw_when)r  rg   rg   rh   r%   B  s   r%   r   ri  native_namespacerW   c                C  s   t t| |||tjdS )a  Instantiate Narwhals Series from iterable (e.g. list or array).

    Arguments:
        name: Name of resulting Series.
        values: Values of make Series from.
        dtype: (Narwhals) dtype. If not provided, the native library
            may auto-infer it from `values`.
        native_namespace: The native library to use for DataFrame creation.

    Returns:
        A new Series
    r  rK  )r"  r   rJ   r  )r   ri  r|  r  rg   rg   rh   
new_seriesZ  s   r  native_framerZ   r   c                C  s   t t| |dS )a  Construct a DataFrame from an object which supports the PyCapsule Interface.

    Arguments:
        native_frame: Object which implements `__arrow_c_stream__`.
        native_namespace: The native library to use for DataFrame creation.

    Returns:
        A new DataFrame.
    )r  )r"  nw_from_arrow)r  r  rg   rg   rh   r"   x  s   
r"   )rw   r  datadict[str, Any]schema dict[str, DType] | Schema | Nonerw   rx   ModuleType | Nonec                C  s    t ||dd}tt| ||dS )aQ  Instantiate DataFrame from dictionary.

    Indexes (if present, for pandas-like backends) are aligned following
    the [left-hand-rule](../pandas_like_concepts/pandas_index.md/).

    Notes:
        For pandas-like dataframes, conversion to schema is applied after dataframe
        creation.

    Arguments:
        data: Dictionary to create DataFrame from.
        schema: The DataFrame schema as Schema or dict of {name: type}.
        backend: specifies which eager backend instantiate to. Only
            necessary if inputs are not Narwhals Series.

                `backend` can be specified in various ways:

                - As `Implementation.<BACKEND>` with `BACKEND` being `PANDAS`, `PYARROW`,
                    `POLARS`, `MODIN` or `CUDF`.
                - As a string: `"pandas"`, `"pyarrow"`, `"polars"`, `"modin"` or `"cudf"`.
                - Directly as a module `pandas`, `pyarrow`, `polars`, `modin` or `cudf`.
        native_namespace: The native library to use for DataFrame creation.

            **Deprecated** (v1.26.0):
                Please use `backend` instead. Note that `native_namespace` is still available
                (and won't emit a deprecation warning) if you use `narwhals.stable.v1`,
                see [perfect backwards compatibility policy](../backcompat.md/).

    Returns:
        A new DataFrame.
    F)rJ  r{   )rT   r"  r   )r  r  rw   r  rg   rg   rh   	from_dict  s   &r  r_   ,dict[str, DType] | Schema | list[str] | Nonec                C  s   t t| ||tjdS )a  Construct a DataFrame from a NumPy ndarray.

    Notes:
        Only row orientation is currently supported.

        For pandas-like dataframes, conversion to schema is applied after dataframe
        creation.

    Arguments:
        data: Two-dimensional data represented as a NumPy ndarray.
        schema: The DataFrame schema as Schema, dict of {name: type}, or a list of str.
        native_namespace: The native library to use for DataFrame creation.

    Returns:
        A new DataFrame.
    r  )r"  r   rJ   r  )r  r  r  rg   rg   rh   
from_numpy  s   r  sourcer   c                K     t t| fd|i|S )a  Read a CSV file into a DataFrame.

    Arguments:
        source: Path to a file.
        native_namespace: The native library to use for DataFrame creation.
        kwargs: Extra keyword arguments which are passed to the native CSV reader.
            For example, you could use
            `nw.read_csv('file.csv', native_namespace=pd, engine='pyarrow')`.

    Returns:
        DataFrame.
    r  )r"  r   r  r  r   rg   rg   rh   read_csv     r  ry   c                K  r  )a&  Lazily read from a CSV file.

    For the libraries that do not support lazy dataframes, the function reads
    a csv file eagerly and then converts the resulting dataframe to a lazyframe.

    Arguments:
        source: Path to a file.
        native_namespace: The native library to use for DataFrame creation.
        kwargs: Extra keyword arguments which are passed to the native CSV reader.
            For example, you could use
            `nw.scan_csv('file.csv', native_namespace=pd, engine='pyarrow')`.

    Returns:
        LazyFrame.
    r  )r"  r    r  rg   rg   rh   scan_csv     r  c                K  r  )a  Read into a DataFrame from a parquet file.

    Arguments:
        source: Path to a file.
        native_namespace: The native library to use for DataFrame creation.
        kwargs: Extra keyword arguments which are passed to the native parquet reader.
            For example, you could use
            `nw.read_parquet('file.parquet', native_namespace=pd, engine='pyarrow')`.

    Returns:
        DataFrame.
    r  )r"  r   r  rg   rg   rh   read_parquet	  r  r  c                K  r  )a:  Lazily read from a parquet file.

    For the libraries that do not support lazy dataframes, the function reads
    a parquet file eagerly and then converts the resulting dataframe to a lazyframe.

    Arguments:
        source: Path to a file.
        native_namespace: The native library to use for DataFrame creation.
        kwargs: Extra keyword arguments which are passed to the native parquet reader.
            For example, you could use
            `nw.scan_parquet('file.parquet', native_namespace=pd, engine='pyarrow')`.

    Returns:
        LazyFrame.
    r  )r"  r!   r  rg   rg   rh   scan_parquet	  r  r  )Mr*   r+   r,   r   r-   r.   r/   r0   r1   r   r2   r3   r4   rI   r5   r6   r7   r8   r9   r   r:   r;   r&   r(   r<   r=   r>   r?   r@   rA   rB   rC   r   r  r  rv  r  r  r   r)   r   r"   r  r9  r  rM   r#   rE   rN   r{  r~  r  r  rO   rP   rQ   rR   rS   r  r  r  r  r  ro  r  ry  r  r  r  r  r   r$   r  r  rO  rF   r%   )r  r  rb   r   )r  r#  rb   r$  )r  r%  rb   r(   )r  r&  rb   r   )r  r   rb   r   )r  r'  rb   r(  )r2  r3  r4  r   r0  r   r5  r   r1  r   r6  r   rb   r7  )r2  r3  r4  r   r0  r   r5  r   r1  r   r6  r   rb   r7  )r2  rG   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  r`   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r`   )r2  rG   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  r`   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r`   )r2  r=  r4  r   r0  r   r5  r   r1  r   r6  r   rb   r>  )r2  r]   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r(   )r2  rH   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r?  )r2  r`   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r`   )r2  rG   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  rG   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  r@  r4  r   r0  r   r5  r   r1  r   r6  r   rb   rA  )r2  rB  r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r(   )r2  rH   r4  r   r0  r   r5  r   r1  r   r6  r;  rb   r?  )r2  r3  rC  r   r0  r   r5  r   r1  r   r6  r   rb   r<  )r2  r3  rC  r   r0  r   r5  r   r1  r   r6  r   rb   r7  )r2  rG   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  r`   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r`   )r2  rG   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  r`   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r`   )r2  r=  rC  r   r0  r   r5  r   r1  r   r6  r   rb   r>  )r2  r]   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r(   )r2  rH   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r?  )r2  r`   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r`   )r2  rG   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  rG   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r<  )r2  r@  rC  r   r0  r   r5  r   r1  r   r6  r   rb   rA  )r2  r]   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r(   )r2  rH   rC  r   r0  r   r5  r   r1  r   r6  r;  rb   r?  )r2  r   rC  r   r0  r   r5  r   r1  r   r6  r
  rb   r   )r2  rF  r4  r
  rC  r
  r0  r   r5  r   r1  r   r6  r
  rb   rG  )rM  r<  r4  r   rb   rG   )rM  r$  r4  r   rb   rH   )rM  r(   r4  r   rb   r   )rM  r   r4  r   rb   r   )rM  r<  rC  r   rb   rG   )rM  r$  rC  r   rb   rH   )rM  r(   rC  r   rb   r   )rM  r   rC  r   rb   r   )rM  rR  r4  r
  rC  r
  rb   rS  re   )rW  rX  r4  r
  rC  r
  r0  r   r5  r   r1  r   r6  r
  rb   rY  )rb   r   )rs  rt  rb   r   )rw  rx  rb   r   )r`  r   r|  r}  rb   r   )r  r   rb   r   )r  r  rb   r   )rh  r  r  r  rb   r<  )rh  r  r  r  rb   r$  )rh  r  r  r  rb   r  )
r  r  r  r[   r  r   r   r   rb   r   )r  r  rb   r   )
r   r   ri  r   r|  r}  r  rW   rb   r(   )r  rZ   r  rW   rb   r   )
r  r  r  r  rw   rx   r  r  rb   r   )r  r_   r  r  r  rW   rb   r   )r  r   r  rW   r   r   rb   r   )r  r   r  rW   r   r   rb   ry   )
__future__r   	functoolsr   typingr   r   r   r   r	   r
   r   r   warningsr   narwhalsrq  r   r   r   r   r   r*  r   r-  narwhals.dependenciesr   r   r   r   r   r&  narwhals.functionsr   r  r   r  r   r   r   r   r   r    r!   r"   r  r#   r$   r%   r  narwhals.schemar&   NwSchemar   r(   r.  narwhals.stable.v1r)   narwhals.stable.v1.dtypesr*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   narwhals.translaterD   rE   rF   narwhals.typingrG   rH   r   rI   rJ   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rV   typesrW   typing_extensionsrX   narwhals.dtypesrY   rZ   r[   r\   r]   r^   r_   r`   r"  r9  rO  ro  r   rv  ry  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __all__rg   rg   rg   rh   <module>   s    d  i   Q/s		
	0 