Base Expression Types¶
These APIs are shared by both table and column expressions.
Expr
¶
Bases: Immutable
Base expression class.
Source code in ibis/expr/types/core.py
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 67 68 69 70 71 72 73 74 75 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 105 106 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 136 137 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 167 168 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 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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 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 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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
Functions¶
as_table()
¶
Convert an expression to a table.
Source code in ibis/expr/types/core.py
528 529 530 |
|
compile(limit=None, timecontext=None, params=None)
¶
Compile to an execution target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit |
int | None
|
An integer to effect a specific row limit. A value of |
None
|
timecontext |
TimeContext | None
|
Defines a time range of |
None
|
params |
Mapping[ir.Value, Any] | None
|
Mapping of scalar parameter expressions to value |
None
|
Source code in ibis/expr/types/core.py
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 |
|
equals(other)
¶
Return whether this expression is structurally equivalent to other
.
If you want to produce an equality expression, use ==
syntax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Another expression |
required |
Examples:
>>> import ibis
>>> t1 = ibis.table(dict(a="int"), name="t")
>>> t2 = ibis.table(dict(a="int"), name="t")
>>> t1.equals(t2)
True
>>> v = ibis.table(dict(a="string"), name="v")
>>> t1.equals(v)
False
Source code in ibis/expr/types/core.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 |
|
execute(limit='default', timecontext=None, params=None, **kwargs)
¶
Execute an expression against its backend if one exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit |
int | str | None
|
An integer to effect a specific row limit. A value of |
'default'
|
timecontext |
TimeContext | None
|
Defines a time range of |
None
|
params |
Mapping[ir.Value, Any] | None
|
Mapping of scalar parameter expressions to value |
None
|
kwargs |
Any
|
Keyword arguments |
{}
|
Source code in ibis/expr/types/core.py
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 |
|
get_name()
¶
Return the name of this expression.
Source code in ibis/expr/types/core.py
112 113 114 |
|
has_name()
¶
Check whether this expression has an explicit name.
Source code in ibis/expr/types/core.py
108 109 110 |
|
pipe(f, *args, **kwargs)
¶
Compose f
with self
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
If the expression needs to be passed as anything other than the first argument to the function, pass a tuple with the argument name. For example, (f, 'data') if the function f expects a 'data' keyword |
required | |
args |
Any
|
Positional arguments to |
()
|
kwargs |
Any
|
Keyword arguments to |
{}
|
Examples:
>>> import ibis
>>> t = ibis.table([('a', 'int64'), ('b', 'string')], name='t')
>>> f = lambda a: (a + 1).name('a')
>>> g = lambda a: (a * 2).name('a')
>>> result1 = t.a.pipe(f).pipe(g)
>>> result1
r0 := UnboundTable: t
a int64
b string
a: r0.a + 1 * 2
>>> result2 = g(f(t.a)) # equivalent to the above
>>> result1.equals(result2)
True
Returns:
Type | Description |
---|---|
Expr
|
Result type of passed function |
Source code in ibis/expr/types/core.py
162 163 164 165 166 167 168 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 198 199 200 201 202 203 204 205 |
|
to_csv(path, *, params=None, **kwargs)
¶
Write the results of executing the given expression to a CSV file
This method is eager and will execute the associated expression immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
The data source. A string or Path to the CSV file. |
required |
params |
Mapping[ir.Scalar, Any] | None
|
Mapping of scalar parameter expressions to value. |
None
|
**kwargs |
Any
|
Additional keyword arguments passed to pyarrow.csv.CSVWriter |
{}
|
Source code in ibis/expr/types/core.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
to_delta(path, *, params=None, **kwargs)
¶
Write the results of executing the given expression to a Delta Lake table
This method is eager and will execute the associated expression immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
The data source. A string or Path to the Delta Lake table directory. |
required |
params |
Mapping[ir.Scalar, Any] | None
|
Mapping of scalar parameter expressions to value. |
None
|
**kwargs |
Any
|
Additional keyword arguments passed to pyarrow.csv.CSVWriter |
{}
|
Source code in ibis/expr/types/core.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
to_parquet(path, *, params=None, **kwargs)
¶
Write the results of executing the given expression to a parquet file
This method is eager and will execute the associated expression immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str | Path
|
The data source. A string or Path to the parquet file. |
required |
params |
Mapping[ir.Scalar, Any] | None
|
Mapping of scalar parameter expressions to value. |
None
|
**kwargs |
Any
|
Additional keyword arguments passed to pyarrow.parquet.ParquetWriter |
{}
|
Examples:
Write out an expression to a single parquet file.
>>> import ibis
>>> penguins = ibis.examples.penguins.fetch()
>>> penguins.to_parquet("penguins.parquet")
Write out an expression to a hive-partitioned parquet file.
>>> import ibis
>>> penguins = ibis.examples.penguins.fetch()
>>> # partition on single column
>>> penguins.to_parquet("penguins_hive_dir", partition_by="year")
>>> # partition on multiple columns
>>> penguins.to_parquet("penguins_hive_dir", partition_by=("year", "island"))
Hive-partitioned output is currently only supported when using DuckDB
Source code in ibis/expr/types/core.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
to_pyarrow(*, params=None, limit=None, **kwargs)
¶
Execute expression and return results in as a pyarrow table.
This method is eager and will execute the associated expression immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
Mapping[ir.Scalar, Any] | None
|
Mapping of scalar parameter expressions to value. |
None
|
limit |
int | str | None
|
An integer to effect a specific row limit. A value of |
None
|
kwargs |
Any
|
Keyword arguments |
{}
|
Returns:
Type | Description |
---|---|
Table
|
A pyarrow table holding the results of the executed expression. |
Source code in ibis/expr/types/core.py
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 |
|
to_pyarrow_batches(*, limit=None, params=None, chunk_size=1000000, **kwargs)
¶
Execute expression and return a RecordBatchReader.
This method is eager and will execute the associated expression immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit |
int | str | None
|
An integer to effect a specific row limit. A value of |
None
|
params |
Mapping[ir.Value, Any] | None
|
Mapping of scalar parameter expressions to value. |
None
|
chunk_size |
int
|
Maximum number of rows in each returned record batch. |
1000000
|
kwargs |
Any
|
Keyword arguments |
{}
|
Returns:
Type | Description |
---|---|
results
|
RecordBatchReader |
Source code in ibis/expr/types/core.py
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 |
|
to_torch(*, params=None, limit=None, **kwargs)
¶
Execute an expression and return results as a dictionary of torch tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
Mapping[ir.Scalar, Any] | None
|
Parameters to substitute into the expression. |
None
|
limit |
int | str | None
|
An integer to effect a specific row limit. A value of |
None
|
kwargs |
Any
|
Keyword arguments passed into the backend's |
{}
|
Returns:
Type | Description |
---|---|
dict[str, torch.Tensor]
|
A dictionary of torch tensors, keyed by column name. |
Source code in ibis/expr/types/core.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
|
unbind()
¶
Return an expression built on UnboundTable
instead of backend-specific objects.
Source code in ibis/expr/types/core.py
522 523 524 525 526 |
|
visualize(format='svg', *, label_edges=False, verbose=False)
¶
Visualize an expression as a GraphViz graph in the browser.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format |
str
|
Image output format. These are specified by the |
'svg'
|
label_edges |
bool
|
Show operation input names as edge labels |
False
|
verbose |
bool
|
Print the graphviz DOT code to stderr if |
False
|
Raises:
Type | Description |
---|---|
ImportError
|
If |
Source code in ibis/expr/types/core.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|