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. A
TYPE:
|
func_kwargs
|
Keyword arguments passed to method. A
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 all sources feeding the DataFrame Method
TYPE:
|
upstream_node_names |
Pipeline node names required to apply transformer node.
TYPE:
|
data_sources
property
¤
Get all sources feeding the DataFrame Method
upstream_node_names
property
¤
Pipeline node names required to apply transformer node.
execute(df)
¤
Execute method on provided DataFrame df.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Input dataframe
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Output dataframe
|
|
Source code in laktory/models/dataframe/dataframemethod.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 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 | |