Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion narwhals/_arrow/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from narwhals._expression_parsing import combine_evaluate_output_names
from narwhals.typing import CompliantNamespace
from narwhals.utils import Implementation
from narwhals.utils import get_column_names
from narwhals.utils import import_dtypes_module

if TYPE_CHECKING:
Expand Down Expand Up @@ -161,7 +162,7 @@ def all(self: Self) -> ArrowExpr:
],
depth=0,
function_name="all",
evaluate_output_names=lambda df: df.columns,
evaluate_output_names=get_column_names,
alias_output_names=None,
backend_version=self._backend_version,
version=self._version,
Expand Down
3 changes: 2 additions & 1 deletion narwhals/_dask/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from narwhals._expression_parsing import combine_alias_output_names
from narwhals._expression_parsing import combine_evaluate_output_names
from narwhals.typing import CompliantNamespace
from narwhals.utils import get_column_names

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -55,7 +56,7 @@ def func(df: DaskLazyFrame) -> list[dx.Series]:
func,
depth=0,
function_name="all",
evaluate_output_names=lambda df: df.columns,
evaluate_output_names=get_column_names,
alias_output_names=None,
backend_version=self._backend_version,
version=self._version,
Expand Down
3 changes: 2 additions & 1 deletion narwhals/_duckdb/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from narwhals._expression_parsing import combine_alias_output_names
from narwhals._expression_parsing import combine_evaluate_output_names
from narwhals.typing import CompliantNamespace
from narwhals.utils import get_column_names

if TYPE_CHECKING:
import duckdb
Expand Down Expand Up @@ -52,7 +53,7 @@ def _all(df: DuckDBLazyFrame) -> list[duckdb.Expression]:
return DuckDBExpr(
call=_all,
function_name="all",
evaluate_output_names=lambda df: df.columns,
evaluate_output_names=get_column_names,
alias_output_names=None,
backend_version=self._backend_version,
version=self._version,
Expand Down
3 changes: 2 additions & 1 deletion narwhals/_pandas_like/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from narwhals._pandas_like.utils import horizontal_concat
from narwhals._pandas_like.utils import vertical_concat
from narwhals.typing import CompliantNamespace
from narwhals.utils import get_column_names
from narwhals.utils import import_dtypes_module

if TYPE_CHECKING:
Expand Down Expand Up @@ -135,7 +136,7 @@ def all(self: Self) -> PandasLikeExpr:
],
depth=0,
function_name="all",
evaluate_output_names=lambda df: df.columns,
evaluate_output_names=get_column_names,
alias_output_names=None,
implementation=self._implementation,
backend_version=self._backend_version,
Expand Down
3 changes: 2 additions & 1 deletion narwhals/_spark_like/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from narwhals._spark_like.utils import maybe_evaluate_expr
from narwhals._spark_like.utils import narwhals_to_native_dtype
from narwhals.typing import CompliantNamespace
from narwhals.utils import get_column_names

if TYPE_CHECKING:
from pyspark.sql import Column
Expand Down Expand Up @@ -51,7 +52,7 @@ def _all(df: SparkLikeLazyFrame) -> list[Column]:
return SparkLikeExpr(
call=_all,
function_name="all",
evaluate_output_names=lambda df: df.columns,
evaluate_output_names=get_column_names,
alias_output_names=None,
backend_version=self._backend_version,
version=self._version,
Expand Down
6 changes: 6 additions & 0 deletions narwhals/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def aggregate(self, *exprs: Any) -> Self:
... # `select` where all args are aggregations or literals
# (so, no broadcasting is necessary).

@property
def columns(self) -> Sequence[str]: ...


class CompliantLazyFrame(Protocol):
def __narwhals_lazyframe__(self) -> Self: ...
Expand All @@ -73,6 +76,9 @@ def aggregate(self, *exprs: Any) -> Self:
... # `select` where all args are aggregations or literals
# (so, no broadcasting is necessary).

@property
def columns(self) -> Sequence[str]: ...


CompliantFrameT_contra = TypeVar(
"CompliantFrameT_contra",
Expand Down
8 changes: 8 additions & 0 deletions narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class _FullContext(_StoresImplementation, _LimitedContext, Protocol): # noqa: P
- `_version`
"""

class _StoresColumns(Protocol):
@property
def columns(self) -> Sequence[str]: ...


class Version(Enum):
V1 = auto()
Expand Down Expand Up @@ -1344,6 +1348,10 @@ def dtype_matches_time_unit_and_time_zone(
)


def get_column_names(frame: _StoresColumns, /) -> Sequence[str]:
return frame.columns


def _hasattr_static(obj: Any, attr: str) -> bool:
sentinel = object()
return getattr_static(obj, attr, sentinel) is not sentinel
Expand Down
Loading