Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jan 29, 2024
1 parent 4c0f283 commit 1fa720a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,42 +51,42 @@ fn pig_latinnify(inputs: &[Series], kwargs: PigLatinKwargs) -> PolarsResult<Seri
}
```

On the python side this expression can then be registered under a namespace:
This can then be exposed on the Python side:

```python
import polars as pl
from polars.type_aliases import IntoExpr
from polars.utils.udfs import _get_shared_lib_location

lib = _get_shared_lib_location(__file__)
from expression_lib.utils import parse_into_expr

lib = _get_shared_lib_location(__file__)

@pl.api.register_expr_namespace("language")
class Language:
def __init__(self, expr: pl.Expr):
self._expr = expr

def pig_latinnify(self, capatilize: bool = False) -> pl.Expr:
return self._expr._register_plugin(
lib=lib,
symbol="pig_latinnify",
is_elementwise=True,
kwargs={"capitalize": capatilize}
)
def pig_latinnify(expr: IntoExpr, capitalize: bool = False) -> pl.Expr:
expr = parse_into_expr(expr)
return expr.register_plugin(
lib=lib,
symbol="pig_latinnify",
is_elementwise=True,
kwargs={"capitalize": capitalize},
)
```
and/or registered as a [Expression Extension](https://docs.pola.rs/py-polars/html/reference/api/polars.api.register_expr_namespace.html#polars.api.register_expr_namespace).

Compile/ship and then it is ready to use:

```python
import polars as pl
import expression_lib
from expression_lib import language

df = pl.DataFrame({
"names": ["Richard", "Alice", "Bob"],
})


out = df.with_columns(
pig_latin = pl.col("names").language.pig_latinnify()
pig_latin = language.pig_latinnify("names")
)
```

Expand Down

0 comments on commit 1fa720a

Please sign in to comment.