
    -Ph                   v   U d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZmZ d dlmZmZmZmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZ d dl m!Z!m"Z"m#Z#m$Z$ d dl%m&Z&m'Z' d d	l(m)Z) d d
l*m+Z+m,Z, erWd dl-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK dZLdeMd<   ddddZN ed d!"          	 dddd#dd/            ZO	 ddd1ZP ed23          	 dddd#dd9            ZQdd<ZR ed d!"          	 dddd#dd>            ZSddAZT ed d!"          ddd#ddD            ZUddFZVddGZWddIZXddLZY edMd!"          ddd#ddP            ZZ ed d!"          ddd#ddR            Z[ ed d!"          ddd#ddS            Z\ ed d!"          ddd#ddT            Z]ddXZ^ddYZ_dd\Z`dd]Zadd^Zbdd`ZcddaZdddbZeddcZfdddZgddgZhddhZiddiZj G dj dk          Zk G dl dme)          ZlddoZmddpZndddsZoddtZpdduZqdvdwdxdd~ZrdS )    )annotationsN)version)TYPE_CHECKINGAnyIterableLiteralMappingSequencecast)ExprKindExprMetadataapply_n_ary_operationcombine_metadataextract_compliantis_scalar_like)
ImplementationVersiondeprecate_native_namespaceflattenis_compliant_expris_eager_allowedis_sequence_but_not_strparse_versionsupports_arrow_c_streamvalidate_laziness)is_narwhals_seriesis_numpy_arrayis_numpy_array_2dis_pyarrow_table)InvalidOperationError
ShapeError)Expr)from_native	to_native)
ModuleType)	TypeAliasTypeIs)CompliantExprCompliantNamespace)IntoArrowTable)	DataFrame	LazyFrame)DTypeSchema)Series)ConcatMethodFrameT	IntoDTypeIntoExprIntoSeriesTNativeFrameNativeLazyFrameNativeSeriesNonNestedLiteral_1DArray_2DArray3Mapping[str, DType] | Schema | Sequence[str] | Noner&   _IntoSchemaverticalhowitemsIterable[FrameT]r@   r1   returnr2   c               ~   ddl m} | sd}t          |          t          |           } t	          |            |dvrd}t          |          | d         } ||          r|dk    rd}t          |          |                                }|                    |	                    d | D             |	                    S )
u\  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. This is only supported
                when all inputs are (eager) DataFrames.
            - diagonal: Finds a union between the column schemas and fills missing column
                values with null.

    Returns:
        A new DataFrame or LazyFrame resulting from the concatenation.

    Raises:
        TypeError: The items to concatenate should either all be eager, or all lazy

    Examples:
        Let's take an example of vertical concatenation:

        >>> import pandas as pd
        >>> import polars as pl
        >>> import pyarrow as pa
        >>> import narwhals as nw

        Let's look at one case a for vertical concatenation (pandas backed):

        >>> df_pd_1 = nw.from_native(pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
        >>> df_pd_2 = nw.from_native(pd.DataFrame({"a": [5, 2], "b": [1, 4]}))
        >>> nw.concat([df_pd_1, df_pd_2], how="vertical")
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |        a  b      |
        |     0  1  4      |
        |     1  2  5      |
        |     2  3  6      |
        |     0  5  1      |
        |     1  2  4      |
        └──────────────────┘

        Let's look at one case a for horizontal concatenation (polars backed):

        >>> df_pl_1 = nw.from_native(pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
        >>> df_pl_2 = nw.from_native(pl.DataFrame({"c": [5, 2], "d": [1, 4]}))
        >>> nw.concat([df_pl_1, df_pl_2], how="horizontal")
        ┌───────────────────────────┐
        |    Narwhals DataFrame     |
        |---------------------------|
        |shape: (3, 4)              |
        |┌─────┬─────┬──────┬──────┐|
        |│ a   ┆ b   ┆ c    ┆ d    │|
        |│ --- ┆ --- ┆ ---  ┆ ---  │|
        |│ i64 ┆ i64 ┆ i64  ┆ i64  │|
        |╞═════╪═════╪══════╪══════╡|
        |│ 1   ┆ 4   ┆ 5    ┆ 1    │|
        |│ 2   ┆ 5   ┆ 2    ┆ 4    │|
        |│ 3   ┆ 6   ┆ null ┆ null │|
        |└─────┴─────┴──────┴──────┘|
        └───────────────────────────┘

        Let's look at one case a for diagonal concatenation (pyarrow backed):

        >>> df_pa_1 = nw.from_native(pa.table({"a": [1, 2], "b": [3.5, 4.5]}))
        >>> df_pa_2 = nw.from_native(pa.table({"a": [3, 4], "z": ["x", "y"]}))
        >>> nw.concat([df_pa_1, df_pa_2], how="diagonal")
        ┌──────────────────────────┐
        |    Narwhals DataFrame    |
        |--------------------------|
        |pyarrow.Table             |
        |a: int64                  |
        |b: double                 |
        |z: string                 |
        |----                      |
        |a: [[1,2],[3,4]]          |
        |b: [[3.5,4.5],[null,null]]|
        |z: [[null,null],["x","y"]]|
        └──────────────────────────┘
    r   )is_narwhals_lazyframezNo items to concatenate.>   diagonalr>   
horizontalzDOnly vertical, horizontal and diagonal concatenations are supported.rG   zdHorizontal concatenation is not supported for LazyFrames.

Hint: you may want to use `join` instead.c                    g | ]	}|j         
S  )_compliant_frame).0dfs     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/narwhals/functions.py
<listcomp>zconcat.<locals>.<listcomp>   s    888BB'888    r?   )
narwhals.dependenciesrE   
ValueErrorlistr   NotImplementedErrorr    __narwhals_namespace___with_compliantconcat)rA   r@   rE   msg
first_itemplxs         rM   rV   rV   B   s    d <;;;;; (ooKKEe
888T!#&&&qJZ(( )SL-@-@8 	 $C(((

+
+
-
-C%%

88%888c
BB  rO   z1.31.0T)warn_versionrequired)backendnative_namespacenamestrvaluesr   dtypeIntoDType | Noner\   (ModuleType | Implementation | str | Noner]   ModuleType | NoneSeries[Any]c               H    t          d|          }t          | |||          S )u  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`.
        backend: specifies which eager backend instantiate to.

            `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.31.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 Series

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> values = [4, 1, 2, 3]
        >>> nw.new_series(name="a", values=values, dtype=nw.Int32, backend=pd)
        ┌─────────────────────┐
        |   Narwhals Series   |
        |---------------------|
        |0    4               |
        |1    1               |
        |2    2               |
        |3    3               |
        |Name: a, dtype: int32|
        └─────────────────────┘
    !ModuleType | Implementation | str)r\   )r   _new_series_impl)r^   r`   ra   r\   r]   s        rM   
new_seriesri      s,    f 6@@GD&%AAAArO   rg   c               0   t          j        |          }t          |          r[t          j        j                            |          j        }|j                            || ||          }|	                                S |t           j
        u rt|                                }	 |                    | ||          }t          |d                              |           S # t          $ r}	d}
t          |
          |	d }	~	ww xY w| d| d}
t!          |
          )N)r^   contextra   T)series_onlyzDUnknown namespace is expected to implement `new_series` constructor.z support in Narwhals is lazy-only, but `new_series` is an eager-only function.

Hint: you may want to use an eager backend and then call `.lazy`, e.g.:

    nw.new_series('a', [1,2,3], backend='pyarrow').to_frame().lazy(''))r   from_backendr   r   MAIN	namespace	compliant_seriesfrom_iterableto_narwhalsUNKNOWNto_native_namespaceri   r#   aliasAttributeErrorrQ   )r^   r`   ra   r\   implementationnsseries_native_namespacenative_serieserW   s              rM   rh   rh      s@    $099N'' -\#00@@J))&tRu)UU!!###	>1	1	1*>>@@	-*;*F*Ffe+ +M }$???EEdKKK 	- 	- 	-XC %%1,	-  	b 	bO]	b 	b 	b 
 S//s   ":C 
C>'C99C>z1.26.0)rZ   dataMapping[str, Any]schema#Mapping[str, DType] | Schema | NoneDataFrame[Any]c               T   | sd}t          |          |t          |           \  } }t          j        |          }t	          |          rXt
          j        j                            |          j        }|j	        
                    | ||                                          S |t          j        u rb|                                }	 |
                    | |          }n$# t          $ r}	d}t          |          |	d}	~	ww xY wt          |d          S | d| d	}t          |          )
u>  Instantiate DataFrame from dictionary.

    Indexes (if present, for pandas-like backends) are aligned following
    the [left-hand-rule](../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}. If not
            specified, the schema will be inferred by the native library.
        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.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>> data = {"c": [5, 2], "d": [1, 4]}
        >>> nw.from_dict(data, backend="pandas")
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |        c  d      |
        |     0  5  1      |
        |     1  2  4      |
        └──────────────────┘
    z0from_dict cannot be called with empty dictionaryN)r   rk   r   z@Unknown namespace is expected to implement `from_dict` function.T
eager_onlyz support in Narwhals is lazy-only, but `from_dict` is an eager-only function.

Hint: you may want to use an eager backend and then call `.lazy`, e.g.:

    nw.from_dict({'a': [1, 2]}, backend='pyarrow').lazy('rm   )rQ   _from_dict_no_backendr   rn   r   r   ro   rp   rq   
_dataframe	from_dictrt   ru   rv   rx   r#   
r   r   r\   r]   rW   ry   rz   r|   native_framer~   s
             rM   r   r      sZ   l  @oo-d33g#099N'' :\#00@@J}&&tFB&GGSSUUU	>1	1	1*>>@@	- ):(C(CDQW(C(X(XLL 	- 	- 	-TC %%1,	- <D9999 	Y 	YFT	Y 	Y 	Y 
 S//s   C 
C?(C::C?Mapping[str, Series[Any] | Any]/tuple[dict[str, Series[Any] | Any], ModuleType]c                   |                                  D ]'}t          |          r|                                } n(d}t          |          d |                                 D             } | |fS )NzgCalling `from_dict` without `backend` is only supported if all input values are already Narwhals Seriesc                8    i | ]\  }}|t          |d           S )T)pass_through)r$   )rK   keyvalues      rM   
<dictcomp>z)_from_dict_no_backend.<locals>.<dictcomp>[  s+    TTTeC5t444TTTrO   )r`   r   __native_namespace__	TypeErrorrA   )r   valr]   rW   s       rM   r   r   Q  s     {{}}  c"" 	"7799E	 xnnTTtzz||TTTD!!!rO   r;   c                  t          d|          }t          |           sd}t          |          t          |          s"dt	          |           d}t          |          t          j        |          }t          |          rQt          j
        j                            |          j        }|                    | |                                          S |t          j        u rb|                                }	 |                    | |          }n$# t"          $ r}	d}t#          |          |	d}	~	ww xY wt%          |d	          S | d
| d}t          |          )u  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 sequence of str.
        backend: specifies which eager backend instantiate to.

            `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.31.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.

    Examples:
        >>> import numpy as np
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> arr = np.array([[5, 2, 1], [1, 4, 3]])
        >>> schema = {"c": nw.Int16(), "d": nw.Float32(), "e": nw.Int8()}
        >>> nw.from_numpy(arr, schema=schema, backend="pyarrow")
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  pyarrow.Table   |
        |  c: int16        |
        |  d: float        |
        |  e: int8         |
        |  ----            |
        |  c: [[5,1]]      |
        |  d: [[2,4]]      |
        |  e: [[1,3]]      |
        └──────────────────┘
    rg   z)`from_numpy` only accepts 2D numpy arrayszi`schema` is expected to be one of the following types: Mapping[str, DType] | Schema | Sequence[str]. Got .r   zAUnknown namespace is expected to implement `from_numpy` function.NTr   z support in Narwhals is lazy-only, but `from_numpy` is an eager-only function.

Hint: you may want to use an eager backend and then call `.lazy`, e.g.:

    nw.from_numpy(arr, backend='pyarrow').lazy('rm   )r   r   rQ   _is_into_schematyper   r   rn   r   r   ro   rp   rq   
from_numpyrt   ru   rv   rx   r#   r   s
             rM   r   r   _  s   v 6@@GT"" 9oo6"" #<<# # # 	
 nn#099N'' :\#00@@J}}T6**66888	>1	1	1*>>@@	- ):(D(DTRX(D(Y(YLL 	- 	- 	-UC %%1,	- <D9999 	N 	N;I	N 	N 	N 
 S//s   9D 
D2D--D2objTypeIs[_IntoSchema]c                b    ddl m} | d u p%t          | t          |f          pt	          |           S )Nr   r.   )narwhals.schemar/   
isinstancer	   r   )r   r/   s     rM   r   r     sE    &&&&&& 	tYz#'899Y=TUX=Y=YrO   r   r*   c                  t          d|          }t          |           s1t          |           s"dt          |            d}t	          |          t          j        |          }t          |          rWt          j	        j
                            |          j        }|j                            | |                                          S |t
          j        u r`|                                }	 |                    |           }n$# t$          $ r}d}t%          |          |d}~ww xY wt'          |d          S | d	| d
}t)          |          )u  Construct a DataFrame from an object which supports the PyCapsule Interface.

    Arguments:
        native_frame: Object which implements `__arrow_c_stream__`.
        backend: specifies which eager backend instantiate to.

            `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.31.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.

    Examples:
        >>> import pandas as pd
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pd.DataFrame({"a": [1, 2], "b": [4.2, 5.1]})
        >>> nw.from_arrow(df_native, backend="polars")
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  shape: (2, 2)   |
        |  ┌─────┬─────┐   |
        |  │ a   ┆ b   │   |
        |  │ --- ┆ --- │   |
        |  │ i64 ┆ f64 │   |
        |  ╞═════╪═════╡   |
        |  │ 1   ┆ 4.2 │   |
        |  │ 2   ┆ 5.1 │   |
        |  └─────┴─────┘   |
        └──────────────────┘
    rg   zGiven object of type z% does not support PyCapsule interface)rk   zuUnknown namespace is expected to implement `DataFrame` class which accepts object which supports PyCapsule Interface.NTr   z support in Narwhals is lazy-only, but `from_arrow` is an eager-only function.

Hint: you may want to use an eager backend and then call `.lazy`, e.g.:

    nw.from_arrow(df, backend='pyarrow').lazy('rm   )r   r   r   r   r   r   rn   r   r   ro   rp   rq   r   
from_arrowrt   ru   rv   r+   rx   r#   rQ   )	r   r\   r]   rW   ry   rz   r|   nativer~   s	            rM   r   r     sz   f 6@@G#L11 5El5S5S _d<&8&8___nn#099N'' 4\#00@@J}''b'AAMMOOO	>1	1	1*>>@@	- #4"="=l"K"KFF 	- 	- 	- JC %%1,	- 6d3333 	M 	M:H	M 	M 	M 
 S//s   .D 
D%D  D%dict[str, str]c                     t           j                            dd          } d| fdt           j        fdt	          j                    ff}t          |          S )zSystem information.

    Returns system and Python version information

    Copied from sklearn

    Returns:
        Dictionary with system info.
    
 python
executablemachine)sysr   replacer   platformdict)r   blobs     rM   _get_sys_infor     sU     [  s++F 
6	s~&	H%''(D ::rO   c                 v    ddl m} m} ddlm} d}d|i}|D ]!}	  ||          ||<   # | $ r d||<   Y w xY w|S )a  Overview of the installed version of main dependencies.

    This function does not import the modules to collect the version numbers
    but instead relies on standard Python package metadata.

    Returns version information on relevant Python libraries

    This function and show_versions were copied from sklearn and adapted

    Returns:
        Mapping from dependency to version.
    r   )PackageNotFoundErrorr   )__version__)pandaspolarscudfmodinpyarrownumpynarwhals )importlib.metadatar   r   r   r   )r   r   r   deps	deps_infomodnames         rM   _get_deps_infor   %  s     A@@@@@@@$$$$$$DD[)I $ $	$!(!1!1Ig# 	$ 	$ 	$!#Ig	$s   )
66Nonec                 6   t                      } t                      }t          d           |                                 D ]\  }}t          |dd|            t          d           |                                D ]\  }}t          |dd|            dS )zPrint useful debugging information.

    Examples:
        >>> from narwhals import show_versions
        >>> show_versions()  # doctest: +SKIP
    z
System:z>10z: z
Python dependencies:z>13N)r   r   printrA   )sys_infor   kstats       rM   show_versionsr   A  s     H  I	+>>## " "4   $  !!!!	
"###??$$ " "4   $  !!!!" "rO   5DataFrame[Any] | LazyFrame[Any] | Series[IntoSeriesT]&Literal['full', 'lazy', 'interchange']c                    | j         S )a  Level of support Narwhals has for current object.

    Arguments:
        obj: Dataframe or Series.

    Returns:
        This can be one of

            - 'full': full Narwhals API support
            - 'lazy': only lazy operations are supported. This excludes anything
              which involves iterating over rows in Python.
            - 'interchange': only metadata operations are supported (`df.schema`)
    )_level)r   s    rM   	get_levelr   T  s      :rO   z1.27.2sourcekwargsc                  t          d|          }t          j        |          }|                                }|t          j        t          j        t          j        t          j        hv r |j        | fi |}nX|t          j	        u rddl
m}  |j        | fi |}n5	  |j        d	d| i|}n$# t          $ r}d}t          |          |d}~ww xY wt          |d          S )
u  Read a CSV file into a DataFrame.

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `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.27.2)

            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/).
        kwargs: Extra keyword arguments which are passed to the native CSV reader.
            For example, you could use
            `nw.read_csv('file.csv', backend='pandas', engine='pyarrow')`.

    Returns:
        DataFrame.

    Examples:
        >>> import narwhals as nw
        >>> nw.read_csv("file.csv", backend="pandas")  # doctest:+SKIP
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |        a   b     |
        |     0  1   4     |
        |     1  2   5     |
        └──────────────────┘
    rg   r   csvr   z?Unknown namespace is expected to implement `read_csv` function.NTr   rI   )r   r   rn   rv   POLARSPANDASMODINCUDFread_csvPYARROWr   r   rx   r#   )	r   r\   r]   r   eager_backendr   r   r~   rW   s	            rM   r   r   g  s+   X 6@@G"/88M$88::	   1'0BB6BB	.0	0	0#s|F55f55	- 5+4MMFMfMMLL 	- 	- 	-SC %%1,	- |5555s   B, ,
C6CCLazyFrame[Any]c                  t          d|          }t          j        |          }|                                }|t          j        u r |j        | fi |}ni|t          j        t          j        t          j        t          j	        t          j
        t          j        hv r |j        | fi |}n|t          j        u rddlm}  |j        | fi |}n|                                r|                    dd          x}d}t%          |          |j                            d          }	|t          j        u r5t-          t/          d                    d	k     r|	                    |           n |	j        di |                    |           }n5	  |j        dd
| i|}n$# t4          $ r}
d}t5          |          |
d}
~
ww xY wt7          |                                          S )u  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.
        backend: The eager backend for DataFrame creation.
            `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.31.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/).
        kwargs: Extra keyword arguments which are passed to the native CSV reader.
            For example, you could use
            `nw.scan_csv('file.csv', backend=pd, engine='pyarrow')`.

    Returns:
        LazyFrame.

    Examples:
        >>> import duckdb
        >>> import narwhals as nw
        >>>
        >>> nw.scan_csv("file.csv", backend="duckdb").to_native()  # doctest:+SKIP
        ┌─────────┬───────┐
        │    a    │   b   │
        │ varchar │ int32 │
        ├─────────┼───────┤
        │ x       │     1 │
        │ y       │     2 │
        │ z       │     3 │
        └─────────┴───────┘
    rg   r   r   sessionNFSpark like backends require a session object to be passed in `kwargs`.r   sqlframe      r   r   z?Unknown namespace is expected to implement `scan_csv` function.rI   )r   r   rn   rv   r   scan_csvr   r   r   DASKDUCKDBIBISr   r   r   r   is_spark_likepoprQ   readformatSQLFRAMEr   r   loadoptionsrx   r#   lazy)r   r\   r]   r   ry   r   r   r   rW   
csv_readerr~   s              rM   r   r     s(   d 6@@G#099N%99;;...0'0BB6BB	 
 
 1'0BB6BB	>1	1	1#s|F55f55		%	%	'	' -zz)T222G;ZCS//!\((//
 ."999!'*"5"566CC OOF###
 $#--f--226:: 		- 5+4MMFMfMMLL 	- 	- 	-SC %%1,	- |$$))+++   F 
F=&F88F=c                  t          d|          }t          j        |          }|                                }|t          j        t          j        t          j        t          j        t          j        t          j	        hv r |j
        | fi |}nX|t          j        u rddlm}  |j        | fi |}n5	  |j
        dd| i|}n$# t          $ r}d}t          |          |d}~ww xY wt!          |d          S )	uy  Read into a DataFrame from a parquet file.

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `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.31.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/).
        kwargs: Extra keyword arguments which are passed to the native parquet reader.
            For example, you could use
            `nw.read_parquet('file.parquet', backend=pd, engine='pyarrow')`.

    Returns:
        DataFrame.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> nw.read_parquet("file.parquet", backend="pyarrow")  # doctest:+SKIP
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |pyarrow.Table     |
        |a: int64          |
        |c: double         |
        |----              |
        |a: [[1,2]]        |
        |c: [[0.2,0.1]]    |
        └──────────────────┘
    rg   r   Nr   zCUnknown namespace is expected to implement `read_parquet` function.Tr   rI   )r   r   rn   rv   r   r   r   r   r   r   read_parquetr   pyarrow.parquetparquet
read_tablerx   r#   )	r   r\   r]   r   ry   r   pqr~   rW   s	            rM   r   r     s7   b 6@@G#099N%99;;   5'4VFFvFF	>1	1	1$$$$$$$r}V66v66	- 9+8QQQ&QQLL 	- 	- 	-WC %%1,	- |5555s   2C 
C#CC#c                  t          d|          }t          j        |          }|                                }|t          j        u r |j        | fi |}ni|t          j        t          j        t          j        t          j	        t          j
        t          j        hv r |j        | fi |}n|t          j        u rddlm}  |j        | fi |}n|                                r|                    dd          x}d}t'          |          |j                            d          }	|t          j        u r5t/          t1          d                    dk     r|	                    |           n |	j        di |                    |           }n5	  |j        dd	| i|}n$# t6          $ r}
d
}t7          |          |
d}
~
ww xY wt9          |                                          S )u
  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.

    Note:
        Spark like backends require a session object to be passed in `kwargs`.

        For instance:

        ```py
        import narwhals as nw
        from sqlframe.duckdb import DuckDBSession

        nw.scan_parquet(source, backend="sqlframe", session=DuckDBSession())
        ```

    Arguments:
        source: Path to a file.
        backend: The eager backend for DataFrame creation.
            `backend` can be specified in various ways

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

            *Deprecated* (v1.31.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/).
        kwargs: Extra keyword arguments which are passed to the native parquet reader.
            For example, you could use
            `nw.scan_parquet('file.parquet', backend=pd, engine='pyarrow')`.

    Returns:
        LazyFrame.

    Examples:
        >>> import dask.dataframe as dd
        >>> from sqlframe.duckdb import DuckDBSession
        >>> import narwhals as nw
        >>>
        >>> nw.scan_parquet("file.parquet", backend="dask").collect()  # doctest:+SKIP
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |        a   b     |
        |     0  1   4     |
        |     1  2   5     |
        └──────────────────┘
        >>> nw.scan_parquet(
        ...     "file.parquet", backend="sqlframe", session=DuckDBSession()
        ... ).collect()  # doctest:+SKIP
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  pyarrow.Table   |
        |  a: int64        |
        |  b: int64        |
        |  ----            |
        |  a: [[1,2]]      |
        |  b: [[4,5]]      |
        └──────────────────┘
    rg   r   Nr   r   r   r   r   r   zCUnknown namespace is expected to implement `scan_parquet` function.rI   )r   r   rn   rv   r   scan_parquetr   r   r   r   r   r   r   r   r   r   r   r   r   rQ   r   r   r   r   r   r   r   rx   r#   r   )r   r\   r]   r   ry   r   r   r   rW   	pq_readerr~   s              rM   r   r   X  s(   Z 6@@G#099N%99;;...4'4VFFvFF	 
 
 5'4VFFvFF	>1	1	1$$$$$$$r}V66v66		%	%	'	' -zz)T222G;ZCS//!L''	22	 ."999!'*"5"566CC NN6"""
 #",,V,,11&99 		- 9+8QQQ&QQLL 	- 	- 	-WC %%1,	- |$$))+++r   namesstr | Iterable[str]r"   c                     t          |           dfd}t          |t                    dk    rt          j                    nt          j                              S )u  Creates 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.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pl.DataFrame({"a": [1, 2], "b": [3, 4], "c": ["x", "z"]})
        >>> nw.from_native(df_native).select(nw.col("a", "b") * nw.col("b"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  shape: (2, 2)   |
        |  ┌─────┬─────┐   |
        |  │ a   ┆ b   │   |
        |  │ --- ┆ --- │   |
        |  │ i64 ┆ i64 │   |
        |  ╞═════╪═════╡   |
        |  │ 3   ┆ 9   │   |
        |  │ 8   ┆ 16  │   |
        |  └─────┴─────┘   |
        └──────────────────┘
    rY   r   rC   c                     | j          S N)col)rY   
flat_namess    rM   funczcol.<locals>.func  s    sw
##rO      rY   r   rC   r   )r   r"   lenr   selector_singleselector_multi_named)r   r   r   s     @rM   r   r     ss    : J$ $ $ $ $ $ z??a 	$&&&.00	  rO   c                     t          t          |                     dfd}t          |t          j                              S )u  Creates an expression that excludes columns by their name(s).

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

    Returns:
        A new expression.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pl.DataFrame({"a": [1, 2], "b": [3, 4], "c": ["x", "z"]})
        >>> nw.from_native(df_native).select(nw.exclude("c", "a"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  shape: (2, 1)   |
        |  ┌─────┐         |
        |  │ b   │         |
        |  │ --- │         |
        |  │ i64 │         |
        |  ╞═════╡         |
        |  │ 3   │         |
        |  │ 4   │         |
        |  └─────┘         |
        └──────────────────┘
    rY   r   rC   c                .    |                                S r   )exclude)rY   exclude_namess    rM   r   zexclude.<locals>.func  s    {{=)))rO   r  )	frozensetr   r"   r   selector_multi_unnamed)r   r   r	  s     @rM   r  r    sQ    : genn--M* * * * * * l9;;<<<rO   indicesint | Sequence[int]c                     t          |           dfd}t          |t                    dk    rt          j                    nt          j                              S )u  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.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> df_native = pa.table({"a": [1, 2], "b": [3, 4], "c": [0.123, 3.14]})
        >>> nw.from_native(df_native).select(nw.nth(0, 2) * 2)
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |pyarrow.Table     |
        |a: int64          |
        |c: double         |
        |----              |
        |a: [[2,4]]        |
        |c: [[0.246,6.28]] |
        └──────────────────┘
    rY   r   rC   c                     | j          S r   )nth)rY   flat_indicess    rM   r   znth.<locals>.funcA  s    sw%%rO   r  r  )r   r"   r  r   r  r  )r  r   r  s     @rM   r  r  !  sw    < 7##L& & & & & & |!! 	$&&&022	  rO   c                 F    t          d t          j                              S )u[  Instantiate an expression representing all columns.

    Returns:
        A new expression.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> df_native = pd.DataFrame({"a": [1, 2], "b": [3.14, 0.123]})
        >>> nw.from_native(df_native).select(nw.all() * 2)
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |      a      b    |
        |   0  2  6.280    |
        |   1  4  0.246    |
        └──────────────────┘
    c                *    |                                  S r   )allrY   s    rM   <lambda>zall_.<locals>.<lambda>a  s    CGGII rO   )r"   r   r  rI   rO   rM   all_r  M  s!    ( %%|'J'L'LMMMrO   c                 L    dd} t          | t          j                              S )u  Return the number of rows.

    Returns:
        A new expression.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pl.DataFrame({"a": [1, 2], "b": [5, None]})
        >>> nw.from_native(df_native).select(nw.len())
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  shape: (1, 1)   |
        |  ┌─────┐         |
        |  │ len │         |
        |  │ --- │         |
        |  │ u32 │         |
        |  ╞═════╡         |
        |  │ 2   │         |
        |  └─────┘         |
        └──────────────────┘
    rY   r   rC   c                *    |                                  S r   )r  r  s    rM   r   zlen_.<locals>.func  s    wwyyrO   r  )r"   r   aggregation)r   s    rM   len_r  e  s1    4    l.00111rO   columnsc                 8    t          |                                  S )u  Sum 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.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> df_native = pd.DataFrame({"a": [1, 2], "b": [-1.4, 6.2]})
        >>> nw.from_native(df_native).select(nw.sum("a", "b"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |       a    b     |
        |    0  3  4.8     |
        └──────────────────┘
    )r   sumr  s    rM   r  r        2 =rO   c                 8    t          |                                  S )u  Get 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.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> df_native = pa.table({"a": [1, 8, 3], "b": [3.14, 6.28, 42.1]})
        >>> nw.from_native(df_native).select(nw.mean("a", "b"))
        ┌─────────────────────────┐
        |   Narwhals DataFrame    |
        |-------------------------|
        |pyarrow.Table            |
        |a: double                |
        |b: double                |
        |----                     |
        |a: [[4]]                 |
        |b: [[17.173333333333336]]|
        └─────────────────────────┘
    )r   meanr  s    rM   r"  r"    s    : =rO   c                 8    t          |                                  S )u+  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.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pl.DataFrame({"a": [4, 5, 2]})
        >>> nw.from_native(df_native).select(nw.median("a"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  shape: (1, 1)   |
        |  ┌─────┐         |
        |  │ a   │         |
        |  │ --- │         |
        |  │ f64 │         |
        |  ╞═════╡         |
        |  │ 4.0 │         |
        |  └─────┘         |
        └──────────────────┘
    )r   medianr  s    rM   r$  r$    s    B =!!!rO   c                 8    t          |                                  S )u0  Return 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.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> df_native = pa.table({"a": [1, 2], "b": [5, 10]})
        >>> nw.from_native(df_native).select(nw.min("a", "b"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  pyarrow.Table   |
        |  a: int64        |
        |  b: int64        |
        |  ----            |
        |  a: [[1]]        |
        |  b: [[5]]        |
        └──────────────────┘
    )r   minr  s    rM   r&  r&    s    : =rO   c                 8    t          |                                  S )u  Return 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.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> df_native = pd.DataFrame({"a": [1, 2], "b": [5, 10]})
        >>> nw.from_native(df_native).select(nw.max("a", "b"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |        a   b     |
        |     0  2  10     |
        └──────────────────┘
    )r   maxr  s    rM   r(  r(    r   rO   exprsIntoExpr | Iterable[IntoExpr]c                     | sd}t          |          t          |           t          fdt          j                   S )u  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.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pl.DataFrame({"a": [1, 2, 3], "b": [5, 10, None]})
        >>> nw.from_native(df_native).with_columns(sum=nw.sum_horizontal("a", "b"))
        ┌────────────────────┐
        | Narwhals DataFrame |
        |--------------------|
        |shape: (3, 3)       |
        |┌─────┬──────┬─────┐|
        |│ a   ┆ b    ┆ sum │|
        |│ --- ┆ ---  ┆ --- │|
        |│ i64 ┆ i64  ┆ i64 │|
        |╞═════╪══════╪═════╡|
        |│ 1   ┆ 5    ┆ 6   │|
        |│ 2   ┆ 10   ┆ 12  │|
        |│ 3   ┆ null ┆ 3   │|
        |└─────┴──────┴─────┘|
        └────────────────────┘
    z:At least one expression must be passed to `sum_horizontal`c                0    t          | | j        gR ddiS N
str_as_litF)r   sum_horizontalrY   
flat_exprss    rM   r  z sum_horizontal.<locals>.<lambda>H  4    )#
&0
 
 
=B
 
 rO   rQ   r   r"   r   from_horizontal_opr)  rW   r1  s     @rM   r/  r/  !  ]    D  JooJ	
 	
 	
 	
 	'4	  rO   c                     | sd}t          |          t          |           t          fdt          j                   S )u  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.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> df_native = pa.table({"a": [1, 8, 3], "b": [4, 5, None]})
        >>> nw.from_native(df_native).with_columns(h_min=nw.min_horizontal("a", "b"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        | pyarrow.Table    |
        | a: int64         |
        | b: int64         |
        | h_min: int64     |
        | ----             |
        | a: [[1,8,3]]     |
        | b: [[4,5,null]]  |
        | h_min: [[1,5,3]] |
        └──────────────────┘
    z:At least one expression must be passed to `min_horizontal`c                0    t          | | j        gR ddiS r-  )r   min_horizontalr0  s    rM   r  z min_horizontal.<locals>.<lambda>t  r2  rO   r3  r5  s     @rM   r9  r9  O  s]    @  JooJ	
 	
 	
 	
 	'4	  rO   c                     | sd}t          |          t          |           t          fdt          j                   S )u	  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.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> df_native = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, None]})
        >>> nw.from_native(df_native).with_columns(h_max=nw.max_horizontal("a", "b"))
        ┌──────────────────────┐
        |  Narwhals DataFrame  |
        |----------------------|
        |shape: (3, 3)         |
        |┌─────┬──────┬───────┐|
        |│ a   ┆ b    ┆ h_max │|
        |│ --- ┆ ---  ┆ ---   │|
        |│ i64 ┆ i64  ┆ i64   │|
        |╞═════╪══════╪═══════╡|
        |│ 1   ┆ 4    ┆ 4     │|
        |│ 8   ┆ 5    ┆ 8     │|
        |│ 3   ┆ null ┆ 3     │|
        |└─────┴──────┴───────┘|
        └──────────────────────┘
    z:At least one expression must be passed to `max_horizontal`c                0    t          | | j        gR ddiS r-  )r   max_horizontalr0  s    rM   r  z max_horizontal.<locals>.<lambda>  r2  rO   r3  r5  s     @rM   r<  r<  {  r6  rO   c                      e Zd ZddZdd	Zd
S )When
predicatesr*  rC   r   c                <    t          t          |           | _        d S r   )all_horizontalr   
_predicate)selfr?  s     rM   __init__zWhen.__init__  s    ('**=*=>rO   r   &IntoExpr | NonNestedLiteral | _1DArrayThenc           
          t          j        d          } j        j        j        r|j        sd}t          |          t           fdt           j        ddd                    S )NFr.  zaIf you pass a scalar-like predicate to `nw.when`, then the `then` value must also be scalar-like.c                >     t            fdj        d          S )Nc                 l                         | d                                       | d                   S )Nr   r  )whenthen)argsrY   s    rM   r  z-When.then.<locals>.<lambda>.<locals>.<lambda>  s)    chhtAw//44T!W== rO   FrH  )r   rB  )rY   rC  r   s   `rM   r  zWhen.then.<locals>.<lambda>  s2    -====    rO   r.  allow_multi_outputto_single_output)r   from_into_exprrB  	_metadatar   r!   rF  r   )rC  r   kindrW   s   ``  rM   rL  z	When.then  s    &u????$3 	"D<O 	"=  S//!      #(!&  
 
 	
rO   N)r?  r*  rC   r   )r   rE  rC   rF  )__name__
__module____qualname__rD  rL  rI   rO   rM   r>  r>    s<        ? ? ? ?
 
 
 
 
 
rO   r>  c                      e Zd ZddZdS )rF  r   rE  rC   r"   c           
          t          j        d           j        j        r t                    sd}t	          |          d
 fd}t          |t           ddd	                    S )NFrH  zfIf you pass a scalar-like predicate to `nw.when`, then the `otherwise` value must also be scalar-like.rY   CompliantNamespace[Any, Any]rC   CompliantExpr[Any, Any]c                                         |           }t          | d          }j        j        s3t                    r$t	          |          r|                              }|                    |          S )NFrH  )_to_compliant_exprr   rR  r   r   	broadcast	otherwise)rY   compliant_exprcompliant_valuerS  rC  r   s      rM   r   zThen.otherwise.<locals>.func  s    !44S99N/UuMMMON1B"4((B &o66B
 #2";";D"A"A!++O<<<rO   rN  )rY   rY  rC   rZ  )r   rQ  rR  r   r!   r"   r   )rC  r   rW   r   rS  s   ``  @rM   r^  zThen.otherwise  s    &u???>( 	"1E1E 	"B  S//!		= 		= 		= 		= 		= 		= 		= 		=  #(!&  	
 	
 		
rO   N)r   rE  rC   r"   )rT  rU  rV  r^  rI   rO   rM   rF  rF    s(        
 
 
 
 
 
rO   rF  r?  c                     t          |  S )u  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 a
    `.otherwise(<value if condition is false>)` can be appended at the end. If not
    appended, and the condition is not `True`, `None` will be returned.

    Info:
        Chaining multiple `.when(<condition>).then(<value>)` statements is currently
        not supported.
        See [Narwhals#668](https://github.com/narwhals-dev/narwhals/issues/668).

    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.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> data = {"a": [1, 2, 3], "b": [5, 10, 15]}
        >>> df_native = pd.DataFrame(data)
        >>> nw.from_native(df_native).with_columns(
        ...     nw.when(nw.col("a") < 3).then(5).otherwise(6).alias("a_when")
        ... )
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |    a   b  a_when |
        | 0  1   5       5 |
        | 1  2  10       5 |
        | 2  3  15       6 |
        └──────────────────┘
    )r>  )r?  s    rM   rK  rK    s    N rO   c                     | sd}t          |          t          |           t          fdt          j                   S )ux  Compute 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.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> data = {
        ...     "a": [False, False, True, True, False, None],
        ...     "b": [False, True, True, None, None, None],
        ... }
        >>> df_native = pa.table(data)
        >>> nw.from_native(df_native).select("a", "b", all=nw.all_horizontal("a", "b"))
        ┌─────────────────────────────────────────┐
        |           Narwhals DataFrame            |
        |-----------------------------------------|
        |pyarrow.Table                            |
        |a: bool                                  |
        |b: bool                                  |
        |all: bool                                |
        |----                                     |
        |a: [[false,false,true,true,false,null]]  |
        |b: [[false,true,true,null,null,null]]    |
        |all: [[false,false,true,null,false,null]]|
        └─────────────────────────────────────────┘

    z:At least one expression must be passed to `all_horizontal`c                0    t          | | j        gR ddiS r-  )r   rA  r0  s    rM   r  z all_horizontal.<locals>.<lambda>:  r2  rO   r3  r5  s     @rM   rA  rA    r6  rO   r   r9   c                     t                     rd}t          |          t           t          t          f          rd  }t          |          t           fdt          j                              S )u  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 by the native library.

    Returns:
        A new expression.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> df_native = pd.DataFrame({"a": [1, 2]})
        >>> nw.from_native(df_native).with_columns(nw.lit(3))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |     a  literal   |
        |  0  1        3   |
        |  1  2        3   |
        └──────────────────┘
    zvnumpy arrays are not supported as literal values. Consider using `with_columns` to create a new column from the array.z,Nested datatypes are not supported yet. Got c                0    |                                S r   )lit)rY   ra   r   s    rM   r  zlit.<locals>.<lambda>e  s    CGGE511 rO   )	r   rQ   r   rR   tuplerS   r"   r   literal)r   ra   rW   s   `` rM   rf  rf  A  s    2 e S 	 oo%$'' 'DUDD!#&&&11111<3G3I3IJJJrO   c                     | sd}t          |          t          |           t          fdt          j                   S )u  Compute 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.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>>
        >>> data = {
        ...     "a": [False, False, True, True, False, None],
        ...     "b": [False, True, True, None, None, None],
        ... }
        >>> df_native = pl.DataFrame(data)
        >>> nw.from_native(df_native).select("a", "b", any=nw.any_horizontal("a", "b"))
        ┌─────────────────────────┐
        |   Narwhals DataFrame    |
        |-------------------------|
        |shape: (6, 3)            |
        |┌───────┬───────┬───────┐|
        |│ a     ┆ b     ┆ any   │|
        |│ ---   ┆ ---   ┆ ---   │|
        |│ bool  ┆ bool  ┆ bool  │|
        |╞═══════╪═══════╪═══════╡|
        |│ false ┆ false ┆ false │|
        |│ false ┆ true  ┆ true  │|
        |│ true  ┆ true  ┆ true  │|
        |│ true  ┆ null  ┆ true  │|
        |│ false ┆ null  ┆ null  │|
        |│ null  ┆ null  ┆ null  │|
        |└───────┴───────┴───────┘|
        └─────────────────────────┘
    z:At least one expression must be passed to `any_horizontal`c                0    t          | | j        gR ddiS r-  )r   any_horizontalr0  s    rM   r  z any_horizontal.<locals>.<lambda>  r2  rO   r3  r5  s     @rM   rk  rk  h  s]    L  JooJ	
 	
 	
 	
 	'4	  rO   c                     | sd}t          |          t          |           t          fdt          j                   S )u  Compute 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.

    Examples:
        >>> import pyarrow as pa
        >>> import narwhals as nw
        >>>
        >>> data = {"a": [1, 8, 3], "b": [4, 5, None], "c": ["x", "y", "z"]}
        >>> df_native = pa.table(data)

        We define a dataframe-agnostic function that computes the horizontal mean of "a"
        and "b" columns:

        >>> nw.from_native(df_native).select(nw.mean_horizontal("a", "b"))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        | pyarrow.Table    |
        | a: double        |
        | ----             |
        | a: [[2.5,6.5,3]] |
        └──────────────────┘
    z;At least one expression must be passed to `mean_horizontal`c                0    t          | | j        gR ddiS r-  )r   mean_horizontalr0  s    rM   r  z!mean_horizontal.<locals>.<lambda>  s4    )$
'1
 
 
>C
 
 rO   r3  r5  s     @rM   rn  rn    s\    <  KooJ	
 	
 	
 	
 	'4	  rO   r   F	separatorignore_nulls
more_exprsr4   rp  rq  boolc          
         t          g t          | g          |          t          fdt          dddd          S )up  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.

    Examples:
        >>> import pandas as pd
        >>> import narwhals as nw
        >>>
        >>> data = {
        ...     "a": [1, 2, 3],
        ...     "b": ["dogs", "cats", None],
        ...     "c": ["play", "swim", "walk"],
        ... }
        >>> df_native = pd.DataFrame(data)
        >>> (
        ...     nw.from_native(df_native).select(
        ...         nw.concat_str(
        ...             [nw.col("a") * 2, nw.col("b"), nw.col("c")], separator=" "
        ...         ).alias("full_sentence")
        ...     )
        ... )
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |   full_sentence  |
        | 0   2 dogs play  |
        | 1   4 cats swim  |
        | 2          None  |
        └──────────────────┘
    c                2     t            fdgR ddiS )Nc                       j         | dS )Nro  )
concat_str)rM  rq  rY   rp  s    rM   r  z.concat_str.<locals>.<lambda>.<locals>.<lambda>  s!    .#.   rO   r.  F)r   )rY   r1  rq  rp  s   `rM   r  zconcat_str.<locals>.<lambda>  sR    )     

 
 
 
 
 
 rO   FTrN  )r   r"   r   )r)  rp  rq  rr  r1  s    `` @rM   rw  rw    sx    ` 97E7++9j9::J	
 	
 	
 	
 	
 	
 	EdUY	
 	
 	
  rO   )rA   rB   r@   r1   rC   r2   r   )r^   r_   r`   r   ra   rb   r\   rc   r]   rd   rC   re   )
r^   r_   r`   r   ra   rb   r\   rg   rC   re   )
r   r   r   r   r\   rc   r]   rd   rC   r   )r   r   rC   r   )
r   r;   r   r<   r\   rc   r]   rd   rC   r   )r   r   rC   r   )r   r*   r\   rc   r]   rd   rC   r   )rC   r   )rC   r   )r   r   rC   r   )
r   r_   r\   rc   r]   rd   r   r   rC   r   )
r   r_   r\   rc   r]   rd   r   r   rC   r   )r   r   rC   r"   )r  r  rC   r"   )rC   r"   )r  r_   rC   r"   )r)  r*  rC   r"   )r?  r*  rC   r>  )r   r9   ra   rb   rC   r"   )
r)  r*  rr  r4   rp  r_   rq  rs  rC   r"   )s
__future__r   r   r   r   r   typingr   r   r   r   r	   r
   r   narwhals._expression_parsingr   r   r   r   r   r   narwhals._utilsr   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   narwhals.exceptionsr    r!   narwhals.exprr"   narwhals.translater#   r$   typesr%   typing_extensionsr&   r'   narwhals._compliantr(   r)   narwhals._translater*   narwhals.dataframer+   r,   narwhals.dtypesr-   r   r/   narwhals.seriesr0   narwhals.typingr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   __annotations__rV   ri   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r"  r$  r&  r(  r/  r9  r<  r>  rF  rK  rA  rf  rk  rn  rw  rI   rO   rM   <module>r     s?   " " " " " " "  



 & & & & & & Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q                                                  B A A A A A A A       5 5 5 5 5 5 5 5 S      33333333EEEEEEEE22222277777777%%%%%%&&&&&&&&&&&&                          SKRRRR <F f f f f f fR DAAA #3B
 9=*.3B 3B 3B 3B 3B BA3Br #    < 222 37M 9=*.M M M M M 32M`" " " " DAAA CGX 9=*.X X X X X BAXv    DAAA 9=*.	I I I I I BAIX   *   8" " " "&   & DAAA 9=*.	B6 B6 B6 B6 B6 BAB6J DAAA 9=*.	Z, Z, Z, Z, Z, BAZ,z DAAA 9=*.	I6 I6 I6 I6 I6 BAI6X DAAA 9=*.	v, v, v, v, v, BAv,r' ' ' 'T"= "= "= "=J( ( ( (XN N N N02 2 2 2@   8       @!" !" !" !"H   @   8+ + + +\) ) ) )X+ + + +\
 
 
 
 
 
 
 
>
 
 
 
 
4 
 
 
B' ' ' 'T+ + + +\$K $K $K $K $KN/ / / /d' ' ' 'Z 	= = = = = = = =rO   