Scalar Functions#
Daft provides a set of built-in operations that can be applied to DataFrame columns. This page provides an overview of all the functions provided by Daft. Learn more about scalar or column functions in Daft User Guide.
functions #
Functions:
Name | Description |
---|---|
columns_avg | Average values across columns. Akin to |
columns_max | Find the maximum value across columns. |
columns_mean | Average values across columns. Akin to |
columns_min | Find the minimum value across columns. |
columns_sum | Sum values across columns. |
format | Format a string using the given arguments. |
monotonically_increasing_id | Generates a column of monotonically increasing unique ids. |
columns_avg #
columns_avg(*exprs: Expression | str) -> Expression
Average values across columns. Akin to columns_mean
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exprs | Expression | str | The columns to average across. | () |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Source code in daft/functions/functions.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
columns_max #
columns_max(*exprs: Expression | str) -> Expression
Find the maximum value across columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exprs | Expression | str | The columns to find the maximum of. | () |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Source code in daft/functions/functions.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
columns_mean #
columns_mean(*exprs: Expression | str) -> Expression
Average values across columns. Akin to columns_avg
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exprs | Expression | str | The columns to average. | () |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Source code in daft/functions/functions.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
columns_min #
columns_min(*exprs: Expression | str) -> Expression
Find the minimum value across columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exprs | Expression | str | The columns to find the minimum of. | () |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Source code in daft/functions/functions.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
columns_sum #
columns_sum(*exprs: Expression | str) -> Expression
Sum values across columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exprs | Expression | str | The columns to sum. | () |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Source code in daft/functions/functions.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
format #
format(
f_string: str, *args: Expression | str
) -> Expression
Format a string using the given arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f_string | str | The format string. | required |
*args | Expression | str | The arguments to format the string with. | () |
Returns:
Name | Type | Description |
---|---|---|
Expression | Expression | A string expression with the formatted result. |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Source code in daft/functions/functions.py
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 |
|
monotonically_increasing_id #
monotonically_increasing_id() -> Expression
Generates a column of monotonically increasing unique ids.
The implementation puts the partition number in the upper 28 bits, and the row number in each partition in the lower 36 bits. This allows for 2^28 ≈ 268 million partitions and 2^40 ≈ 68 billion rows per partition.
Returns:
Name | Type | Description |
---|---|---|
Expression | Expression | An expression that generates monotonically increasing IDs |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Source code in daft/functions/functions.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
llm_generate #
Functions:
Name | Description |
---|---|
llm_generate | A UDF for running LLM inference over an input column of strings. |
llm_generate #
llm_generate(
input_column: Expression,
model: str = "facebook/opt-125m",
provider: Literal["vllm"] = "vllm",
concurrency: int = 1,
batch_size: int = 1024,
num_cpus: int | None = None,
num_gpus: int | None = None,
**generation_config: dict[str, Any],
) -> Expression
A UDF for running LLM inference over an input column of strings.
This UDF provides a flexible interface for text generation using various LLM providers. By default, it uses vLLM for efficient local inference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | str | str, default="facebook/opt-125m" The model identifier to use for generation | 'facebook/opt-125m' |
provider | Literal['vllm'] | str, default="vllm" The LLM provider to use for generation. Supported values: "vllm" | 'vllm' |
concurrency | int | int, default=1 The number of concurrent instances of the model to run | 1 |
batch_size | int | int, default=1024 The batch size for the UDF | 1024 |
num_cpus | int | None | float, default=None The number of CPUs to use for the UDF | None |
num_gpus | int | None | float, default=None The number of GPUs to use for the UDF | None |
generation_config | dict[str, Any] | dict, default={} Configuration parameters for text generation (e.g., temperature, max_tokens) | {} |
Examples:
1 2 3 4 5 6 |
|
Note
Make sure the required provider packages are installed (e.g. vllm, transformers).
Source code in daft/functions/llm_generate.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|