DataFrameMethod
laktory.models.dataframe.DataFrameMethod
¤
Bases: BaseModel, PipelineChild
Definition of a DataFrame method to be applied. Both native and Narwhals API are supported.
Examples:
import polars as pl
import laktory as lk
df0 = pl.DataFrame(
{
"x": [1.1, 2.2, 3.3],
}
)
m1 = lk.models.DataFrameMethod(
func_name="with_columns",
func_kwargs={"xr": "nw.col('x').round()"},
dataframe_api="NARWHALS",
)
df = m1.execute(df0)
m2 = lk.models.DataFrameMethod(
func_name="select", func_args=["pl.col('x').sqrt()"], dataframe_api="NATIVE"
)
df = m2.execute(df0)
print(df.to_native())
'''
| x |
|----------|
| 1.048809 |
| 1.48324 |
| 1.81659 |
'''
| PARAMETER | DESCRIPTION |
|---|---|
func_args
|
Arguments passed to method. Use
TYPE:
|
func_kwargs
|
Keyword arguments passed to method. Use
TYPE:
|
func_name
|
DataFrame method or attribute name (e.g. 'select', 'filter', 'dt.strftime'). Resolved as an attribute of the DataFrame object.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute method on provided DataFrame |
| ATTRIBUTE | DESCRIPTION |
|---|---|
data_sources |
Get PipelineNodeDataSource objects for each {nodes.X} reference in func_args/func_kwargs.
TYPE:
|
upstream_node_names |
Pipeline node names referenced via {nodes.X} in func_args / func_kwargs.
TYPE:
|
data_sources
property
¤
Get PipelineNodeDataSource objects for each {nodes.X} reference in func_args/func_kwargs.
upstream_node_names
property
¤
Pipeline node names referenced via {nodes.X} in func_args / func_kwargs.
execute(df, named_dfs=None)
¤
Execute method on provided DataFrame df.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Input dataframe
TYPE:
|
named_dfs
|
Pre-loaded named DataFrames available for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Output dataframe
|
|
Source code in laktory/models/dataframe/dataframemethod.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |