o
    $&]i                     @  s  U d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlZd dlmZmZ d dlmZ d dlmZmZ d dl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#m$Z$ d d
l%m&Z'm(Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZK d dlLmMZMmNZNmOZO d dlPmQZR d dlSmTZU d dlVmWZWmXZXmYZY d dlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb d dlcmdZdmeZemfZf erVd dlgmhZhmiZimjZj d dlkmlZlmmZmmnZn d dlompZpmqZqmrZrmsZsmtZtmuZumvZv d dlwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~ d dl%mZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZ ededZeldZedZG dd  d e'e\ Z&G d!d" d"e)e^ Z(G d#d$ d$eUe` ZTG d%d& d&eKZJG d'd( d(eRZQedd-d.Zedd1d.Zedd4d.Zedd6d.Zdd9d.Zedd>d?ZeddAd?ZeddDd?ZeddGd?ZeddId?ZeddKd?ZeddLd?ZeddNd?ZeddQd?ZeddUd?ZeddWd?Zedd_d?Zd`d`d`ddadddd?ZededfddidjZededfddkdjZededfddldjZeddmdjZd`dfddodjZ	ddpd`d`dpdaddtduZddvdwZddzd{Zdd|d}ZdddZdddZddddZdddZdddZdddZdddZdddZdddZdddZdddZdddZdddZdddZdd`dd ddZdddZdddZG dd dejZG dd dejeJZdddZ	ddddZdddĄZ	dddŜddd̄Ze&jZded< 	dddd҄ZdddքZd	ddڄZddd܄Zd	ddބZg dߢZdS (
      )annotationswraps)TYPE_CHECKINGAnyCallableFinalLiteralcastoverloadN)
exceptions	functions)issue_warning)ExprKindExprNode)TypeVarassert_never)ImplementationVersiongenerate_temporary_column_nameinherit_docis_ordered_categoricalmaybe_align_indexmaybe_convert_dtypesmaybe_get_indexmaybe_reset_indexmaybe_set_indexnot_implemented)	DataFrame	LazyFrame)ArrayBinaryBooleanCategoricalDateDatetimeDecimalDurationEnumFieldFloat32Float64Int8Int16Int32Int64Int128ListObjectStringStructTimeUInt8UInt16UInt32UInt64UInt128Unknown)NarwhalsUnstableWarning)Expr)_new_series_implconcatshow_versions)Schema)Series)dependenciesdtypes	selectors)
DataFrameTIntoDataFrameT	IntoFrameIntoLazyFrameT
IntoSeriesIntoSeriesT
LazyFrameTSeriesT)_from_native_implget_native_namespaceto_py_scalar)IterableMappingSequence)	ParamSpecSelfUnpack)AllowAny	AllowLazyAllowSeriesExcludeSeriesIntoArrowTable
OnlySeriesPassThroughUnknown)ArrowBackendEagerAllowedIntoBackendLazyAllowedPandasPolars)MultiColSelectorMultiIndexSelector)DType)		IntoDTypeIntoExpr
IntoSchemaNonNestedLiteralPythonLiteralSingleColSelectorSingleIndexSelector_1DArray_2DArrayT)defaultPRc                      sf  e Zd ZejZeedQ fddZe	dR fddZ
e		dSdddT fddZe		dSdU fddZe		dSdV fddZedWd!d"ZedXd$d%ZedYd(d)ZedZd,d)Zed[d/d)Zd\ fd2d)Zd] fd5d6Z	dSdd7d^ fd<d=Zed>d?d_dCdDZed`dGdDZedHd?dadKdDZdHd?da fdLdDZdb fdMdNZdb fdOdPZ  ZS )cr   dfr   level&Literal['full', 'lazy', 'interchange']returnNonec                  $   |j tju sJ t j||d d S N)rv   _versionr   V2super__init__selfru   rv   	__class__ Y/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/narwhals/stable/v2/__init__.pyr   v      zDataFrame.__init__native_framer[   backendIntoBackend[EagerAllowed]DataFrame[Any]c                  s   t  j||d}td|S Nr   r   )r   
from_arrowr
   )clsr   r   resultr   r   r   r   ~   s   
zDataFrame.from_arrowNr   dataMapping[str, Any]schema.IntoSchema | Mapping[str, DType | None] | None IntoBackend[EagerAllowed] | Nonec                     t  j|||d}td|S r   )r   	from_dictr
   r   r   r   r   r   r   r   r   r         
zDataFrame.from_dictSequence[Mapping[str, Any]]c                  r   r   )r   
from_dictsr
   r   r   r   r   r      r   zDataFrame.from_dictsrp   3Mapping[str, DType] | Schema | Sequence[str] | Nonec                  r   r   r   
from_numpyr
   r   r   r   r   r      r   zDataFrame.from_numpytype[Series[Any]]c                 C  
   t dtS )Nr   )r
   rB   r   r   r   r   _series      
zDataFrame._seriestype[LazyFrame[Any]]c                 C  r   )Nr   )r
   r   r   r   r   r   
_lazyframe   r   zDataFrame._lazyframeitem-tuple[SingleIndexSelector, SingleColSelector]c                 C     d S Nr   r   r   r   r   r   __getitem__      zDataFrame.__getitem__2str | tuple[MultiIndexSelector, SingleColSelector]Series[Any]c                 C  r   r   r   r   r   r   r   r         SingleIndexSelector | MultiIndexSelector | MultiColSelector | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, MultiColSelector]rU   c                 C  r   r   r   r   r   r   r   r      s   
  SingleIndexSelector | SingleColSelector | MultiColSelector | MultiIndexSelector | tuple[SingleIndexSelector, SingleColSelector] | tuple[SingleIndexSelector, MultiColSelector] | tuple[MultiIndexSelector, SingleColSelector] | tuple[MultiIndexSelector, MultiColSelector]Series[Any] | Self | Anyc                      t  |S r   )r   r   r   r   r   r   r      s   namestrc                   r   r   )r   
get_column)r   r   r   r   r   r      s   zDataFrame.get_column)sessionIntoBackend[LazyAllowed] | Noner   
Any | NoneLazyFrame[Any]c                  s   t t j||dS )N)r   r   )
_stableifyr   lazy)r   r   r   r   r   r   r      s   zDataFrame.lazy.	as_seriesr   Literal[True]dict[str, Series[Any]]c                C  r   r   r   r   r   r   r   r   to_dict   r   zDataFrame.to_dictLiteral[False]dict[str, list[Any]]c                C  r   r   r   r   r   r   r   r      r   Tbool-dict[str, Series[Any]] | dict[str, list[Any]]c                C  r   r   r   r   r   r   r   r      r   c                  s   t  j|dS )Nr   )r   r   r   r   r   r   r      s   c                      t t  S r   )r   r   is_duplicatedr   r   r   r   r         zDataFrame.is_duplicatedc                   r   r   )r   r   	is_uniquer   r   r   r   r      r   zDataFrame.is_uniqueru   r   rv   rw   rx   ry   r   r[   r   r   rx   r   r   )r   r   r   r   r   r   rx   r   )r   r   r   r   r   r   rx   r   r   rp   r   r   r   r   rx   r   )rx   r   )rx   r   )r   r   rx   r   )r   r   rx   r   )r   r   rx   rU   )r   r   rx   r   )r   r   rx   r   )r   r   r   r   rx   r   )r   r   rx   r   )r   r   rx   r   )r   r   rx   r   )rx   r   )__name__
__module____qualname__r   r~   r}   r   NwDataFramer   classmethodr   r   r   r   propertyr   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r   s   sX    



r   c                      sF   e Zd Zeed fddZedd
dZ	dd fddZ  Z	S )r   ru   r   rv   rw   rx   ry   c                  rz   r{   r|   r   r   r   r   r      r   zLazyFrame.__init__type[DataFrame[Any]]c                 C     t S r   r   r   r   r   r   
_dataframe      zLazyFrame._dataframeNr   +IntoBackend[Polars | Pandas | Arrow] | Nonekwargsr   c                   s   t t jdd|i|S )Nr   r   )r   r   collect)r   r   r   r   r   r   r      s   zLazyFrame.collectr   rx   r   r   )r   r   r   r   rx   r   )
r   r   r   r   NwLazyFramer   r   r   r   r   r   r   r   r   r      s    r   c                      s   e Zd ZU ejZeed- fddZe	d.d
dZ
e	d/d0 fddZe	d/d1 fddZd2 fddZdddddd3 fd%d&Ze Zded'< dd(d4 fd+d,Z  ZS )5rB   seriesr   rv   rw   rx   ry   c                  rz   r{   r|   )r   r   rv   r   r   r   r     s   zSeries.__init__r   c                 C  r   r   r   r   r   r   r   r     r   zSeries._dataframeNr   r   valuesro   dtypeIntoDType | Noner   r   r   c                     t  j||||d}td|S Nr   r   r   r   r   r   r   r   r   r   r   r   r        	
zSeries.from_numpyIterable[Any]c                  r   r   )r   from_iterabler
   r   r   r   r   r      r   zSeries.from_iterabler   c                   r   r   )r   r   to_framer   r   r   r   r   ,  r   zSeries.to_frameFsortparallelr   	normalizer   r   r   
str | Noner   c                  s   t t j||||dS )Nr   )r   r   value_counts)r   r   r   r   r   r   r   r   r   /  s
   zSeries.value_countshistignore_nullsr   rl   c                  s   d}t |t t j|dS )Nz_`Series.any_value` is being called from the stable API although considered an unstable feature.r   )r   r<   r   	any_valuer   r   msgr   r   r   r   @  s   
zSeries.any_value)r   r   rv   rw   rx   ry   r   r   )
r   r   r   ro   r   r   r   r   rx   r   )
r   r   r   r   r   r   r   r   rx   r   )rx   r   )
r   r   r   r   r   r   r   r   rx   r   )r   r   rx   rl   )r   r   r   r   r~   r}   r   NwSeriesr   r   r   r   r   r   r   r   r   r   __annotations__r   r   r   r   r   r   rB     s(   
 	rB   c                   @  s   e Zd Zddd
ddZd	S )r=   Fr   r   r   rx   rU   c                C  s$   d}t |t | ttjd|dS )Nz]`Expr.any_value` is being called from the stable API although considered an unstable feature.r   r   )r   r<   _append_noder   r   AGGREGATIONr   r   r   r   r   J  s   
zExpr.any_valueN)r   r   rx   rU   )r   r   r   r   r   r   r   r   r=   I  s    r=   c                      s0   e Zd ZejZee	dd	 fddZ  Z	S )
rA   Nr   8Mapping[str, DType] | Iterable[tuple[str, DType]] | Nonerx   ry   c                   s   t  | d S r   )r   r   )r   r   r   r   r   r   X  s   zSchema.__init__r   )r   r   rx   ry   )
r   r   r   r   r~   r}   r   NwSchemar   r   r   r   r   r   rA   U  s
    rA   objNwDataFrame[IntoDataFrameT]rx   DataFrame[IntoDataFrameT]c                 C  r   r   r   r   r   r   r   r   _  r   r   NwLazyFrame[IntoLazyFrameT]LazyFrame[IntoLazyFrameT]c                 C  r   r   r   r   r   r   r   r   a  r   NwSeries[IntoSeriesT]Series[IntoSeriesT]c                 C  r   r   r   r   r   r   r   r   c  r   NwExprc                 C  r   r   r   r   r   r   r   r   e  r   ZNwDataFrame[IntoDataFrameT] | NwLazyFrame[IntoLazyFrameT] | NwSeries[IntoSeriesT] | NwExprRDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT] | Exprc                 C  s   t | trt| jtj| jdS t | tr"t	| jtj| jdS t | t
r3t| jtj| jdS t | tr=t| j S t|  d S r{   )
isinstancer   r   _compliant_frame_with_versionr   r~   _levelr   r   r   rB   _compliant_seriesr  r=   _nodesr   r   r   r   r   r   i  s   




native_objectrM   kwdsUnpack[OnlySeries]c                 K  r   r   r   r  r  r   r   r   from_nativez  r   r  Unpack[AllowSeries]c                 K  r   r   r   r  r   r   r   r  |  r   rF   Unpack[ExcludeSeries]c                 K  r   r   r   r  r   r   r   r  ~  r   rL   Unpack[AllowLazy]c                 K  r   r   r   r  r   r   r   r    r   rG   c                 K  r   r   r   r  r   r   r   r    r   rK   c                 K  r   r   r   r  r   r   r   r    r   c                 K  r   r   r   r  r   r   r   r    r   rI   c                 K  r   r   r   r  r   r   r   r    r   IntoDataFrameT | IntoSeriesT/DataFrame[IntoDataFrameT] | Series[IntoSeriesT]c                 K  r   r   r   r  r   r   r   r    r   -IntoDataFrameT | IntoLazyFrameT | IntoSeriesTUnpack[AllowAny]KDataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT]c                 K  r   r   r   r  r   r   r   r    r   Unpack[PassThroughUnknown]c                 K  r   r   r   r  r   r   r   r    r   r   pass_throughr   
eager_onlyseries_onlyallow_seriesbool | Nonec                C  r   r   r   r  r  r  r  r  r   r   r   r    s   Fr  r  r  r  JIntoLazyFrameT | IntoDataFrameT | IntoSeriesT | IntoFrame | IntoSeries | TOLazyFrame[IntoLazyFrameT] | DataFrame[IntoDataFrameT] | Series[IntoSeriesT] | Tc             	   C  sD   t | ttfr|s| S t | tr|s|r| S t| ||||dtjdS )a  Convert `native_object` to Narwhals Dataframe, Lazyframe, or Series.

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

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

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

            - `False` (default): don't require `native_object` to be eager
            - `True`: only convert to Narwhals if `native_object` is eager
        series_only: Whether to only allow Series

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

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

    Returns:
        DataFrame, LazyFrame, Series, or original object, depending
            on which combination of parameters was passed.
    F)r  r  r  r  eager_or_interchange_onlyversion)r  r   r   rB   rN   r   r~   r   r   r   r   r    s   ,.r  narwhals_objectr   c                C  r   r   r   r'  r  r   r   r   	to_native  r   r)  c                C  r   r   r   r(  r   r   r   r)    r   c                C  r   r   r   r(  r   r   r   r)    r   c                C  r   r   r   r(  r   r   r   r)    r   3IntoDataFrameT | IntoLazyFrameT | IntoSeriesT | Anyc                C  s   t j| |dS )a]  Convert Narwhals object to native one.

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

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

    Returns:
        Object of class that user started with.
    r&  )nwr)  r(  r   r   r   r)    s   TfuncCallable[..., Any] | NoneCallable[..., Any]c                  s(   d fdd}| du r|S || S )a  Decorate function so it becomes dataframe-agnostic.

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

    Arguments:
        func: Function to wrap in a `from_native`-`to_native` block.
        pass_through: Determine what happens if the object can't be converted to Narwhals

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

            - `False` (default): don't require `native_object` to be eager
            - `True`: only convert to Narwhals if `native_object` is eager
        series_only: Whether to only allow Series

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

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

    Returns:
        Decorated function.
    r,  r.  rx   c                   s"   t  d fdd}|S )Nargsr   r   rx   c                    s   fdd| D } fdd|  D } fddg | | R D }| dkr6d}t|| i |}t|d	S )
Nc              	     s   g | ]}t | d qS r!  r  ).0argr  r  r  r  r   r   
<listcomp>7  s    zBnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>c              
     s$   i | ]\}}|t | d qS r0  r1  )r2  r   valuer4  r   r   
<dictcomp>B  s    zBnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<dictcomp>c                   s"   h | ]}t |d d  r  qS )__native_namespace__N)getattr)r2  vbr   r   	<setcomp>M  s    zAnarwhalify.<locals>.decorator.<locals>.wrapper.<locals>.<setcomp>   z_Found multiple backends. Make sure that all dataframe/series inputs come from the same backend.r&  )itemsr   __len__
ValueErrorr)  )r/  r   backendsr   r   )r  r  r,  r  r  r;  r   wrapper5  s   
z.narwhalify.<locals>.decorator.<locals>.wrapper)r/  r   r   r   rx   r   r   )r,  rC  r4  )r,  r   	decorator4  s   %znarwhalify.<locals>.decoratorN)r,  r.  rx   r.  r   )r,  r  r  r  r  rD  r   r4  r   
narwhalify  s   ))rE  c                   C     t t S )z3Instantiate an expression representing all columns.)r   r+  allr   r   r   r   rG  c     rG  namesstr | Iterable[str]c                  G     t tj|  S )zCreates an expression that references one or more columns by their name(s).

    Arguments:
        names: Name(s) of the columns to use.
    )r   r+  colrI  r   r   r   rL  h     rL  c                  G  rK  )zCreates an expression that excludes columns by their name(s).

    Arguments:
        names: Name(s) of the columns to exclude.
    )r   r+  excluderM  r   r   r   rO  q  rN  rO  indicesint | Sequence[int]c                  G  rK  )a!  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.
    )r   r+  nth)rP  r   r   r   rR  z     
rR  c                   C  rF  )zReturn the number of rows.)r   r+  lenr   r   r   r   rT    rH  rT  r6  rk   r   r   c                 C  s   t t| |S )zReturn 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.
    )r   r+  lit)r6  r   r   r   r   rU    s   rU  columnsr   c                  G  rK  )zReturn the minimum value.

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

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function.
    )r   r+  minrV  r   r   r   rW       	rW  c                  G  rK  )zReturn the maximum value.

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

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function.
    )r   r+  maxrX  r   r   r   rZ    rY  rZ  c                  G  rK  )zGet the mean value.

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

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function
    )r   r+  meanrX  r   r   r   r[    rY  r[  c                  G  rK  )aL  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
    )r   r+  medianrX  r   r   r   r\    s   r\  c                  G  rK  )zSum all values.

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

    Arguments:
        columns: Name(s) of the columns to use in the aggregation function
    )r   r+  sumrX  r   r   r   r]    rY  r]  exprsIntoExpr | Iterable[IntoExpr]c                  G  rK  )a
  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.
    )r   r+  sum_horizontalr^  r   r   r   r`    rS  r`  r   c                 G     t tj|d| iS )a  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.
    r   )r   r+  all_horizontalr   r^  r   r   r   rc       rc  c                 G  rb  )a  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.
    r   )r   r+  any_horizontalrd  r   r   r   rf    re  rf  c                  G  rK  )zCompute the mean of all values horizontally across columns.

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r+  mean_horizontalra  r   r   r   rg    s   rg  c                  G  rK  )a  Get the minimum value horizontally across columns.

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

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r+  min_horizontalra  r   r   r   rh    rS  rh  c                  G  rK  )a  Get the maximum value horizontally across columns.

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

    Arguments:
        exprs: Name(s) of the columns to use in the aggregation function. Accepts
            expression input.
    )r   r+  max_horizontalra  r   r   r   ri    rS  ri   	separatorr   
more_exprsri   rl  c                G  s   t tj| g|R ||dS )a  Horizontally concatenate columns into a single string column.

    Arguments:
        exprs: Columns to concatenate into a single string column. Accepts expression
            input. Strings are parsed as column names, other non-expression inputs are
            parsed as literals. Non-`String` columns are cast to `String`.
        *more_exprs: Additional columns to concatenate into a single string column,
            specified as positional arguments.
        separator: String that will be used to separate the values of each column.
        ignore_nulls: Ignore null values (default is `False`).
            If set to `False`, null values will be propagated and if the row contains any
            null values, the output is null.
    rk  )r   r+  
concat_str)r^  rl  r   rm  r   r   r   rn  &  s   rn  f_stringr/  c                 G     t tj| g|R  S )zFormat expressions as a string.

    Arguments:
        f_string: A string that with placeholders.
        args: Expression(s) that fill the placeholders.
    )r   r+  format)ro  r/  r   r   r   rq  >  s   rq  c                 G  rp  )a  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.
    )r   r+  coalesce)r^  rm  r   r   r   rr  H  s   rr  c                      ,   e Zd ZedddZd fd	d
Z  ZS )Whenwhen	nw_f.Whenrx   c                 C  s
   | |j S r   )
_predicate)r   ru  r   r   r   	from_whenY  r   zWhen.from_whenr6  &IntoExpr | NonNestedLiteral | _1DArrayThenc                   s   t t |S r   )rz  	from_thenr   thenr   r6  r   r   r   r|  ]  s   z	When.then)ru  rv  rx   rt  )r6  ry  rx   rz  )r   r   r   r   rx  r|  r   r   r   r   r   rt  X      rt  c                      rs  )rz  r|  	nw_f.Thenrx   c                 C  s
   | |j  S r   )r  )r   r|  r   r   r   r{  b  r   zThen.from_thenr6  ry  r=   c                   s   t t |S r   )r   r   	otherwiser}  r   r   r   r  f  s   zThen.otherwise)r|  r  rx   rz  )r6  ry  rx   r=   )r   r   r   r   r{  r  r   r   r   r   r   rz  a  r~  rz  
predicatesc                  G  s   t tj|  S )a  Start a `when-then-otherwise` expression.

    Expression similar to an `if-else` statement in Python. Always initiated by a
    `pl.when(<condition>).then(<value if condition>)`, and optionally followed by 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.
    )rt  rx  nw_fru  )r  r   r   r   ru  j  s   ru  r   r   r   r   r   c                C  s   t t| |||dS )a  Instantiate Narwhals Series from iterable (e.g. list or array).

    Arguments:
        name: Name of resulting Series.
        values: Values of make Series from.
        dtype: (Narwhals) dtype. If not provided, the native library
            may auto-infer it from `values`.
        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`.
    r   )r   r>   )r   r   r   r   r   r   r   
new_series  s   r  r   r[   r   c                C  s   t tj| |dS )aL  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`.
    r   )r   r  r   )r   r   r   r   r   r     s   r   r   r   r   r   #Mapping[str, DType] | Schema | Noner   c                C     t tj| ||dS )aX  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. If
            any `dtype` is `None`, the data type for that column 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`.
    r   )r   r  r   r   r   r   r   r   r   r     s   r   r   r   rp   r   c                C  r  )a.  Construct a DataFrame from a NumPy ndarray.

    Notes:
        Only row orientation is currently supported.

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

    Arguments:
        data: Two-dimensional data represented as a NumPy ndarray.
        schema: The DataFrame schema as Schema, dict of {name: type}, or a 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`.
    r   )r   r  r   r  r   r   r   r     s   r   sourcer   c                K     t tj| fd|i|S )a  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')`.
    r   )r   r  read_csvr  r   r   r   r   r   r       r  IntoBackend[Backend]r   c                K  r  )aR  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')`.
    r   )r   r  scan_csvr  r   r   r   r    s   r  c                K  r  )a  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')`.
    r   )r   r  read_parquetr  r   r   r   r    r  r  c                K  r  )a  Lazily read from a parquet file.

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

    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')`.
    r   )r   r  scan_parquetr  r   r   r   r  3  s   #r  )Tr    r!   r"   r#   r   r$   r%   r&   r'   r(   r=   r)   r*   r+   r   r,   r-   r.   r/   r0   r   r1   r2   rA   rB   r3   r4   r5   r6   r7   r8   r9   r:   r;   rG  rc  rf  rr  rL  r?   rn  rC   rD   rD   r   rO  rq  r   r   r   r  r   r   rO   r   rT  rU  rZ  ri  r   r   r   r   r   r[  rg  r\  rW  rh  rE  r  rR  r  r  r  r  rE   rE   r@   r]  r`  r)  rP   ru  )r   r   rx   r   )r   r   rx   r  )r   r  rx   r  )r   r  rx   r=   )r   r  rx   r  )r  rM   r  r  rx   rM   )r  rM   r  r  rx   rM   )r  rF   r  r  rx   rF   )r  rL   r  r  rx   rL   )r  rG   r  r  rx   r   )r  rK   r  r  rx   r  )r  rK   r  r  rx   r  )r  rI   r  r  rx   r  )r  r  r  r  rx   r  )r  r  r  r  rx   r  )r  rq   r  r  rx   rq   )r  r   r  r   r  r   r  r   r  r  rx   r   )r  r"  r  r   r  r   r  r   r  r  rx   r#  )r'  r   r  r   rx   rG   )r'  r  r  r   rx   rI   )r'  r  r  r   rx   rK   )r'  r   r  r   rx   r   )r'  r  r  r   rx   r*  r   )r,  r-  r  r   r  r   r  r   r  r  rx   r.  )rx   r=   )rI  rJ  rx   r=   )rP  rQ  rx   r=   )r6  rk   r   r   rx   r=   )rV  r   rx   r=   )r^  r_  rx   r=   )r^  r_  r   r   rx   r=   )
r^  r_  rm  ri   rl  r   r   r   rx   r=   )ro  r   r/  ri   rx   r=   )r^  r_  rm  ri   rx   r=   )r  r_  rx   rt  )
r   r   r   r   r   r   r   r   rx   r   r   )r   r   r   r  r   r   rx   r   r   )r  r   r   r   r   r   rx   r   )r  r   r   r  r   r   rx   r   )
__future__r   	functoolsr   typingr   r   r   r   r	   r
   r   narwhalsr+  r   r   r  narwhals._exceptionsr   narwhals._expression_parsingr   r   narwhals._typing_compatr   r   narwhals._utilsr   r   r   r   r   r   r   r   r   r   r   narwhals.dataframer   r   r   r   narwhals.dtypesr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   narwhals.exceptionsr<   narwhals.exprr=   r  narwhals.functionsr>   r?   r@   narwhals.schemarA   r   narwhals.seriesrB   r   narwhals.stable.v2rC   rD   rE   narwhals.stable.v2.typingrF   rG   rH   rI   rJ   rK   rL   rM   narwhals.translaterN   rO   rP   collections.abcrQ   rR   rS   typing_extensionsrT   rU   rV   narwhals._translaterW   rX   rY   rZ   r[   r\   r]   narwhals._typingr^   r_   r`   ra   rb   rc   rd   re   rf   narwhals.stable.v2.dtypesrg   narwhals.typingrh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rs   rt   r   r  r)  rE  rG  rL  rO  rR  rT  rU  rW  rZ  r[  r\  r]  r`  rc  rf  rg  rh  ri  rn  rq  rr  rt  rz  ru  r  r   r   r   r   r   r  r  r  r  __all__r   r   r   r   <module>   s   $4x(
$$		, F

<
X

	
	













		"&