1818from narwhals ._compliant .typing import EagerSeriesT
1919from narwhals ._compliant .typing import NativeFrameT_co
2020from narwhals ._expression_parsing import evaluate_output_names_and_aliases
21+ from narwhals ._translate import NumpyConvertible
2122from narwhals .utils import Version
2223from narwhals .utils import _StoresNative
2324from narwhals .utils import deprecated
3435
3536 from narwhals ._compliant .group_by import CompliantGroupBy
3637 from narwhals .dtypes import DType
38+ from narwhals .schema import Schema
3739 from narwhals .typing import SizeUnit
3840 from narwhals .typing import _2DArray
3941 from narwhals .utils import Implementation
42+ from narwhals .utils import _FullContext
4043
4144 Incomplete : TypeAlias = Any
4245
4649
4750
4851class CompliantDataFrame (
52+ NumpyConvertible ["_2DArray" , "_2DArray" ],
4953 _StoresNative [NativeFrameT_co ],
5054 Sized ,
5155 Protocol [CompliantSeriesT , CompliantExprT_contra , NativeFrameT_co ],
@@ -57,6 +61,15 @@ class CompliantDataFrame(
5761
5862 def __narwhals_dataframe__ (self ) -> Self : ...
5963 def __narwhals_namespace__ (self ) -> Any : ...
64+ @classmethod
65+ def from_numpy (
66+ cls ,
67+ data : _2DArray ,
68+ / ,
69+ * ,
70+ context : _FullContext ,
71+ schema : Mapping [str , DType ] | Schema | Sequence [str ] | None ,
72+ ) -> Self : ...
6073 def __array__ (self , dtype : Any , * , copy : bool | None ) -> _2DArray : ...
6174 def __getitem__ (self , item : Any ) -> CompliantSeriesT | Self : ...
6275 def simple_select (self , * column_names : str ) -> Self :
@@ -143,7 +156,6 @@ def sort(
143156 ) -> Self : ...
144157 def tail (self , n : int ) -> Self : ...
145158 def to_arrow (self ) -> pa .Table : ...
146- def to_numpy (self ) -> _2DArray : ...
147159 def to_pandas (self ) -> pd .DataFrame : ...
148160 def to_polars (self ) -> pl .DataFrame : ...
149161 @overload
@@ -286,7 +298,8 @@ def _evaluate_expr(self, expr: EagerExprT_contra, /) -> EagerSeriesT:
286298 return result [0 ]
287299
288300 def _evaluate_into_exprs (self , * exprs : EagerExprT_contra ) -> Sequence [EagerSeriesT ]:
289- return list (chain .from_iterable (self ._evaluate_into_expr (expr ) for expr in exprs ))
301+ # NOTE: Ignore is to avoid an intermittent false positive
302+ return list (chain .from_iterable (self ._evaluate_into_expr (expr ) for expr in exprs )) # pyright: ignore[reportArgumentType]
290303
291304 def _evaluate_into_expr (self , expr : EagerExprT_contra , / ) -> Sequence [EagerSeriesT ]:
292305 """Return list of raw columns.
@@ -308,3 +321,9 @@ def _evaluate_into_expr(self, expr: EagerExprT_contra, /) -> Sequence[EagerSerie
308321 def _extract_comparand (self , other : EagerSeriesT , / ) -> Any :
309322 """Extract native Series, broadcasting to `len(self)` if necessary."""
310323 ...
324+
325+ @staticmethod
326+ def _numpy_column_names (
327+ data : _2DArray , columns : Sequence [str ] | None , /
328+ ) -> list [str ]:
329+ return list (columns or (f"column_{ x } " for x in range (data .shape [1 ])))
0 commit comments