
    Wh{                       U d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZmZmZmZ d dlmZmZmZmZmZ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% d d
l&m'Z' d dl(m)Z) d dl*m+Z+m,Z, erQd dl-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8m9Z9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJ dZKdeLd<   dddGdZM	 dH	 	 	 	 	 	 	 	 	 dIdZN	 dH	 	 	 	 	 	 	 	 	 dIdZO ed      	 dHddd	 	 	 	 	 	 	 	 	 dJd       ZP	 	 	 	 dKd ZQ	 dH	 	 	 	 	 	 	 dLd!ZRdMd"ZS	 	 	 	 	 	 dNd#ZTdOd$ZUdOd%ZVdPd&ZW	 	 	 	 	 	 	 	 dQd'ZX	 	 	 	 	 	 	 	 dRd(ZY	 	 	 	 	 	 	 	 dQd)ZZ	 	 	 	 	 	 	 	 dRd*Z[dSd+Z\dSd,Z]dTd-Z^dUd.Z_dUd/Z`dVd0ZadVd1ZbdVd2ZcdVd3ZddVd4Ze	 	 	 	 	 	 	 	 dWd5ZfdXd6ZgdXd7ZhdXd8Zi G d9 d:      Zj G d; d<e'      ZkdYd=ZldZd>ZmdHd[d?ZndZd@ZodXdAZpdBdCdD	 	 	 	 	 	 	 	 	 d\dEZq	 	 	 	 	 	 d]dFZry)^    )annotationsN)IterableMappingSequence)partial)TYPE_CHECKINGAnyCallable)ExprKindExprMetadataapply_n_ary_operationcombine_metadatais_scalar_like)
ImplementationVersiondeprecate_native_namespaceflattenis_compliant_expris_eager_allowedis_sequence_but_not_strnormalize_pathsupports_arrow_c_streamvalidate_laziness)is_narwhals_seriesis_numpy_arrayis_numpy_array_2dis_pyarrow_table)InvalidOperationError)Expr)Series)from_native	to_native)
ModuleType)	TypeAliasTypeIs)CompliantExprCompliantNamespace)IntoArrowTable)BackendEagerAllowedIntoBackend)	DataFrame	LazyFrame)ConcatMethod
FileSourceFrameT	IntoDTypeIntoExpr
IntoSchemaNativeDataFrameNativeLazyFrameNativeSeriesNonNestedLiteral_1DArray_2DArray!IntoSchema | Sequence[str] | Noner$   _IntoSchemaverticalhowc               V   ddl m} | sd}t        |      t        |       } t	        |        |dvrd}t        |      | d   } ||      r|dk(  rd}t        |      |j                         }|j                  |j                  | D cg c]  }|j                   c}|            S c c}w )	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.rB   zdHorizontal concatenation is not supported for LazyFrames.

Hint: you may want to use `join` instead.r=   )narwhals.dependenciesr@   
ValueErrorlistr   NotImplementedErrorr   __narwhals_namespace___with_compliantconcat_compliant_frame)itemsr>   r@   msg
first_itemplxdfs          L/var/www/html/jupyter_env/lib/python3.12/site-packages/narwhals/functions.pyrI   rI   B   s    d <(oKEe
88T!#&&qJZ(SL-@8 	 $C((

+
+
-C%%

%8BB''8c
B 8s   B&c                    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`.

    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|
        └─────────────────────┘
    )backend)_new_series_impl)namevaluesdtyperR   s       rP   
new_seriesrW      s    T D&%AA    c                  t        j                  |      }t        |      rbt        j                  j
                  j                  |      j                  }|j                  j                  || ||      }|j                         S |t         j                  u r@|j                         }	 |j                  | ||      }t        |d      j                  |       S | d| d}
t!        |
      # t        $ r}	d}
t        |
      |	d }	~	ww xY w)N)rT   contextrV   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_namespacerW   r!   aliasAttributeErrorrD   )rT   rU   rV   rR   implementationnsseries_native_namespacenative_serieserL   s              rP   rS   rS      s    $009N'\\##00@JJ))&tRu)U!!##///*>>@	-*;*F*Ffe+M }$?EEdKK
 
 OO]N^^`	b 
 S/  	-XC %1,	-s   &.C( (	D1C??Dz1.26.0)warn_version)rR   native_namespacec               
   |t        |       \  } }t        j                  |      }t        |      r_t        j
                  j                  j                  |      j                  }|j                  j                  | ||      j                         S |t        j                  u r1|j                         }	 |j                  | |      }t        |d      S | d| d}	t        |	      # t        $ r}d}	t        |	      |d}~ww xY w)	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: deprecated, same as `backend`.

    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      |
        └──────────────────┘
    N)schemarZ   rq   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('r\   )_from_dict_no_backendr   r]   r   r   r^   r_   r`   
_dataframe	from_dictrc   rd   re   rg   r!   rD   )
datarq   rR   ro   rh   ri   rk   native_framerm   rL   s
             rP   rw   rw      s   ` -d3g#009N'\\##00@JJ}}&&tFB&GSSUU///*>>@	- ->,G,GV -H -L <D99
 FFTEUUW	Y 
 S/  	-TC %1,	-s   3C& &	D/C==Dc          	         | j                         D ]  }t        |      s|j                         } n d}t        |      | j	                         D ci c]  \  }}|t        |d       } }}| |fS c c}}w )NzgCalling `from_dict` without `backend` is only supported if all input values are already Narwhals SeriesT)pass_through)rU   r   __native_namespace__	TypeErrorrK   r"   )rx   valro   rL   keyvalues         rP   ru   ru   @  s     {{} c""779
 xnGKzz|TeC5t44TDT!!! Us   A2c               L   t        |       sd}t        |      t        |      sdt        |       d}t	        |      t        j                  |      }t        |      rSt        j                  j                  j                  |      j                  }|j                  | |      j                         S |t
        j                  u r1|j                         }	 |j                  | |      }t#        |d      S | d	| d
}t        |      # t         $ r}d}t!        |      |d}~ww xY w)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`.

    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]]      |
        └──────────────────┘
    z)`from_numpy` only accepts 2D numpy arrayszW`schema` is expected to be one of the following types: IntoSchema | Sequence[str]. Got .rr   zAUnknown namespace is expected to implement `from_numpy` function.NTrs   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('r\   )r   rD   _is_into_schematyper}   r   r]   r   r   r^   r_   r`   
from_numpyrc   rd   re   rg   r!   )	rx   rq   rR   rL   rh   ri   rk   ry   rm   s	            rP   r   r   N  s8   d T"9o6"<.# 	
 n#009N'\\##00@JJ}}T6*6688///*>>@	- ->,H,HV -I -L <D99
 ;;I:J"	N 
 S/  	-UC %1,	-s   D 	D#DD#c                X    ddl m} | d u xs t        | t        |f      xs t	        |       S )Nr   )Schema)narwhals.schemar   
isinstancer   r   )objr   s     rP   r   r     s0    & 	tYz#'89Y=TUX=YrX   c               D   t        |       s%t        |       sdt        |        d}t        |      t	        j
                  |      }t        |      r^t        j                  j                  j                  |      j                  }|j                  j                  | |      j                         S |t        j                  u r/|j                         }	 |j!                  |       }t%        |d      S | d| d	}t'        |      # t"        $ r}d}t#        |      |d}~ww xY w)
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`.

    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 │   |
        |  └─────┴─────┘   |
        └──────────────────┘
    zGiven object of type z% does not support PyCapsule interface)rZ   zuUnknown namespace is expected to implement `DataFrame` class which accepts object which supports PyCapsule Interface.NTrs   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('r\   )r   r   r   r}   r   r]   r   r   r^   r_   r`   rv   
from_arrowrc   rd   re   r,   rg   r!   rD   )ry   rR   rL   rh   ri   rk   nativerm   s           rP   r   r     s#   P $L15El5S%d<&8%99^_n#009N'\\##00@JJ}}''b'AMMOO///*>>@	- '8&A&A,&OF 6d33
 ::H9I	M 
 S/  	- JC %1,	-s   D 	DDDc                     t         j                  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)sysversionreplacer   platformdict)r   blobs     rP   _get_sys_infor     sT     [[  s+F 
6	s~~&	H%%'(D :rX   c                 `  	 ddl m}  d}t        j                  }ddh	t	        	fdg ||D              }t
        j                  |d      } |        D ]W  }|j                  j                         |j                  }}||v r|||<   3|D ]   }||   r	|j                  |      s|||<    W Y |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   )distributions)narwhalsnumpyPYSPARK_CONNECTrd   c              3  H   K   | ]  }|vs|j                           y wN)lower).0rT   excludes     rP   	<genexpr>z!_get_deps_info.<locals>.<genexpr>  s#      $gBU

s   	"" )importlib.metadatar   r   _member_names_tupler   fromkeysrT   r   r   
startswith)
r   extra_namesmember_namestarget_namesresultdist	dist_namedist_versiontargetr   s
            @rP   _get_deps_infor      s     1'K!00L ),G !>;!>!> L ]]<,F 	"&))//"3T\\<	 ,F9& f~)*>*>v*F%1F6N	 MrX   c                     t               } t               }t        d       | j                         D ]  \  }}t        |dd|         t        d       |j                         D ]  \  }}t        |dd|         y)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   printrK   )sys_info	deps_infokstats       rP   show_versionsr   %  s     H I	+>># "43r$ !" 

"#??$ "43r$ !"rX   c                  t        j                  |      }|j                         }|t         j                  t         j                  t         j
                  t         j                  hv r |j                  t        |       fi |}n|t         j                  u rddl
m}  |j                  | fi |}n|t         j                  t         j                  t         j                  t         j                  t         j                   t         j"                  hv rd| d|  d| d}t%        |      	  |j                  dd| i|}t)        |d
      S # t&        $ r}d}t'        |      |d	}~ww xY w)uq  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`.
        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     |
        └──────────────────┘
    r   csvExpected eager backend, found z .

Hint: use nw.scan_csv(source=
, backend=)sourcez?Unknown namespace is expected to implement `read_csv` function.NTrs    )r   r]   re   POLARSPANDASMODINCUDFread_csvr   PYARROWpyarrowr   PYSPARKDASKDUCKDBIBISSQLFRAMEr   rD   rg   r!   )	r   rR   kwargsimplro   ry   r   rL   rm   s	            rP   r   r   8  sd   @ &&w/D//1	  1'001GR6R	''	'#s||F5f5	&& 
 -TF 3,,28:gYaI 	 o	- 5+44MFMfML |55  	-SC %1,	-s   %E 	E"EE"c                  t        j                  |      }|j                         }t        |       } |t         j                  u r |j
                  | fi |}nW|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|j!                         r|j#                  dd      x}d}t%        |      |j&                  j)                  d      }	|t         j*                  u r$|j-                         dk  r|	j/                  |       n  |	j0                  d
i |j/                  |       }n	  |j
                  d
d| i|}t5        |      j7                         S # t2        $ r}
d	}t3        |      |
d}
~
ww xY w)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`.
        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 │
        └─────────┴───────┘
    r   r   sessionNFSpark like backends require a session object to be passed in `kwargs`.r         r   r   z?Unknown namespace is expected to implement `scan_csv` function.r   )r   r]   re   r   r   scan_csvr   r   r   r   r   r   r   r   r   r   is_spark_likepoprD   readformatr   _backend_versionloadoptionsrg   r!   lazy)r   rR   r   rh   ro   ry   r   r   rL   
csv_readerrm   s              rP   r   r   ~  s   L $009N%99;F#F...0'00B6B	 
 1'00B6B	>11	1#s||F5f5		%	%	'zz)T22G;ZCS/!\\((/
 ."9"99"335
B OOF#
 $##-f-226: 		- 5+44MFMfML |$))++  	-SC %1,	-   G 	G$GG$c                  t        j                  |      }|j                         }|t         j                  t         j                  t         j
                  t         j                  hv rt        |       }  |j                  | fi |}n|t         j                  u rddl
m}  |j                  | fi |}n|t         j                  t         j                  t         j                  t         j                   t         j"                  t         j$                  hv rd| d|  d| d}t'        |      	  |j                  dd| i|}t+        |d	
      S # t(        $ r}d}t)        |      |d}~ww xY w)u  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`.
        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]]    |
        └──────────────────┘
    r   Nr   z$.

Hint: use nw.scan_parquet(source=r   r   r   zCUnknown namespace is expected to implement `read_parquet` function.Trs   r   )r   r]   re   r   r   r   r   r   read_parquetr   pyarrow.parquetparquet
read_tabler   r   r   r   r   r   rD   rg   r!   )	r   rR   r   r   ro   ry   pqrL   rm   s	            rP   r   r     si   J &&w/D//1	   '4'44VFvF	''	'$$r}}V6v6	&& 
 -TF 3006xz'!M 	 o	- 9+88QQ&QL |55  	-WC %1,	-s   'E 	E$EE$c                  t        j                  |      }|j                         }t        |       } |t         j                  u r |j
                  | fi |}nW|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|j#                         r|j%                  dd      x}d}t'        |      |j(                  j+                  d      }	|t         j,                  u r$|j/                         dk  r|	j1                  |       n  |	j2                  d	i |j1                  |       }n	  |j
                  d	d| i|}t7        |      j9                         S # t4        $ r}
d}t5        |      |
d}
~
ww xY w)
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`.
        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]]      |
        └──────────────────┘
    r   Nr   r   r   r   r   zCUnknown namespace is expected to implement `scan_parquet` function.r   )r   r]   re   r   r   scan_parquetr   r   r   r   r   r   r   r   r   r   r   r   r   rD   r   r   r   r   r   r   rg   r!   r   )r   rR   r   rh   ro   ry   r   r   rL   	pq_readerrm   s              rP   r   r     s   B $009N%99;F#F...4'44VFvF	 
 5'44VFvF	>11	1$$r}}V6v6		%	%	'zz)T22G;ZCS/!LL''	2	 ."9"99"335
B NN6"
 #"",V,11&9 		- 9+88QQ&QL |$))++  	-WC %1,	-r   c                     t        |       dfd}t        |t              dk(  rt        j                               S 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  │   |
        |  └─────┴─────┘   |
        └──────────────────┘
    c                "     | j                    S r   )col)rN   
flat_namess    rP   funczcol.<locals>.func  s    sww
##rX      rN   r	   returnr	   )r   r   lenr   selector_singleselector_multi_named)namesr   r   s     @rP   r   r     sW    : J$ z?a 	$$&  ..0	 rX   c                 t    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   │         |
        |  └─────┘         |
        └──────────────────┘
    c                &    | j                        S r   )r   )rN   exclude_namess    rP   r   zexclude.<locals>.func  s    {{=))rX   r   )	frozensetr   r   r   selector_multi_unnamed)r   r   r   s     @rP   r   r     s0    : gen-M* l99;<<rX   c                     t        |       dfd}t        |t              dk(  rt        j                               S 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]] |
        └──────────────────┘
    c                "     | j                    S r   )nth)rN   flat_indicess    rP   r   znth.<locals>.func  s    sww%%rX   r   r   )r   r   r   r   r   r   )indicesr   r   s     @rP   r   r     sY    < 7#L& |! 	$$&  002	 rX   c                 @    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                "    | j                         S r   )allrN   s    rP   <lambda>zall_.<locals>.<lambda>  s    CGGI rX   )r   r   r   r   rX   rP   all_r    s    ( %|'J'J'LMMrX   c                 F    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   │         |
        |  └─────┘         |
        └──────────────────┘
    c                "    | j                         S r   )r   r  s    rP   r   zlen_.<locals>.func5  s    wwyrX   r   )r   r   aggregation)r   s    rP   len_r    s    4 l..011rX   c                 .    t        |  j                         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columnss    rP   r  r  ;      2 =rX   c                 .    t        |  j                         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    rP   r  r  W  s    : =rX   c                 .    t        |  j                         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    rP   r  r  w  s    B =!!rX   c                 .    t        |  j                         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    rP   r  r    s    : =rX   c                 .    t        |  j                         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    rP   r  r    r  rX   c                l    sd|  d}t        |      t        fdt        j                         S )Nz+At least one expression must be passed to ``c                0    t        |  |       gddiS )N
str_as_litFr   )rN   exprsoperation_factorys    rP   r  z%_expr_with_n_ary_op.<locals>.<lambda>  s(    )"3'
*/
<A
 rX   )rD   r   r   from_horizontal_op)	func_namer  r  rL   s    `` rP   _expr_with_n_ary_opr"    sB     ;I;aHo	
 	''/	 rX   c                 0    t        dd gt        |        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   │|
        |└─────┴──────┴─────┘|
        └────────────────────┘
    sum_horizontalc                    | j                   S r   )r$  r  s    rP   r  z sum_horizontal.<locals>.<lambda>      c&8&8 rX   r"  r   r  s    rP   r$  r$    $    D 8;B5> rX   c                 0    t        dd gt        |        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]] |
        └──────────────────┘
    min_horizontalc                    | j                   S r   )r+  r  s    rP   r  z min_horizontal.<locals>.<lambda>1  r&  rX   r'  r(  s    rP   r+  r+    s$    @ 8;B5> rX   c                 0    t        dd gt        |        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     │|
        |└─────┴──────┴───────┘|
        └──────────────────────┘
    max_horizontalc                    | j                   S r   )r.  r  s    rP   r  z max_horizontal.<locals>.<lambda>X  r&  rX   r'  r(  s    rP   r.  r.  5  r)  rX   c                      e Zd ZddZddZy)Whenc                6    t        t        |      ddi| _        y )Nignore_nullsF)all_horizontalr   
_predicate)self
predicatess     rP   __init__zWhen.__init__]  s    ('**=RERrX   c           
          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                 P    j                  | d         j                  | d         S )Nr   r   )whenthenargsrN   s    rP   r  z-When.then.<locals>.<lambda>.<locals>.<lambda>l  s#    chhtAw/44T!W= rX   Fr:  )r   r5  )rN   r6  r   s   `rP   r  zWhen.then.<locals>.<lambda>j  s     -=  rX   r  allow_multi_outputto_single_output)r   from_into_exprr5  	_metadatar   r   Thenr   )r6  r   kindrL   s   ``  rP   r>  z	When.then`  sv    &&u???$$33D<O<O=  (,,  #(!&
 	
rX   N)r7  IntoExpr | Iterable[IntoExpr]r   None)r   &IntoExpr | NonNestedLiteral | _1DArrayr   rF  )__name__
__module____qualname__r8  r>  r   rX   rP   r1  r1  \  s    S
rX   r1  c                      e Zd ZddZy)rF  c           
          t        j                  d       j                  j                  rt              sd}t	        |      d fd}t        |t         ddd            S )NFr:  zfIf you pass a scalar-like predicate to `nw.when`, then the `otherwise` value must also be scalar-like.c                    j                  |       }| j                  d      }j                  j                  s't              rt	        |      r|j                        }|j                  |      S )NFr:  )_to_compliant_exprparse_into_exprrE  r   r   	broadcast	otherwise)rN   compliant_exprcompliant_valuerG  r6  r   s      rP   r   zThen.otherwise.<locals>.func  sf    !44S9N!11%E1JONN11"4(%o6"1";";D"A!++O<<rX   rA  )rN   zCompliantNamespace[Any, Any]r   zCompliantExpr[Any, Any])r   rD  rE  r   r   r   r   )r6  r   rL   r   rG  s   ``  @rP   rT  zThen.otherwise|  so    &&u?>>((1EB  (,,		=  #(!&	
 		
rX   N)r   rJ  r   r   )rK  rL  rM  rT  r   rX   rP   rF  rF  {  s    
rX   rF  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 |
        └──────────────────┘
    )r1  )r7  s    rP   r=  r=    s    N rX   c                6     t        d fdgt        |       S )u  Compute the bitwise AND horizontally across columns.

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

            - If `True`, null values are ignored. If there are no elements, the result
              is `True`.
            - If `False`, Kleene logic is followed. Note that this is not allowed for
              pandas with classical NumPy dtypes when null values are present.

    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", ignore_nulls=False)
        ... )
        ┌─────────────────────────────────────────┐
        |           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]]|
        └─────────────────────────────────────────┘

    r4  c                2    t        | j                        S N)r3  )r   r4  rN   r3  s    rP   r  z all_horizontal.<locals>.<lambda>      GC..\J rX   r'  r3  r  s   ` rP   r4  r4    s'    T J 
 rX   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                (    | j                        S r   )lit)rN   rV   r   s    rP   r  zlit.<locals>.<lambda>  s    CGGE51 rX   )	r   rD   r   rE   r   rF   r   r   literal)r   rV   rL   s   `` rP   r`  r`    s`    2 eS 	 o%$'<UGD!#&&1<3G3G3IJJrX   c                6     t        d fdgt        |       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.
        ignore_nulls: Whether to ignore nulls:

            - If `True`, null values are ignored. If there are no elements, the result
              is `False`.
            - If `False`, Kleene logic is followed. Note that this is not allowed for
              pandas with classical NumPy dtypes when null values are present.

    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", ignore_nulls=False)
        ... )
        ┌─────────────────────────┐
        |   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  │|
        |└───────┴───────┴───────┘|
        └─────────────────────────┘
    any_horizontalc                2    t        | j                        S rZ  )r   rc  r[  s    rP   r  z any_horizontal.<locals>.<lambda>N  r\  rX   r'  r]  s   ` rP   rc  rc    s'    \ J 
 rX   c                 0    t        dd gt        |        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]] |
        └──────────────────┘
    mean_horizontalc                    | j                   S r   )rf  r  s    rP   r  z!mean_horizontal.<locals>.<lambda>r  s    s':': rX   r'  r(  s    rP   rf  rf  S  s#    < :=DU^ rX   r   F	separatorr3  c               Z    t        g t        | g      |      }t        dfdg| 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  |
        └──────────────────┘
    
concat_strc                      fdS )Nc                 *     j                   | dS )Nrh  )rk  )r@  r3  rN   ri  s    rP   r  z.concat_str.<locals>.<lambda>.<locals>.<lambda>  s    .#..Y\#
 rX   r   )rN   r3  ri  s   `rP   r  zconcat_str.<locals>.<lambda>  s
     
 rX   )r   r"  )r  ri  r3  
more_exprs
flat_exprss    ``  rP   rk  rk  v  sA    ` 97E7+9j9:J	

 
 rX   c                N   t        g t        | g      |      D cg c]   }t        |t        t        t        f      r|" }}|r;dt        dt        dt        ddj                  d |D               }t        |      t        fdt        j                         S c c}w )u8  Folds the columns from left to right, keeping the first non-null value.

    Arguments:
        exprs: Columns to coalesce, must be a str, nw.Expr, or nw.Series
            where strings are parsed as column names and both nw.Expr/nw.Series
            are passed through as-is. Scalar values must be wrapped in `nw.lit`.

        *more_exprs: Additional columns to coalesce, specified as positional arguments.

    Raises:
        TypeError: If any of the inputs are not a str, nw.Expr, or nw.Series.

    Returns:
        A new expression.

    Examples:
        >>> import polars as pl
        >>> import narwhals as nw
        >>> data = [
        ...     (1, 5, None),
        ...     (None, 6, None),
        ...     (None, None, 9),
        ...     (4, 8, 10),
        ...     (None, None, None),
        ... ]
        >>> df = pl.DataFrame(data, schema=["a", "b", "c"], orient="row")
        >>> nw.from_native(df).select(nw.coalesce("a", "b", "c", nw.lit(-1)))
        ┌──────────────────┐
        |Narwhals DataFrame|
        |------------------|
        |  shape: (5, 1)   |
        |  ┌─────┐         |
        |  │ a   │         |
        |  │ --- │         |
        |  │ i64 │         |
        |  ╞═════╡         |
        |  │ 1   │         |
        |  │ 6   │         |
        |  │ 9   │         |
        |  │ 4   │         |
        |  │ -1  │         |
        |  └─────┘         |
        └──────────────────┘
    z,All arguments to `coalesce` must be of type z, z, or z9.
Got the following invalid arguments (type, value):
    c              3  H   K   | ]  }t        t        |      |f        y wr   )reprr   )r   rm   s     rP   r   zcoalesce.<locals>.<genexpr>  s     EatT!WaL1Es    "c                ,     t          fdgddiS )Nc                 "     j                   |  S r   )coalescer?  s    rP   r  z,coalesce.<locals>.<lambda>.<locals>.<lambda>  s    |s||T2 rX   r  Fr  )rN   ro  s   `rP   r  zcoalesce.<locals>.<lambda>  s#    )2
5?
LQ
 rX   )	r   r   strr   r    joinr}   r   r   )r  rn  expr	non_exprsrL   ro  s        @rP   ru  ru    s    ^ 97E7+9j9:J",Z$Jtc4QWEX4YZIZ:3'D85QWPZ [YYE9EEFH 	
 n	
 	''4	  [s    B" B")rK   zIterable[FrameT]r>   r.   r   r0   r   )
rT   rv  rU   r	   rV   IntoDType | NonerR   IntoBackend[EagerAllowed]r   zSeries[Any])
rx   zMapping[str, Any]rq   zIntoSchema | NonerR   z IntoBackend[EagerAllowed] | Nonero   zModuleType | Noner   DataFrame[Any])rx   zMapping[str, Series[Any] | Any]r   z/tuple[dict[str, Series[Any] | Any], ModuleType])rx   r9   rq   r:   rR   r{  r   r|  )r   r	   r   zTypeIs[_IntoSchema])ry   r(   rR   r{  r   r|  )r   zdict[str, str])r   rI  )r   r/   rR   r{  r   r	   r   r|  )r   r/   rR   zIntoBackend[Backend]r   r	   r   zLazyFrame[Any])r   zstr | Iterable[str]r   r   )r  zint | Sequence[int]r   r   )r   r   )r  rv  r   r   )r!  rv  r  zPCallable[[CompliantNamespace[Any, Any]], Callable[..., CompliantExpr[Any, Any]]]r  r2   r   r   )r  rH  r   r   )r7  rH  r   r1  )r  rH  r3  boolr   r   )r   r7   rV   rz  r   r   )
r  rH  rn  r2   ri  rv  r3  r}  r   r   )r  rH  rn  zIntoExpr | NonNestedLiteralr   r   )s
__future__r   r   r   collections.abcr   r   r   	functoolsr   typingr   r	   r
   narwhals._expression_parsingr   r   r   r   r   narwhals._utilsr   r   r   r   r   r   r   r   r   r   rC   r   r   r   r   narwhals.exceptionsr   narwhals.exprr   narwhals.seriesr    narwhals.translater!   r"   typesr#   typing_extensionsr$   r%   narwhals._compliantr&   r'   narwhals._translater(   narwhals._typingr)   r*   r+   narwhals.dataframer,   r-   narwhals.typingr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r;   __annotations__rI   rW   rS   rw   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r"  r$  r+  r.  r1  rF  r=  r4  r`  rc  rf  rk  ru  r   rX   rP   <module>r     s   "  
 7 7  / /     6  " 5 3E2CC7    AK@ <F fX #*B
*B*B *B
 '*B *B` #
 
 ' < 2 !%F 15*.F
FF .	F
 (F F 3FR"
)"4"  15Q
Q-Q '	Q
 Qh> >.G>>B*"J"&C6C6$=C6ILC6C6LN,N,$8N,DGN,N,bI6I6$=I6ILI6I6Xj,j,$8j,DGj,j,Z'T"=J(XN02@8 @!"H@8
  
$$N"J$N
 
>
4 
B'T.b$KN2j L 	7(77 7 	7
 
7t?(?7R?	?rX   