| 
12 | 12 | from typing import TypeVar  | 
13 | 13 | from typing import overload  | 
14 | 14 | 
 
  | 
 | 15 | +from narwhals._compliant.typing import CompliantDataFrameAny  | 
15 | 16 | from narwhals._compliant.typing import CompliantExprT_contra  | 
 | 17 | +from narwhals._compliant.typing import CompliantLazyFrameAny  | 
16 | 18 | from narwhals._compliant.typing import CompliantSeriesT  | 
17 | 19 | from narwhals._compliant.typing import EagerExprT  | 
18 | 20 | from narwhals._compliant.typing import EagerSeriesT  | 
 | 
22 | 24 | from narwhals._translate import DictConvertible  | 
23 | 25 | from narwhals._translate import FromNative  | 
24 | 26 | from narwhals._translate import NumpyConvertible  | 
 | 27 | +from narwhals._translate import ToNarwhals  | 
 | 28 | +from narwhals._translate import ToNarwhalsT_co  | 
25 | 29 | from narwhals.utils import Version  | 
26 | 30 | from narwhals.utils import _StoresNative  | 
27 | 31 | from narwhals.utils import deprecated  | 
 | 
47 | 51 |     from narwhals._compliant.group_by import DataFrameGroupBy  | 
48 | 52 |     from narwhals._compliant.namespace import EagerNamespace  | 
49 | 53 |     from narwhals._translate import IntoArrowTable  | 
 | 54 | +    from narwhals.dataframe import DataFrame  | 
50 | 55 |     from narwhals.dtypes import DType  | 
51 | 56 |     from narwhals.schema import Schema  | 
52 | 57 |     from narwhals.typing import AsofJoinStrategy  | 
@@ -81,8 +86,9 @@ class CompliantDataFrame(  | 
81 | 86 |     ArrowConvertible["pa.Table", "IntoArrowTable"],  | 
82 | 87 |     _StoresNative[NativeFrameT],  | 
83 | 88 |     FromNative[NativeFrameT],  | 
 | 89 | +    ToNarwhals[ToNarwhalsT_co],  | 
84 | 90 |     Sized,  | 
85 |  | -    Protocol[CompliantSeriesT, CompliantExprT_contra, NativeFrameT],  | 
 | 91 | +    Protocol[CompliantSeriesT, CompliantExprT_contra, NativeFrameT, ToNarwhalsT_co],  | 
86 | 92 | ):  | 
87 | 93 |     _native_frame: NativeFrameT  | 
88 | 94 |     _implementation: Implementation  | 
@@ -113,6 +119,7 @@ def from_numpy(  | 
113 | 119 |         context: _FullContext,  | 
114 | 120 |         schema: Mapping[str, DType] | Schema | Sequence[str] | None,  | 
115 | 121 |     ) -> Self: ...  | 
 | 122 | + | 
116 | 123 |     def __array__(self, dtype: Any, *, copy: bool | None) -> _2DArray: ...  | 
117 | 124 |     def __getitem__(  | 
118 | 125 |         self,  | 
@@ -148,7 +155,7 @@ def shape(self) -> tuple[int, int]: ...  | 
148 | 155 |     def clone(self) -> Self: ...  | 
149 | 156 |     def collect(  | 
150 | 157 |         self, backend: Implementation | None, **kwargs: Any  | 
151 |  | -    ) -> CompliantDataFrame[Any, Any, Any]: ...  | 
 | 158 | +    ) -> CompliantDataFrameAny: ...  | 
152 | 159 |     def collect_schema(self) -> Mapping[str, DType]: ...  | 
153 | 160 |     def drop(self, columns: Sequence[str], *, strict: bool) -> Self: ...  | 
154 | 161 |     def drop_nulls(self, subset: Sequence[str] | None) -> Self: ...  | 
@@ -190,7 +197,7 @@ def join_asof(  | 
190 | 197 |         strategy: AsofJoinStrategy,  | 
191 | 198 |         suffix: str,  | 
192 | 199 |     ) -> Self: ...  | 
193 |  | -    def lazy(self, *, backend: Implementation | None) -> CompliantLazyFrame[Any, Any]: ...  | 
 | 200 | +    def lazy(self, *, backend: Implementation | None) -> CompliantLazyFrameAny: ...  | 
194 | 201 |     def pivot(  | 
195 | 202 |         self,  | 
196 | 203 |         on: Sequence[str],  | 
@@ -260,7 +267,8 @@ def _evaluate_aliases(self, *exprs: CompliantExprT_contra) -> list[str]:  | 
260 | 267 | class CompliantLazyFrame(  | 
261 | 268 |     _StoresNative[NativeFrameT],  | 
262 | 269 |     FromNative[NativeFrameT],  | 
263 |  | -    Protocol[CompliantExprT_contra, NativeFrameT],  | 
 | 270 | +    ToNarwhals[ToNarwhalsT_co],  | 
 | 271 | +    Protocol[CompliantExprT_contra, NativeFrameT, ToNarwhalsT_co],  | 
264 | 272 | ):  | 
265 | 273 |     _native_frame: NativeFrameT  | 
266 | 274 |     _implementation: Implementation  | 
@@ -297,7 +305,7 @@ def schema(self) -> Mapping[str, DType]: ...  | 
297 | 305 |     def _iter_columns(self) -> Iterator[Any]: ...  | 
298 | 306 |     def collect(  | 
299 | 307 |         self, backend: Implementation | None, **kwargs: Any  | 
300 |  | -    ) -> CompliantDataFrame[Any, Any, Any]: ...  | 
 | 308 | +    ) -> CompliantDataFrameAny: ...  | 
301 | 309 |     def collect_schema(self) -> Mapping[str, DType]: ...  | 
302 | 310 |     def drop(self, columns: Sequence[str], *, strict: bool) -> Self: ...  | 
303 | 311 |     def drop_nulls(self, subset: Sequence[str] | None) -> Self: ...  | 
@@ -364,14 +372,17 @@ def _evaluate_aliases(self, *exprs: CompliantExprT_contra) -> list[str]:  | 
364 | 372 | 
 
  | 
365 | 373 | 
 
  | 
366 | 374 | class EagerDataFrame(  | 
367 |  | -    CompliantDataFrame[EagerSeriesT, EagerExprT, NativeFrameT],  | 
368 |  | -    CompliantLazyFrame[EagerExprT, NativeFrameT],  | 
 | 375 | +    CompliantDataFrame[EagerSeriesT, EagerExprT, NativeFrameT, "DataFrame[NativeFrameT]"],  | 
 | 376 | +    CompliantLazyFrame[EagerExprT, NativeFrameT, "DataFrame[NativeFrameT]"],  | 
369 | 377 |     Protocol[EagerSeriesT, EagerExprT, NativeFrameT, NativeSeriesT],  | 
370 | 378 | ):  | 
371 | 379 |     def __narwhals_namespace__(  | 
372 | 380 |         self,  | 
373 | 381 |     ) -> EagerNamespace[Self, EagerSeriesT, EagerExprT, NativeFrameT, NativeSeriesT]: ...  | 
374 | 382 | 
 
  | 
 | 383 | +    def to_narwhals(self) -> DataFrame[NativeFrameT]:  | 
 | 384 | +        return self._version.dataframe(self, level="full")  | 
 | 385 | + | 
375 | 386 |     def _evaluate_expr(self, expr: EagerExprT, /) -> EagerSeriesT:  | 
376 | 387 |         """Evaluate `expr` and ensure it has a **single** output."""  | 
377 | 388 |         result: Sequence[EagerSeriesT] = expr(self)  | 
 | 
0 commit comments