Skip to content

Commit

Permalink
add why
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 24, 2024
1 parent 07cd722 commit 68fa694
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ site_name: Narwhals
repo_url: https://github.com/MarcoGorelli/narwhals.git
nav:
- Home: index.md
- Why: why.md
- Installation: installation.md
- Quick start: quick_start.md
- Tutorial:
Expand Down
24 changes: 24 additions & 0 deletions narwhals/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,34 +180,58 @@ def ends_with(self, suffix: str) -> Expr:


def col(*names: str | Iterable[str]) -> Expr:
"""
Instantiate an expression, similar to `polars.col`.
"""
return Expr(lambda plx: plx.col(*names))


def all() -> Expr:
"""
Instantiate an expression representing all columns, similar to `polars.all`.
"""
return Expr(lambda plx: plx.all())


def len() -> Expr:
"""
Instantiate an expression representing the length of a dataframe, similar to `polars.len`.
"""
return Expr(lambda plx: plx.len())


def sum(*columns: str) -> Expr:
"""
Instantiate an expression representing the sum of one or more columns, similar to `polars.sum`.
"""
return Expr(lambda plx: plx.sum(*columns))


def mean(*columns: str) -> Expr:
"""
Instantiate an expression representing the mean of one or more columns, similar to `polars.mean`.
"""
return Expr(lambda plx: plx.mean(*columns))


def min(*columns: str) -> Expr:
"""
Instantiate an expression representing the minimum of one or more columns, similar to `polars.min`.
"""
return Expr(lambda plx: plx.min(*columns))


def max(*columns: str) -> Expr:
"""
Instantiate an expression representing the maximum of one or more columns, similar to `polars.max`.
"""
return Expr(lambda plx: plx.max(*columns))


def sum_horizontal(*exprs: IntoExpr | Iterable[IntoExpr]) -> Expr:
"""
Instantiate an expression representing the horzontal sum of one or more expressions, similar to `polars.sum_horizontal`.
"""
return Expr(
lambda plx: plx.sum_horizontal([extract_native(plx, v) for v in flatten(exprs)])
)
Expand Down

0 comments on commit 68fa694

Please sign in to comment.