L i@FUddlmZddlmZmZmZmZddlmZddl m Z m Z m Z m Z mZmZddlmZmZmZmZmZmZmZmZmZmZddlmZmZmZmZm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/dd l0m1Z1e rdd l2m3Z3dd l4m5Z5dd l6m7Z7dd l8Z9dd l:Z;dd lm?Z?m@Z@ddlAmBZBmCZCddlDmEZEddlFmGZGddlmHZHddlImJZJmKZKddl$mLZLmMZMddlNmOZOddlPmQZQddl0mRZRddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZae Zbdecd<gdZdedZedZfdecd<edZgGd d!e'egeege e!e eege!fZhGd"d#ed$ed%eeie ffed&eeheee!fe eeee!fZjGd'd(eheee!fe eee!fZkGd)d*ejeeed+fekedd+fe%e eeeefZly ),) annotations)IteratorMappingSequenceSized)chain) TYPE_CHECKINGAnyLiteralProtocolTypeVaroverload) CompliantDataFrameAnyCompliantExprT_contraCompliantLazyFrameAnyCompliantNamespaceAnyCompliantSeriesT EagerExprT EagerSeriesTNativeDataFrameTNativeLazyFrameT NativeSeriesT)ArrowConvertibleDictConvertible FromNativeNumpyConvertible ToNarwhalsToNarwhalsT_co) assert_never) ValidateBackendVersionVersion _StoresNativecheck_columns_existis_compliant_seriesis_index_selectoris_rangeis_sequence_likeis_sized_multi_index_selectoris_slice_index is_slice_none)MultiOutputExpressionError)BytesIO)Path) ModuleTypeN)Self TypeAlias)CompliantGroupByDataFrameGroupBy)EagerNamespace) SparkSession)IntoArrowTable)_EagerAllowedImpl_LazyAllowedImpl)Implementation_LimitedContext) DataFrame)DType)ColumnNotFoundError)AsofJoinStrategy IntoSchema JoinStrategyMultiColSelectorMultiIndexSelectorPivotAggSingleIndexSelectorSizedMultiIndexSelectorSizedMultiNameSelectorSizeUnitUniqueKeepStrategy_2DArray _SliceIndex _SliceNamer0 Incomplete)CompliantDataFrameCompliantFrameCompliantLazyFrameEagerDataFrameT2dict[str, CompliantSeriesT] | dict[str, list[Any]]_ToDict _NativeFrameTceZdZUdZded<ded<ded<d"dZd#d Zd$d Zd%d Ze d&d Z e d'd Z e d(dZ e d)dZd)dZd*dZd+dZd,dZd-dZ d.dZd/dZ d0dZ d1dZd2dZd3dZd4dZ d5dZ d6dZ d7dZd3dZd8d Zy!)9rMz)Common parts of `DataFrame`, `LazyFrame`.rS _native_framer8_implementationr!_versioncyNselfs c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/narwhals/_compliant/dataframe.py__native_namespace__z#CompliantFrame.__native_namespace__fcyrYrZr[s r]__narwhals_namespace__z%CompliantFrame.__narwhals_namespace__gr_r`cyrYrZ)r\dfs r] _with_nativezCompliantFrame._with_nativehr_r`cyrYrZ)r\versions r] _with_versionzCompliantFrame._with_versionir_r`cyrYrZclsdatacontexts r] from_nativezCompliantFrame.from_nativejWZr`cyrYrZr[s r]columnszCompliantFrame.columnsl(+r`c|jSrY)rUr[s r]nativezCompliantFrame.nativens!!!r`cyrYrZr[s r]schemazCompliantFrame.schemars-0r`cyrYrZr[s r]collect_schemazCompliantFrame.collect_schemaur_r`cyrYrZ)r\rqstricts r]dropzCompliantFrame.dropvr_r`cyrYrZr\subsets r] drop_nullszCompliantFrame.drop_nullswr_r`cyrYrZr\rqs r]explodezCompliantFrame.explodexr_r`cyrYrZ)r\ predicates r]filterzCompliantFrame.filteryr_r`cyrYrZr\keysdrop_null_keyss r]group_byzCompliantFrame.group_byzs 9@ $9GK $!  '    $     GMr`rMc*eZdZd%dZed&dZe d'dZe d(dZe d)dZd*dZ d+dZ e d,dZ d%d Z d-d Zd.d Zd/d Z d0d Zd1dZd2dZ d3dZd4dZ d5dZ d6dZd7dZ d8dZ d9dZd:dZd;dZddZ d?dZdd d@dZ dAd Z!edBd!Z"edCd"Z"dDd#Z"dCd$Z#y)ErLcyrYrZr[s r]__narwhals_dataframe__z)CompliantDataFrame.__narwhals_dataframe__r_r`cyrYrZrjs r] from_arrowzCompliantDataFrame.from_arrowror`cyrYrZrkrlrmrvs r] from_dictzCompliantDataFrame.from_dictrr`cyrYrZrs r] from_dictszCompliantDataFrame.from_dictsrr`cyrYrZrs r] from_numpyzCompliantDataFrame.from_numpyrr`cyrYrZ)r\dtypecopys r] __array__zCompliantDataFrame.__array__r_r`cyrYrZ)r\items r] __getitem__zCompliantDataFrame.__getitem__rr`cyrYrZr[s r]shapezCompliantDataFrame.shaperrr`cyrYrZr[s r]clonezCompliantDataFrame.cloner_r`cyrYrZ)r\units r]estimated_sizez!CompliantDataFrame.estimated_sizer_r`cyrYrZ)r\roffsets r] gather_everyzCompliantDataFrame.gather_everyr_r`cyrYrZ)r\rs r] get_columnzCompliantDataFrame.get_columnr_r`cyrYrZrs r]rzCompliantDataFrame.group_bys '*r`cyrYrZ)r\rowcolumns r]rzCompliantDataFrame.itemr_r`cyrYrZr[s r] iter_columnszCompliantDataFrame.iter_columnsr_r`cyrYrZ)r\named buffer_sizes r] iter_rowszCompliantDataFrame.iter_rowsBEr`cyrYrZr[s r] is_uniquezCompliantDataFrame.is_uniquer_r`cyrYrZ)r\backendsessions r]lazyzCompliantDataFrame.lazy #r`cyrYrZ)r\rrvaluesaggregate_function sort_columns separators r]pivotzCompliantDataFrame.pivotsr`cyrYrZ)r\rs r]rzCompliantDataFrame.rowr_r`cyrYrZ)r\rs r]rowszCompliantDataFrame.rowsrr`cyrYrZ)r\rfractionwith_replacementseeds r]samplezCompliantDataFrame.sampler`cyrYrZr[s r]to_arrowzCompliantDataFrame.to_arrow r_r`cyrYrZr[s r] to_pandaszCompliantDataFrame.to_pandas r_r`cyrYrZr[s r] to_polarszCompliantDataFrame.to_polars r_r`cyrYrZr\ as_seriess r]to_dictzCompliantDataFrame.to_dict sSVr`cyrYrZrs r]rzCompliantDataFrame.to_dictsMPr`cyrYrZrs r]rzCompliantDataFrame.to_dicts=@r`N)maintain_ordercyrYrZ)r\r~rrrs r]rzCompliantDataFrame.uniquer r`cyrYrZrs r]rz!CompliantDataFrame.with_row_indexr_r`cyrYrZr\files r] write_csvzCompliantDataFrame.write_csvs,/r`cyrYrZrs r]rzCompliantDataFrame.write_csvs=@r`cyrYrZrs r]rzCompliantDataFrame.write_csv!r_r`cyrYrZrs r] write_parquetz CompliantDataFrame.write_parquet"r_r`rr/)rlr5rmr9rr/)rlzMapping[str, Any]rmrrv.IntoSchema | Mapping[str, DType | None] | Nonerr/)rlzSequence[Mapping[str, Any]]rmr9rvr$rr/)rlrHrmr9rvz!IntoSchema | Sequence[str] | Nonerr/)rr r bool | NonerrH)rzetuple[SingleIndexSelector | MultiIndexSelector[CompliantSeriesT], MultiColSelector[CompliantSeriesT]]rr/)rztuple[int, int])rrFrz int | float)rrrrrr/)rrrr)rrrrrzDataFrameGroupBy[Self, Any])r int | Nonerzint | str | Nonerr )rzIterator[CompliantSeriesT])rrrrrz7Iterator[tuple[Any, ...]] | Iterator[Mapping[str, Any]])rr)rz_LazyAllowedImpl | NonerzSparkSession | Nonerr)rrrrrrrzPivotAgg | Nonerrrrrr/)rrrztuple[Any, ...])rrrz7Sequence[tuple[Any, ...]] | Sequence[Mapping[str, Any]]) rr&rz float | Nonerrr r&rr/)rpa.Table)rz pd.DataFrame)rz pl.DataFrame)rz Literal[True]rzdict[str, CompliantSeriesT])rzLiteral[False]rzdict[str, list[Any]])rrrrQ) r~rrrGrr%rrrr/)rrrrrr/)rNonerrrzstr | Path | BytesIOrr()rzstr | Path | BytesIO | Nonerz str | None)$rrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrr"rZr`r]rLrLs2ZZ '  ?  ) !  ?   !  2  K   ++ @<<*=* * % * J=FF+.F @F1$.$$ $Dr`rNceZdZeddZ ddZddZddZdd ddZddZ dd Z dd Z dd Z d d Z e d!d Zd"dZd#dZ d$dZ d%dZd&dZd'dZ d(dZd)dZy)*rOc6|jjSrY)rV_backend_versionr[s r]r8zEagerDataFrame._backend_versionAs##4466r`cyrYrZr[s r]rbz%EagerDataFrame.__narwhals_namespace__Es r`c<|jj|dS)Nfull)level)rW dataframer[s r] to_narwhalszEagerDataFrame.to_narwhalsKs}}&&t6&::r`c |j|SrY)rrs r]r0zEagerDataFrame.aggregateNst{{E""r`T)validate_column_namescyrYrZ)r\rdr@s r]rezEagerDataFrame._with_nativeXrr`c0t||jS)N) available)r#rqr}s r]_check_columns_existz#EagerDataFrame._check_columns_exist\s"6T\\BBr`cd|j|}t|dk7r d}t||dS)z6Evaluate `expr` and ensure it has a **single** output.z4multi-output expressions not allowed in this contextr)_evaluate_exprlenr+)r\exprresultmsgs r]_evaluate_single_output_exprz+EagerDataFrame._evaluate_single_output_expr_s: $$T* v;! HC,S1 1ayr`cRttjfd|DS)Nc3@K|]}j|ywrY)rG).0rIr\s r] z1EagerDataFrame._evaluate_exprs..ns(Ut)<).sL!'! LsrF)rVranger)rlrqs r]_numpy_column_namesz"EagerDataFrame._numpy_column_namess'GLLuTZZ]7KLMMr`cyrYrZr\rs r]_gatherzEagerDataFrame._gatherr_r`cyrYrZrds r] _gather_slicezEagerDataFrame._gather_slicer_r`cyrYrZrs r]_select_multi_indexz"EagerDataFrame._select_multi_indexrr`cyrYrZrs r]_select_multi_namez!EagerDataFrame._select_multi_namerr`cyrYrZrs r]_select_slice_indexz"EagerDataFrame._select_slice_indexr_r`cyrYrZrs r]_select_slice_namez!EagerDataFrame._select_slice_namer_r`c|\}}|}t|s t|trt|dk(r|j St |rat |s t|r|j|}nt|r|j|j}n|j|}nqt|tr|j|}nOt|r|j|j}n(t|r|j|}n t!|t|st|t"r|j%|g}|St|tt&fr|j)|}|St|r|j%|j}|St+|r|j%|}|St!||S)Nr)r* isinstancerrHrr%r)r&rmr$rirtslicerorkr'rrrerargr()r\rrrq compliants r]rzEagerDataFrame.__getitem__s g W%'5)c'la.? '')) )!'*hw.? ) = =g FI(1 $ 8 8 HI ) = =g FIGU+%88A $W- 33GNNC !'* 33G< W%T"$$%--tf5 D5%.1%33D9 %T*%--dkk:  /t4%--d3 T"r`c$|j|SrY)r"rs r]r5zEagerDataFrame.sink_parquets!!$''r`N)rztuple[int, ...])rzOEagerNamespace[Self, EagerSeriesT, EagerExprT, NativeDataFrameT, NativeSeriesT])rDataFrame[NativeDataFrameT])rrrr/)rdrr@rrr/)r~rrzColumnNotFoundError | None)rIrrr)rrrSequence[EagerSeriesT])rIrrrv)rrrr )rlrHrqrrz list[str])r&SizedMultiIndexSelector[NativeSeriesT]rr/)r_SliceIndex | rangerr/)rqrwrr/)rqz%SizedMultiNameSelector[NativeSeriesT]rr/)rqrxrr/)rqrJrr/)rz]tuple[SingleIndexSelector | MultiIndexSelector[EagerSeriesT], MultiColSelector[EagerSeriesT]]rr/r))rrrrr8rbr>r0rerDrLrSrGr\ staticmethodrbrergrirkrmrorr5rZr`r]rOrO9s77   ;#FJ">B C W & NN!5N NN QC= < MB( (  (T(r`rOru)m __future__rcollections.abcrrrr itertoolsrtypingr r r r r rnarwhals._compliant.typingrrrrrrrrrrnarwhals._translaterrrrrrnarwhals._typing_compatrnarwhals._utilsr r!r"r#r$r%r&r'r(r)r*narwhals.exceptionsr+ior,pathlibr-typesr.pandaspdpolarsplpyarrowpatyping_extensionsr/r0narwhals._compliant.group_byr1r2narwhals._compliant.namespacer3narwhals._spark_like.utilsr4r5narwhals._typingr6r7r8r9narwhals.dataframer:narwhals.dtypesr;r<narwhals.typingr=r>r?r@rArBrCrDrErFrGrHrIrJrKr__all__rPrRrSrMrrLrNrOrZr`r]rs">>KK   1    ; 1O<72D?,%7" J  Z CLII( SN- }~ "M> AB SNlrE+,/c1BBC12 (*:NJK 46F VW rEjD(*:NJK "$4n DED(I(j"24QQz<1NNO \:'7 FG I(r`