Skip to content

Commit 154dc54

Browse files
committed
feat: Define CompliantDataFrame.from_numpy
1 parent 6ec7272 commit 154dc54

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

narwhals/_compliant/dataframe.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from narwhals._compliant.typing import EagerSeriesT
1919
from narwhals._compliant.typing import NativeFrameT_co
2020
from narwhals._expression_parsing import evaluate_output_names_and_aliases
21+
from narwhals._translate import NumpyConvertible
2122
from narwhals.utils import Version
2223
from narwhals.utils import _StoresNative
2324
from narwhals.utils import deprecated
@@ -34,9 +35,11 @@
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

@@ -46,6 +49,7 @@
4649

4750

4851
class CompliantDataFrame(
52+
NumpyConvertible["_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:
@@ -286,7 +299,8 @@ def _evaluate_expr(self, expr: EagerExprT_contra, /) -> EagerSeriesT:
286299
return result[0]
287300

288301
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))
302+
# NOTE: Ignore is to avoid an intermittent false positive
303+
return list(chain.from_iterable(self._evaluate_into_expr(expr) for expr in exprs)) # pyright: ignore[reportArgumentType]
290304

291305
def _evaluate_into_expr(self, expr: EagerExprT_contra, /) -> Sequence[EagerSeriesT]:
292306
"""Return list of raw columns.

0 commit comments

Comments
 (0)