Skip to content

Conversation

@dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Dec 21, 2025

Description

This'll be the first in a series of PRs that close gaps in non-Expr features.

Will be focusing on what is defined in DslPlan, and this one is for DslPlan::Distinct.

Related issues

@dangotbanned dangotbanned added enhancement New feature or request internal labels Dec 22, 2025
Comment on lines +290 to +291
class todo: # pragma: no cover # noqa: N801
"""A variation of `not_implemented`, for shorter-lived placeholders."""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still want to have this, but it doesn't make sense now that it isn't used in the PR 😅

Comment on lines +42 to +51
pytest.param(
ncs.first().last(),
InvalidOperationError,
# TODO @dangotbanned: Fix this in another PR
# Need to be stricter on the Selector check
marks=pytest.mark.xfail(
reason="narwhals/_plan/_expansion.py:160: 'Last' object has no attribute 'iter_expand_names'",
raises=AttributeError,
),
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up PR

Be stricter here.

Calling an Expr method on a Selector preserves the runtime type of Selector

def _parse_into_selector(
input: ColumnNameOrSelector | Expr, /, *, require_all: bool = True
) -> Selector:
if is_selector(input):
selector = input
elif isinstance(input, str):
import narwhals._plan.selectors as cs
selector = cs.by_name(input, require_all=require_all)
elif is_expr(input):
selector = input.meta.as_selector()
else:
msg = f"cannot turn {qualified_type_name(input)!r} into a selector"
raise TypeError(msg)
return selector

Some related bits

def as_selector(self) -> Selector:
"""Try to turn this expression into a selector.
Raises if the underlying expressions is not a column or selector.
"""
return self._ir.to_selector_ir().to_narwhals()

def is_column_name_or_selector(
obj: Any, *, allow_expr: bool = False
) -> TypeIs[ColumnNameOrSelector]:
tps = (str, _selectors().Selector) if not allow_expr else (str, _expr().Expr)
return isinstance(obj, tps)

@dangotbanned dangotbanned marked this pull request as ready for review December 22, 2025 21:54
@dangotbanned dangotbanned merged commit 158eda2 into oh-nodes Dec 22, 2025
30 of 35 checks passed
@dangotbanned dangotbanned deleted the expr-ir/dataframe-unique branch December 22, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request internal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants