You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/noop.md
+19-32Lines changed: 19 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,18 @@ should look a bit like the following:
13
13
├── Cargo.toml
14
14
├── minimal_plugin
15
15
│ ├── __init__.py
16
-
│ └── utils.py
16
+
│ └── typing.py
17
17
├── pyproject.toml
18
-
└── src
19
-
├── expressions.rs
20
-
├── lib.rs
21
-
└── utils.rs
18
+
├── run.py
19
+
├── src
20
+
│ ├── expressions.rs
21
+
│ └── lib.rs
22
+
└── tests
22
23
```
24
+
The cookiecutter command you ran earlier set up a Polars plugin project with a
25
+
sample function called `pig_latinnify` already implemented. The [Polars Plugins Cookiecutter](https://github.com/MarcoGorelli/cookiecutter-polars-plugins)
26
+
helps you quickly start a Polars plugin project, skipping the boilerplate setup.
27
+
Check it out for more details!
23
28
24
29
[Prerequisites]: ../prerequisites/
25
30
@@ -31,22 +36,20 @@ Start by adding the following to `minimal_plugin/__init__.py`:
31
36
32
37
```python
33
38
defnoop(expr: IntoExpr) -> pl.Expr:
34
-
returnregister_plugin(
39
+
returnregister_plugin_function(
35
40
args=[expr],
36
-
lib=lib,
37
-
symbol="noop",
41
+
plugin_path=LIB,
42
+
function_name="noop",
38
43
is_elementwise=True,
39
44
)
40
45
```
41
46
Let's go through this line-by-line:
42
47
43
48
- when we compile Rust, it generates a Shared Object file.
44
-
The `lib` variable holds its filepath;
49
+
The `LIB` variable holds its filepath;
45
50
- We'll cover `is_elementwise` in [Yes we SCAN], for now don't pay attention to it;
46
-
- We use the utility function `register_plugin`, provided to us by the cookiecutter.
47
-
Polars actually has a public [register_plugin_function](https://docs.pola.rs/py-polars/html/reference/plugins.html#polars.plugins.register_plugin_function) utility for this, but it was only introduced in
48
-
Polars 0.20.16. The `register_plugin` function we introduce here handles backwards-compatibility
49
-
until Polars 0.20.6, so we use that in this tutorial.
51
+
- We use the Polars utility function [register_plugin_function](https://docs.pola.rs/py-polars/html/reference/plugins.html#polars.plugins.register_plugin_function) to extend its functionality with our own.
52
+
50
53
51
54
Note that string literals are parsed as expressions, so that if somebody
52
55
calls `noop('a')`, it gets interpreted as `noop(pl.col('a'))`.
@@ -103,9 +106,9 @@ and return a (cheap!) clone of it.
103
106
104
107
## Putting it all together
105
108
106
-
Right, does this all work? Let's make a Python file `run.py` with which to
107
-
test it out. We'll just make a toy dataframe and apply `noop`
108
-
to each column!
109
+
Right, does this all work? Let's edit the Python file `run.py`,
110
+
which we will use for testing. We'll just make a toy dataframe
0 commit comments