register_lazyframe_namespace
laktory.api.register_lazyframe_namespace(name)
¤
Decorator for registering custom method to a Narwhals LazyFrame.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the namespace
TYPE:
|
Examples:
import narwhals as nw
import polars as pl
import laktory as lk
@lk.api.register_lazyframe_namespace("custom")
class CustomNamespace:
def __init__(self, _df):
self._df = _df
def with_x2(self):
return self._df.with_columns(x2=nw.col("x") * 2)
df = nw.from_native(pl.DataFrame({"x": [0, 1]}).lazy())
df = df.custom.with_x2()
print(df.collect().sort("x"))
'''
┌──────────────────┐
|Narwhals DataFrame|
|------------------|
| | x | x2 | |
| |---|----| |
| | 0 | 0 | |
| | 1 | 2 | |
└──────────────────┘
'''
References
Source code in laktory/narwhals_ext/namespace.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |