Skip to content

Conversation

@dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Mar 13, 2025

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

- 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: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

  • Return type would require another generic protocol for When
  • Doing that is a pretty low priority for now

Comment on lines 51 to 57
@property
def _expr(self) -> type[SparkLikeExpr]:
return SparkLikeExpr

def all(self: Self) -> SparkLikeExpr:
return SparkLikeExpr.from_column_names(
get_column_names,
Copy link
Member Author

@dangotbanned dangotbanned Mar 13, 2025

Choose a reason for hiding this comment

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

Oooh we might be able to implement this (and maybe a few other methods) higher up in the protocol 🤯

Copy link
Member Author

Choose a reason for hiding this comment

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

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,
        )

Copy link
Member Author

Choose a reason for hiding this comment

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

Already most of the way there in

# --- selection ---
def col(self: Self, *column_names: str) -> PandasLikeExpr:
return self._expr.from_column_names(
passthrough_column_names(column_names), function_name="col", context=self
)
def exclude(self: Self, excluded_names: Container[str]) -> PandasLikeExpr:
return self._expr.from_column_names(
partial(exclude_column_names, names=excluded_names),
function_name="exclude",
context=self,
)
def nth(self: Self, *column_indices: int) -> PandasLikeExpr:
return self._expr.from_column_indices(*column_indices, context=self)
def all(self: Self) -> PandasLikeExpr:
return self._expr.from_column_names(
get_column_names, function_name="all", context=self
)

Copy link
Member Author

Choose a reason for hiding this comment

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

@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

Copy link
Member Author

Choose a reason for hiding this comment

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

Went ahead with that in (5d609a7)

We now have default implementations for 4x CompliantNamespace methods 😁

@dangotbanned dangotbanned marked this pull request as ready for review March 14, 2025 10:34
)

def mean_horizontal(self: Self, *exprs: ArrowExpr) -> IntoArrowExpr:
def mean_horizontal(self: Self, *exprs: ArrowExpr) -> ArrowExpr:
Copy link
Member Author

@dangotbanned dangotbanned Mar 14, 2025

Choose a reason for hiding this comment

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

This only got flagged after filling out the protocol.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @dangotbanned !

@dangotbanned dangotbanned merged commit 14c0c78 into main Mar 15, 2025
29 checks passed
@dangotbanned dangotbanned deleted the compliant-namespace-spec branch March 15, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants