|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from functools import partial |
3 | 4 | from typing import TYPE_CHECKING |
4 | 5 | from typing import Any |
5 | 6 | from typing import Container |
|
13 | 14 | from narwhals._compliant.typing import EagerExprT |
14 | 15 | from narwhals._compliant.typing import EagerSeriesT_co |
15 | 16 | from narwhals.utils import deprecated |
| 17 | +from narwhals.utils import exclude_column_names |
| 18 | +from narwhals.utils import get_column_names |
| 19 | +from narwhals.utils import passthrough_column_names |
16 | 20 |
|
17 | 21 | if TYPE_CHECKING: |
18 | 22 | from narwhals._compliant.selectors import CompliantSelectorNamespace |
19 | 23 | from narwhals.dtypes import DType |
| 24 | + from narwhals.utils import Implementation |
| 25 | + from narwhals.utils import Version |
20 | 26 |
|
21 | 27 | __all__ = ["CompliantNamespace", "EagerNamespace"] |
22 | 28 |
|
23 | 29 |
|
24 | 30 | class CompliantNamespace(Protocol[CompliantFrameT, CompliantExprT]): |
25 | | - def col(self, *column_names: str) -> CompliantExprT: ... |
26 | | - def lit(self, value: Any, dtype: DType | None) -> CompliantExprT: ... |
27 | | - def exclude(self, excluded_names: Container[str]) -> CompliantExprT: ... |
28 | | - def nth(self, *column_indices: int) -> CompliantExprT: ... |
| 31 | + _implementation: Implementation |
| 32 | + _backend_version: tuple[int, ...] |
| 33 | + _version: Version |
| 34 | + |
| 35 | + def all(self) -> CompliantExprT: |
| 36 | + return self._expr.from_column_names( |
| 37 | + get_column_names, function_name="all", context=self |
| 38 | + ) |
| 39 | + |
| 40 | + def col(self, *column_names: str) -> CompliantExprT: |
| 41 | + return self._expr.from_column_names( |
| 42 | + passthrough_column_names(column_names), function_name="col", context=self |
| 43 | + ) |
| 44 | + |
| 45 | + def exclude(self, excluded_names: Container[str]) -> CompliantExprT: |
| 46 | + return self._expr.from_column_names( |
| 47 | + partial(exclude_column_names, names=excluded_names), |
| 48 | + function_name="exclude", |
| 49 | + context=self, |
| 50 | + ) |
| 51 | + |
| 52 | + def nth(self, *column_indices: int) -> CompliantExprT: |
| 53 | + return self._expr.from_column_indices(*column_indices, context=self) |
| 54 | + |
29 | 55 | def len(self) -> CompliantExprT: ... |
30 | | - def all(self) -> CompliantExprT: ... |
| 56 | + def lit(self, value: Any, dtype: DType | None) -> CompliantExprT: ... |
31 | 57 | def all_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... |
32 | 58 | def any_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... |
33 | 59 | def sum_horizontal(self, *exprs: CompliantExprT) -> CompliantExprT: ... |
|
0 commit comments