Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/docs/source/src/python/polars-cloud/plugins.py
6940 views
1
"""
2
import polars as pl
3
import polars_cloud as pc
4
5
# --8<-- [start:set-context]
6
ctx = pc.ComputeContext(workspace="your-workspace",
7
cpus=12,
8
memory=12,
9
requirements="requirements.txt"
10
)
11
# --8<-- [end:set-context]
12
13
14
# --8<-- [start:run-plugin]
15
16
import polars_xdt as xdt
17
18
lf = pl.LazyFrame(
19
{
20
"local_dt": [
21
datetime(2020, 10, 10, 1),
22
datetime(2020, 10, 10, 2),
23
datetime(2020, 10, 9, 20),
24
],
25
"timezone": [
26
"Europe/London",
27
"Africa/Kigali",
28
"America/New_York",
29
],
30
}
31
)
32
33
query = lf.with_columns(
34
xdt.from_local_datetime(
35
"local_dt", pl.col("timezone"), "UTC"
36
).alias("date")
37
)
38
39
query.remote(ctx).show()
40
# --8<-- [end:run-plugin]
41
42
43
# --8<-- [start:run-udf]
44
import numpy as numpy
45
46
lf = pl.LazyFrame(
47
{
48
"keys": ["a", "a", "b", "b"],
49
"values": [10, 7, 1, 23],
50
}
51
)
52
53
q = lf.select(
54
pl.col("values").map_batches(np.log, return_dtype=pl.Float64)
55
)
56
57
q.remote(ctx).show()
58
59
# --8<-- [end:run-udf]
60
61
"""
62
63