|
6 | 6 | from typing import Container |
7 | 7 | from typing import Iterable |
8 | 8 | from typing import Literal |
| 9 | +from typing import Mapping |
9 | 10 | from typing import Protocol |
| 11 | +from typing import Sequence |
| 12 | +from typing import overload |
10 | 13 |
|
11 | 14 | from narwhals._compliant.typing import CompliantExprT |
12 | 15 | from narwhals._compliant.typing import CompliantFrameT |
13 | 16 | from narwhals._compliant.typing import DepthTrackingExprT |
14 | 17 | from narwhals._compliant.typing import EagerDataFrameT |
15 | 18 | from narwhals._compliant.typing import EagerExprT |
16 | 19 | from narwhals._compliant.typing import EagerSeriesT |
| 20 | +from narwhals.dependencies import is_numpy_array_2d |
17 | 21 | from narwhals.utils import exclude_column_names |
18 | 22 | from narwhals.utils import get_column_names |
19 | 23 | from narwhals.utils import passthrough_column_names |
|
25 | 29 | from narwhals._compliant.when_then import CompliantWhen |
26 | 30 | from narwhals._compliant.when_then import EagerWhen |
27 | 31 | from narwhals.dtypes import DType |
| 32 | + from narwhals.schema import Schema |
| 33 | + from narwhals.typing import Into1DArray |
| 34 | + from narwhals.typing import _2DArray |
28 | 35 | from narwhals.utils import Implementation |
29 | 36 | from narwhals.utils import Version |
30 | 37 |
|
@@ -116,3 +123,29 @@ def _series(self) -> type[EagerSeriesT]: ... |
116 | 123 | def when( |
117 | 124 | self, predicate: EagerExprT |
118 | 125 | ) -> EagerWhen[EagerDataFrameT, EagerSeriesT, EagerExprT, Incomplete]: ... |
| 126 | + |
| 127 | + @overload |
| 128 | + def from_numpy( |
| 129 | + self, |
| 130 | + data: Into1DArray, |
| 131 | + /, |
| 132 | + schema: None = ..., |
| 133 | + ) -> EagerSeriesT: ... |
| 134 | + |
| 135 | + @overload |
| 136 | + def from_numpy( |
| 137 | + self, |
| 138 | + data: _2DArray, |
| 139 | + /, |
| 140 | + schema: Mapping[str, DType] | Schema | Sequence[str] | None, |
| 141 | + ) -> EagerDataFrameT: ... |
| 142 | + |
| 143 | + def from_numpy( |
| 144 | + self, |
| 145 | + data: Into1DArray | _2DArray, |
| 146 | + /, |
| 147 | + schema: Mapping[str, DType] | Schema | Sequence[str] | None = None, |
| 148 | + ) -> EagerDataFrameT | EagerSeriesT: |
| 149 | + if is_numpy_array_2d(data): |
| 150 | + return self._dataframe.from_numpy(data, schema=schema, context=self) |
| 151 | + return self._series.from_numpy(data, context=self) |
0 commit comments