chore(typing): Fill out CompliantNamespace protocol#2202
Conversation
- Only needs to be the extra stuff - `_create_compliant_series` is removed in #2196
| *, | ||
| how: Literal["horizontal", "vertical", "diagonal"], | ||
| ) -> CompliantFrameT: ... | ||
| def when(self, predicate: CompliantExprT) -> Any: ... |
There was a problem hiding this comment.
- Return type would require another generic protocol for
When - Doing that is a pretty low priority for now
narwhals/_spark_like/namespace.py
Outdated
| @property | ||
| def _expr(self) -> type[SparkLikeExpr]: | ||
| return SparkLikeExpr | ||
|
|
||
| def all(self: Self) -> SparkLikeExpr: | ||
| return SparkLikeExpr.from_column_names( | ||
| get_column_names, |
There was a problem hiding this comment.
Oooh we might be able to implement this (and maybe a few other methods) higher up in the protocol 🤯
There was a problem hiding this comment.
from narwhals.utils import get_column_names
class CompliantNamespace(Protocol[CompliantFrameT, CompliantExprT]):
@property
def _expr(self) -> type[CompliantExprT]: ...
def all(self) -> CompliantExprT:
return self._expr.from_column_names(
get_column_names,
function_name="all",
implementation=self._implementation,
backend_version=self._backend_version,
version=self._version,
)There was a problem hiding this comment.
Already most of the way there in
narwhals/narwhals/_pandas_like/namespace.py
Lines 77 to 96 in d860054
There was a problem hiding this comment.
@FBruzzesi ignore this if you're not fully back yet 🙂
Thought you might like to see this new possibility - following the recent spec-ing of the Compliant* protocols
There was a problem hiding this comment.
Went ahead with that in (5d609a7)
We now have default implementations for 4x CompliantNamespace methods 😁
All backends (besides `polars`) now share the same implementation #2202 (comment)
- `FrameT` isn't relevant to what is used - Only needed before as `CompliantNamespace` didn't expose an `ExprT`
| ) | ||
|
|
||
| def mean_horizontal(self: Self, *exprs: ArrowExpr) -> IntoArrowExpr: | ||
| def mean_horizontal(self: Self, *exprs: ArrowExpr) -> ArrowExpr: |
There was a problem hiding this comment.
This only got flagged after filling out the protocol.

What type of PR is this? (check all applicable)
Related issues
CompliantSeries.from_numpy#2196CompliantExpr#2119Checklist
If you have comments or can explain your changes, please do so below
_create_compliant_seriesis removed in refactor: AddCompliantSeries.from_numpy#2196CompliantExpr