Skip to content

Commit

Permalink
Merge pull request #60 from jraviS2023/jravi-rename-IntoExpr-to-IntoE…
Browse files Browse the repository at this point in the history
…xprColumn

Rename IntoExpr to IntoExprColumn
  • Loading branch information
MarcoGorelli authored Oct 3, 2024
2 parents 0f1970e + 525becb commit 73e2361
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions docs/abs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Let's start with the Python side - this is almost the same as what
we did for `noop`, we'll just change the names. Please add this to
`minimal_plugin/__init__.py`, right below the definition of `noop`:
```python
def abs_i64(expr: IntoExpr) -> pl.Expr:
def abs_i64(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down Expand Up @@ -89,7 +89,7 @@ generalise it a bit, so that it can accept any signed numeric column.
First, add the following definition to `minimal_plugin/__init__.py`:

```python
def abs_numeric(expr: IntoExpr) -> pl.Expr:
def abs_numeric(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ the weights are given by a second column.
Nothing fancy here:

```python
def vertical_weighted_mean(values: IntoExpr, weights: IntoExpr) -> pl.Expr:
def vertical_weighted_mean(values: IntoExprColumn, weights: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[values, weights],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We'll do this with `kwargs`. In `minimal_plugin/__init__.py`, add the
following:

```python
def add_suffix(expr: IntoExpr, *, suffix: str) -> pl.Expr:
def add_suffix(expr: IntoExprColumn, *, suffix: str) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This should illustrate both how to unpack an array inside our Rust code and also
We'll start by registering our plugin:

```python
def midpoint_2d(expr: IntoExpr, ref_point: tuple[float, float]) -> pl.Expr:
def midpoint_2d(expr: IntoExprColumn, ref_point: tuple[float, float]) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=Path(__file__).parent,
Expand Down
2 changes: 1 addition & 1 deletion docs/cum_sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We're going to implement `cum_sum`.

Add this to `minimal_plugin/__init__.py`:
```python
def cum_sum(expr: IntoExpr) -> pl.Expr:
def cum_sum(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
6 changes: 3 additions & 3 deletions docs/life_pt1.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ from pathlib import Path
from typing import Iterable, Any

import polars as pl
from polars._typing import IntoExpr
from polars._typing import IntoExprColumn
from polars.plugins import register_plugin_function


Expand All @@ -61,7 +61,7 @@ def _nwise_wrapping(iterable: Iterable[Any], n: int): ...
def step(df: pl.DataFrame, n: int = 1): ...

# Register our plugin
def life_step(left: IntoExpr, mid: IntoExpr, right: IntoExpr) -> pl.Expr: ...
def life_step(left: IntoExprColumn, mid: IntoExprColumn, right: IntoExprColumn) -> pl.Expr: ...
```

Starting with the function to parse a board from a file or stdin:
Expand Down Expand Up @@ -153,7 +153,7 @@ Let's skip `_nwise_wrapping` and `step` for now and jump straight to the last fu
Don't forget to read the comments!

```python
def life_step(left: IntoExpr, mid: IntoExpr, right: IntoExpr) -> pl.Expr:
def life_step(left: IntoExprColumn, mid: IntoExprColumn, right: IntoExprColumn) -> pl.Expr:
"""
This is the function that registers the polars plugin. To use it directly,
data must be in the correct format. An interesting way to do so is to use
Expand Down
2 changes: 1 addition & 1 deletion docs/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ as you'll see here, it's not that hard to write a plugin, and it's probably fast
On the Python side, this'll be similar to `sum_i64`:

```python
def weighted_mean(expr: IntoExpr, weights: IntoExpr) -> pl.Expr:
def weighted_mean(expr: IntoExprColumn, weights: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr, weights],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/lists_in_lists_out.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Polars dtype.
To finish this off, the Python side will be a bog-standard:

```python
def non_zero_indices(expr: IntoExpr) -> pl.Expr:
def non_zero_indices(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr], plugin_path=LIB, function_name="non_zero_indices", is_elementwise=True
)
Expand Down
2 changes: 1 addition & 1 deletion docs/lost_in_space.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Unfortunately, not. But, this is a good chance to learn about a few new concepts
We'll start easy by dealing with the Python side. Add the following to `minimal_plugin/__init__.py`:

```python
def reverse_geocode(lat: IntoExpr, long: IntoExpr) -> pl.Expr:
def reverse_geocode(lat: IntoExprColumn, long: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[lat, long], plugin_path=LIB, function_name="reverse_geocode", is_elementwise=True
)
Expand Down
2 changes: 1 addition & 1 deletion docs/noop.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ implement the Rust side too, but it's a necessary step.
Start by adding the following to `minimal_plugin/__init__.py`:

```python
def noop(expr: IntoExpr) -> pl.Expr:
def noop(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/stem.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ df.with_columns(stemmed_word=mp.snowball_stem('word'))
On the Python side, let's add the following function to `minimal_plugin/__init__.py`:

```python
def snowball_stem(expr: IntoExpr) -> pl.Expr:
def snowball_stem(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/stringify.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ If you combine this with a Python definition (which you should put
in `minimal_plugin/__init__.py`):

```python
def pig_latinnify(expr: IntoExpr) -> pl.Expr:
def pig_latinnify(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the input was `{'a': 1, 'b': 2., 'c': '3'}`, then the output will be
On the Python side, usual business:

```python
def shift_struct(expr: IntoExpr) -> pl.Expr:
def shift_struct(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion docs/sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ by using the `args` argument when we register our expression. Add the following
`minimal_plugins/__init__.py`:

```python
def sum_i64(expr: IntoExpr, other: IntoExpr) -> pl.Expr:
def sum_i64(expr: IntoExprColumn, other: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr, other],
plugin_path=LIB,
Expand Down
38 changes: 19 additions & 19 deletions minimal_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
LIB = Path(__file__).parent

if TYPE_CHECKING:
from minimal_plugin.typing import IntoExpr
from minimal_plugin.typing import IntoExprColumn


def noop(expr: IntoExpr) -> pl.Expr:
def noop(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -22,7 +22,7 @@ def noop(expr: IntoExpr) -> pl.Expr:
)


def abs_i64(expr: IntoExpr) -> pl.Expr:
def abs_i64(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -31,7 +31,7 @@ def abs_i64(expr: IntoExpr) -> pl.Expr:
)


def abs_numeric(expr: IntoExpr) -> pl.Expr:
def abs_numeric(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -40,7 +40,7 @@ def abs_numeric(expr: IntoExpr) -> pl.Expr:
)


def sum_i64(expr: IntoExpr, other: IntoExpr) -> pl.Expr:
def sum_i64(expr: IntoExprColumn, other: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr, other],
plugin_path=LIB,
Expand All @@ -49,7 +49,7 @@ def sum_i64(expr: IntoExpr, other: IntoExpr) -> pl.Expr:
)


def cum_sum(expr: IntoExpr) -> pl.Expr:
def cum_sum(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -58,7 +58,7 @@ def cum_sum(expr: IntoExpr) -> pl.Expr:
)


def pig_latinnify(expr: IntoExpr) -> pl.Expr:
def pig_latinnify(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -67,7 +67,7 @@ def pig_latinnify(expr: IntoExpr) -> pl.Expr:
)


def remove_extension(expr: IntoExpr) -> pl.Expr:
def remove_extension(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -76,7 +76,7 @@ def remove_extension(expr: IntoExpr) -> pl.Expr:
)


def abs_i64_fast(expr: IntoExpr) -> pl.Expr:
def abs_i64_fast(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -85,7 +85,7 @@ def abs_i64_fast(expr: IntoExpr) -> pl.Expr:
)


def add_suffix(expr: IntoExpr, *, suffix: str) -> pl.Expr:
def add_suffix(expr: IntoExprColumn, *, suffix: str) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -95,7 +95,7 @@ def add_suffix(expr: IntoExpr, *, suffix: str) -> pl.Expr:
)


def snowball_stem(expr: IntoExpr) -> pl.Expr:
def snowball_stem(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -104,7 +104,7 @@ def snowball_stem(expr: IntoExpr) -> pl.Expr:
)


def weighted_mean(expr: IntoExpr, weights: IntoExpr) -> pl.Expr:
def weighted_mean(expr: IntoExprColumn, weights: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr, weights],
plugin_path=LIB,
Expand All @@ -113,7 +113,7 @@ def weighted_mean(expr: IntoExpr, weights: IntoExpr) -> pl.Expr:
)


def shift_struct(expr: IntoExpr) -> pl.Expr:
def shift_struct(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -122,7 +122,7 @@ def shift_struct(expr: IntoExpr) -> pl.Expr:
)


def reverse_geocode(lat: IntoExpr, long: IntoExpr) -> pl.Expr:
def reverse_geocode(lat: IntoExprColumn, long: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[lat, long],
plugin_path=LIB,
Expand All @@ -131,7 +131,7 @@ def reverse_geocode(lat: IntoExpr, long: IntoExpr) -> pl.Expr:
)


def non_zero_indices(expr: IntoExpr) -> pl.Expr:
def non_zero_indices(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -140,7 +140,7 @@ def non_zero_indices(expr: IntoExpr) -> pl.Expr:
)


def vertical_weighted_mean(values: IntoExpr, weights: IntoExpr) -> pl.Expr:
def vertical_weighted_mean(values: IntoExprColumn, weights: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[values, weights],
plugin_path=LIB,
Expand All @@ -150,7 +150,7 @@ def vertical_weighted_mean(values: IntoExpr, weights: IntoExpr) -> pl.Expr:
)


def interpolate(expr: IntoExpr) -> pl.Expr:
def interpolate(expr: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand All @@ -159,7 +159,7 @@ def interpolate(expr: IntoExpr) -> pl.Expr:
)


def life_step(left: IntoExpr, mid: IntoExpr, right: IntoExpr) -> pl.Expr:
def life_step(left: IntoExprColumn, mid: IntoExprColumn, right: IntoExprColumn) -> pl.Expr:
return register_plugin_function(
args=[left, mid, right],
plugin_path=LIB,
Expand All @@ -168,7 +168,7 @@ def life_step(left: IntoExpr, mid: IntoExpr, right: IntoExpr) -> pl.Expr:
)


def midpoint_2d(expr: IntoExpr, ref_point: tuple[float, float]) -> pl.Expr:
def midpoint_2d(expr: IntoExprColumn, ref_point: tuple[float, float]) -> pl.Expr:
return register_plugin_function(
args=[expr],
plugin_path=LIB,
Expand Down
2 changes: 1 addition & 1 deletion minimal_plugin/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
from typing_extensions import TypeAlias
from polars.datatypes import DataType, DataTypeClass

IntoExpr: TypeAlias = Union[pl.Expr, str, pl.Series]
IntoExprColumn: TypeAlias = Union[pl.Expr, str, pl.Series]
PolarsDataType: TypeAlias = Union[DataType, DataTypeClass]

0 comments on commit 73e2361

Please sign in to comment.