Generic Expression APIs¶
These expressions are available on scalars and columns of any element type.
Value
¶
Bases: Expr
Base class for a data generating expression having a known type.
Source code in ibis/expr/types/generic.py
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 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 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
|
Functions¶
as_table()
¶
Promote the expression to a table.
Returns:
Type | Description |
---|---|
Table
|
A table expression |
Examples:
>>> t = ibis.table(dict(a="str"), name="t")
>>> expr = t.a.length().name("len").as_table()
>>> expected = t.select(len=t.a.length())
>>> expr.equals(expected)
True
Source code in ibis/expr/types/generic.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
|
asc()
¶
Sort an expression ascending.
Source code in ibis/expr/types/generic.py
857 858 859 |
|
between(lower, upper)
¶
Check if this expression is between lower
and upper
, inclusive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower |
Value
|
Lower bound |
required |
upper |
Value
|
Upper bound |
required |
Returns:
Type | Description |
---|---|
BooleanValue
|
Expression indicating membership in the provided range |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.bill_length_mm.between(35, 38)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Between(bill_length_mm, 35, 38) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├─────────────────────────────────┤
│ False │
│ False │
│ False │
│ NULL │
│ True │
└─────────────────────────────────┘
Source code in ibis/expr/types/generic.py
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 |
|
case()
¶
Create a SimpleCaseBuilder to chain multiple if-else statements.
Add new search expressions with the .when()
method. These must be
comparable with this column expression. Conclude by calling .end()
Returns:
Type | Description |
---|---|
SimpleCaseBuilder
|
A case builder |
Examples:
>>> import ibis
>>> t = ibis.table([('string_col', 'string')], name='t')
>>> expr = t.string_col
>>> case_expr = (expr.case()
... .when('a', 'an a')
... .when('b', 'a b')
... .else_('null or (not a and not b)')
... .end())
>>> case_expr
r0 := UnboundTable: t
string_col string
SimpleCase(...)
Source code in ibis/expr/types/generic.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
|
cases(case_result_pairs, default=None)
¶
Create a case expression in one shot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
case_result_pairs |
Iterable[tuple[ir.BooleanValue, Value]]
|
Conditional-result pairs |
required |
default |
Value | None
|
Value to return if none of the case conditions are true |
None
|
Returns:
Type | Description |
---|---|
Value
|
Value expression |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values": [1, 2, 1, 2, 3, 2, 4]})
>>> t
┏━━━━━━━━┓
┃ values ┃
┡━━━━━━━━┩
│ int64 │
├────────┤
│ 1 │
│ 2 │
│ 1 │
│ 2 │
│ 3 │
│ 2 │
│ 4 │
└────────┘
>>> number_letter_map = ((1, "a"), (2, "b"), (3, "c"))
>>> t.values.cases(number_letter_map, default="unk").name("replace")
┏━━━━━━━━━┓
┃ replace ┃
┡━━━━━━━━━┩
│ string │
├─────────┤
│ a │
│ b │
│ a │
│ b │
│ c │
│ b │
│ unk │
└─────────┘
Source code in ibis/expr/types/generic.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
|
cast(target_type)
¶
Cast expression to indicated data type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_type |
dt.DataType
|
Type to cast to |
required |
Returns:
Type | Description |
---|---|
Value
|
Casted expression |
Examples:
>>> import ibis
>>> ibis.options.interactive = False
>>> t = ibis.table(dict(a="int64"), name="t")
>>> t.a.cast("float")
r0 := UnboundTable: t
a int64
Cast(a, float64): Cast(r0.a, to=float64)
Source code in ibis/expr/types/generic.py
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 |
|
coalesce(*args)
¶
Return the first non-null value from args
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Value
|
Arguments from which to choose the first non-null value |
()
|
Returns:
Type | Description |
---|---|
Value
|
Coalesced expression |
Examples:
>>> import ibis
>>> ibis.coalesce(None, 4, 5).name("x")
x: Coalesce(...)
Source code in ibis/expr/types/generic.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
collect(where=None)
¶
Aggregate this expression's elements into an array.
This function is called array_agg
, list_agg
, or list
in other systems.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter to apply before aggregation |
None
|
Returns:
Type | Description |
---|---|
ArrayScalar
|
Collected array |
Examples:
Basic collect usage
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"key": list("aaabb"), "value": [1, 2, 3, 4, 5]})
>>> t
┏━━━━━━━━┳━━━━━━━┓
┃ key ┃ value ┃
┡━━━━━━━━╇━━━━━━━┩
│ string │ int64 │
├────────┼───────┤
│ a │ 1 │
│ a │ 2 │
│ a │ 3 │
│ b │ 4 │
│ b │ 5 │
└────────┴───────┘
>>> t.value.collect()
[1, 2, 3, 4, 5]
>>> type(t.value.collect())
<class 'ibis.expr.types.arrays.ArrayScalar'>
Collect elements per group
>>> t.group_by("key").agg(v=lambda t: t.value.collect())
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ key ┃ v ┃
┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ string │ array<int64> │
├────────┼──────────────────────┤
│ a │ [1, 2, ... +1] │
│ b │ [4, 5] │
└────────┴──────────────────────┘
Collect elements per group using a filter
>>> t.group_by("key").agg(v=lambda t: t.value.collect(where=t.value > 1))
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ key ┃ v ┃
┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ string │ array<int64> │
├────────┼──────────────────────┤
│ a │ [2, 3] │
│ b │ [4, 5] │
└────────┴──────────────────────┘
Source code in ibis/expr/types/generic.py
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
|
desc()
¶
Sort an expression descending.
Source code in ibis/expr/types/generic.py
861 862 863 |
|
fillna(fill_value)
¶
Replace any null values with the indicated fill value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fill_value |
Scalar
|
Value with which to replace |
required |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.sex
┏━━━━━━━━┓
┃ sex ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ male │
│ female │
│ female │
│ NULL │
│ female │
└────────┘
>>> t.sex.fillna("unrecorded").name("sex")
┏━━━━━━━━━━━━┓
┃ sex ┃
┡━━━━━━━━━━━━┩
│ string │
├────────────┤
│ male │
│ female │
│ female │
│ unrecorded │
│ female │
└────────────┘
Returns:
Type | Description |
---|---|
Value
|
|
Source code in ibis/expr/types/generic.py
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 |
|
greatest(*args)
¶
Compute the largest value among the supplied arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
ir.Value
|
Arguments to choose from |
()
|
Returns:
Type | Description |
---|---|
Value
|
Maximum of the passed arguments |
Source code in ibis/expr/types/generic.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
group_concat(sep=',', where=None)
¶
Concatenate values using the indicated separator to produce a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sep |
str
|
Separator will be used to join strings |
','
|
where |
ir.BooleanValue | None
|
Filter expression |
None
|
Returns:
Type | Description |
---|---|
StringScalar
|
Concatenated string expression |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t[["bill_length_mm", "bill_depth_mm"]]
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ bill_length_mm ┃ bill_depth_mm ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ float64 │ float64 │
├────────────────┼───────────────┤
│ 39.1 │ 18.7 │
│ 39.5 │ 17.4 │
│ 40.3 │ 18.0 │
│ nan │ nan │
│ 36.7 │ 19.3 │
└────────────────┴───────────────┘
>>> t.bill_length_mm.group_concat()
'39.1,39.5,40.3,36.7'
>>> t.bill_length_mm.group_concat(sep=": ")
'39.1: 39.5: 40.3: 36.7'
>>> t.bill_length_mm.group_concat(sep=": ", where=t.bill_depth_mm > 18)
'39.1: 36.7'
Source code in ibis/expr/types/generic.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
|
hash()
¶
Compute an integer hash value.
The hashing function used is backend-dependent.
Returns:
Type | Description |
---|---|
IntegerValue
|
The hash value of |
Source code in ibis/expr/types/generic.py
67 68 69 70 71 72 73 74 75 76 77 |
|
identical_to(other)
¶
Return whether this expression is identical to other.
Corresponds to IS NOT DISTINCT FROM
in SQL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Value
|
Expression to compare to |
required |
Returns:
Type | Description |
---|---|
BooleanValue
|
Whether this expression is not distinct from |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> one = ibis.literal(1)
>>> two = ibis.literal(2)
>>> two.identical_to(one + one)
True
Source code in ibis/expr/types/generic.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
|
isin(values)
¶
Check whether this expression's values are in values
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
Value | Sequence[Value]
|
Values or expression to check for membership |
required |
Returns:
Type | Description |
---|---|
BooleanValue
|
Expression indicating membership |
Examples:
Check whether a column's values are contained in a sequence
>>> import ibis
>>> table = ibis.table(dict(string_col='string'), name="t")
>>> table.string_col.isin(['foo', 'bar', 'baz'])
r0 := UnboundTable: t
string_col string
Contains(string_col): Contains(...)
Check whether a column's values are contained in another table's column
>>> table2 = ibis.table(dict(other_string_col='string'), name="t2")
>>> table.string_col.isin(table2.other_string_col)
r0 := UnboundTable: t
string_col string
r1 := UnboundTable: t2
other_string_col string
Contains(string_col, other_string_col): Contains(...)
Source code in ibis/expr/types/generic.py
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 |
|
isnull()
¶
Return whether this expression is NULL.
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.bill_depth_mm
┏━━━━━━━━━━━━━━━┓
┃ bill_depth_mm ┃
┡━━━━━━━━━━━━━━━┩
│ float64 │
├───────────────┤
│ 18.7 │
│ 17.4 │
│ 18.0 │
│ nan │
│ 19.3 │
└───────────────┘
>>> t.bill_depth_mm.isnull()
┏━━━━━━━━━━━━━━━━━━━━━━━┓
┃ IsNull(bill_depth_mm) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├───────────────────────┤
│ False │
│ False │
│ False │
│ True │
│ False │
└───────────────────────┘
Source code in ibis/expr/types/generic.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
|
least(*args)
¶
Compute the smallest value among the supplied arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
ir.Value
|
Arguments to choose from |
()
|
Returns:
Type | Description |
---|---|
Value
|
Minimum of the passed arguments |
Source code in ibis/expr/types/generic.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
name(name)
¶
Rename an expression to name
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
The new name of the expression |
required |
Returns:
Type | Description |
---|---|
Value
|
|
Examples:
>>> import ibis
>>> t = ibis.table(dict(a="int64"), name="t")
>>> t.a.name("b")
r0 := UnboundTable: t
a int64
b: r0.a
Source code in ibis/expr/types/generic.py
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 |
|
notin(values)
¶
Check whether this expression's values are not in values
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
Value | Sequence[Value]
|
Values or expression to check for lack of membership |
required |
Returns:
Type | Description |
---|---|
BooleanValue
|
Whether |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.bill_depth_mm
┏━━━━━━━━━━━━━━━┓
┃ bill_depth_mm ┃
┡━━━━━━━━━━━━━━━┩
│ float64 │
├───────────────┤
│ 18.7 │
│ 17.4 │
│ 18.0 │
│ nan │
│ 19.3 │
└───────────────┘
>>> t.bill_depth_mm.notin([18.7, 18.1])
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ NotContains(bill_depth_mm) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├────────────────────────────┤
│ False │
│ True │
│ True │
│ NULL │
│ True │
└────────────────────────────┘
Source code in ibis/expr/types/generic.py
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 |
|
notnull()
¶
Return whether this expression is not NULL.
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.bill_depth_mm
┏━━━━━━━━━━━━━━━┓
┃ bill_depth_mm ┃
┡━━━━━━━━━━━━━━━┩
│ float64 │
├───────────────┤
│ 18.7 │
│ 17.4 │
│ 18.0 │
│ nan │
│ 19.3 │
└───────────────┘
>>> t.bill_depth_mm.notnull()
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ NotNull(bill_depth_mm) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━┩
│ boolean │
├────────────────────────┤
│ True │
│ True │
│ True │
│ False │
│ True │
└────────────────────────┘
Source code in ibis/expr/types/generic.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
|
nullif(null_if_expr)
¶
Set values to null if they equal the values null_if_expr
.
Commonly use to avoid divide-by-zero problems by replacing zero with
NULL
in the divisor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
null_if_expr |
Value
|
Expression indicating what values should be NULL |
required |
Returns:
Type | Description |
---|---|
Value
|
Value expression |
Source code in ibis/expr/types/generic.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
over(window=None, *, rows=None, range=None, group_by=None, order_by=None)
¶
Construct a window expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window |
Window specification |
None
|
|
rows |
Whether to use the |
None
|
|
range |
Whether to use the |
None
|
|
group_by |
Grouping key |
None
|
|
order_by |
Ordering key |
None
|
Returns:
Type | Description |
---|---|
Value
|
A window function expression |
Source code in ibis/expr/types/generic.py
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 531 532 533 534 |
|
substitute(value, replacement=None, else_=None)
¶
Replace values given in values
with replacement
.
This is similar to the pandas replace
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Value | dict
|
Expression or dict. |
required |
replacement |
Value | None
|
If an expression is passed to value, this must be passed. |
None
|
else_ |
Value | None
|
If an original value does not match |
None
|
Returns:
Type | Description |
---|---|
Value
|
Replaced values |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.island.value_counts()
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ island ┃ island_count ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ string │ int64 │
├───────────┼──────────────┤
│ Torgersen │ 52 │
│ Biscoe │ 168 │
│ Dream │ 124 │
└───────────┴──────────────┘
>>> t.island.substitute({"Torgersen": "torg", "Biscoe": "bisc"}).value_counts()
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ SimpleCase(island, island) ┃ SimpleCase(island, island)_count ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ string │ int64 │
├────────────────────────────┼──────────────────────────────────┤
│ torg │ 52 │
│ bisc │ 168 │
│ Dream │ 124 │
└────────────────────────────┴──────────────────────────────────┘
Source code in ibis/expr/types/generic.py
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 |
|
to_pandas(**kwargs)
¶
Convert a column expression to a pandas Series or scalar object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Same as keyword arguments to |
{}
|
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch().limit(5)
>>> t.to_pandas()
species island bill_length_mm ... body_mass_g sex year
0 Adelie Torgersen 39.1 ... 3750.0 male 2007
1 Adelie Torgersen 39.5 ... 3800.0 female 2007
2 Adelie Torgersen 40.3 ... 3250.0 female 2007
3 Adelie Torgersen NaN ... NaN None 2007
4 Adelie Torgersen 36.7 ... 3450.0 female 2007
[5 rows x 8 columns]
Source code in ibis/expr/types/generic.py
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
|
try_cast(target_type)
¶
Try cast expression to indicated data type. If the cast fails for a row, the value is returned as null or NaN depending on target_type and backend behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_type |
dt.DataType
|
Type to try cast to |
required |
Returns:
Type | Description |
---|---|
Value
|
Casted expression |
Examples:
>>> import ibis
>>> from ibis import _
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"numbers": [1, 2, 3, 4], "strings": ["1.0", "2", "hello", "world"]})
>>> t
┏━━━━━━━━━┳━━━━━━━━━┓
┃ numbers ┃ strings ┃
┡━━━━━━━━━╇━━━━━━━━━┩
│ int64 │ string │
├─────────┼─────────┤
│ 1 │ 1.0 │
│ 2 │ 2 │
│ 3 │ hello │
│ 4 │ world │
└─────────┴─────────┘
>>> t = t.mutate(numbers_to_strings=_.numbers.try_cast("string"))
>>> t = t.mutate(strings_to_numbers=_.strings.try_cast("int"))
>>> t
┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┓
┃ numbers ┃ strings ┃ numbers_to_strings ┃ strings_to_numbers ┃
┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━┩
│ int64 │ string │ string │ int64 │
├─────────┼─────────┼────────────────────┼────────────────────┤
│ 1 │ 1.0 │ 1 │ 1 │
│ 2 │ 2 │ 2 │ 2 │
│ 3 │ hello │ 3 │ NULL │
│ 4 │ world │ 4 │ NULL │
└─────────┴─────────┴────────────────────┴────────────────────┘
Source code in ibis/expr/types/generic.py
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 |
|
type()
¶
Return the [DataType] of this expression.
Source code in ibis/expr/types/generic.py
63 64 65 |
|
typeof()
¶
Return the data type of the expression.
The values of the returned strings are necessarily backend dependent.
Returns:
Type | Description |
---|---|
StringValue
|
A string indicating the type of the value |
Source code in ibis/expr/types/generic.py
221 222 223 224 225 226 227 228 229 230 231 |
|
Column
¶
Bases: Value
, _FixedTextJupyterMixin
Source code in ibis/expr/types/generic.py
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 |
|
Functions¶
approx_median(where=None)
¶
Return an approximate of the median of self
.
The result may or may not be exact
Whether the result is an approximation depends on the backend.
Do not depend on the results being exact
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
An approximation of the median of |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.body_mass_g.approx_median()
4030
>>> t.body_mass_g.approx_median(where=t.species == "Chinstrap")
3700
Source code in ibis/expr/types/generic.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 |
|
approx_nunique(where=None)
¶
Return the approximate number of distinct elements in self
.
The result may or may not be exact
Whether the result is an approximation depends on the backend.
Do not depend on the results being exact
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
An approximate count of the distinct elements of |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.body_mass_g.approx_nunique()
94
>>> t.body_mass_g.approx_nunique(where=t.species == "Adelie")
55
Source code in ibis/expr/types/generic.py
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 |
|
arbitrary(where=None, how='first')
¶
Select an arbitrary value in a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
A filter expression |
None
|
how |
Literal['first', 'last', 'heavy']
|
The method to use for selecting the element.
|
'first'
|
Returns:
Type | Description |
---|---|
Scalar
|
An expression |
Source code in ibis/expr/types/generic.py
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
|
argmax(key, where=None)
¶
Return the value of self
that maximizes key
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
The value of |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.species.argmax(t.body_mass_g)
'Gentoo'
>>> t.species.argmax(t.body_mass_g, where=t.island == "Dream")
'Chinstrap'
Source code in ibis/expr/types/generic.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
|
argmin(key, where=None)
¶
Return the value of self
that minimizes key
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
The value of |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.species.argmin(t.body_mass_g)
'Chinstrap'
>>> t.species.argmin(t.body_mass_g, where=t.island == "Biscoe")
'Adelie'
Source code in ibis/expr/types/generic.py
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
|
count(where=None)
¶
Compute the number of rows in an expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter expression |
None
|
Returns:
Type | Description |
---|---|
IntegerScalar
|
Number of elements in an expression |
Source code in ibis/expr/types/generic.py
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 |
|
cume_dist()
¶
Return the cumulative distribution over a window.
Source code in ibis/expr/types/generic.py
1501 1502 1503 |
|
cummax()
¶
Return the cumulative max over a window.
Source code in ibis/expr/types/generic.py
1509 1510 1511 |
|
cummin()
¶
Return the cumulative min over a window.
Source code in ibis/expr/types/generic.py
1505 1506 1507 |
|
dense_rank()
¶
Position of first element within each group of equal values.
Values are returned in sorted order and duplicate values are ignored.
Equivalent to SQL's DENSE_RANK()
.
Returns:
Type | Description |
---|---|
IntegerColumn
|
The rank |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values": [1, 2, 1, 2, 3, 2]})
>>> t.mutate(rank=t.values.dense_rank())
┏━━━━━━━━┳━━━━━━━┓
┃ values ┃ rank ┃
┡━━━━━━━━╇━━━━━━━┩
│ int64 │ int64 │
├────────┼───────┤
│ 1 │ 0 │
│ 1 │ 0 │
│ 2 │ 1 │
│ 2 │ 1 │
│ 2 │ 1 │
│ 3 │ 2 │
└────────┴───────┘
Source code in ibis/expr/types/generic.py
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 |
|
first(where=None)
¶
Return the first value of a column.
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"chars": ["a", "b", "c", "d"]})
>>> t
┏━━━━━━━━┓
┃ chars ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ a │
│ b │
│ c │
│ d │
└────────┘
>>> t.chars.first()
'a'
>>> t.chars.first(where=t.chars != 'a')
'b'
Source code in ibis/expr/types/generic.py
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 |
|
lag(offset=None, default=None)
¶
Return the row located at offset
rows before the current row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int | ir.IntegerValue | None
|
Index of row to select |
None
|
default |
Value | None
|
Value used if no row exists at |
None
|
Source code in ibis/expr/types/generic.py
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 |
|
last(where=None)
¶
Return the last value of a column.
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"chars": ["a", "b", "c", "d"]})
>>> t
┏━━━━━━━━┓
┃ chars ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ a │
│ b │
│ c │
│ d │
└────────┘
>>> t.chars.last()
'd'
>>> t.chars.last(where=t.chars != 'd')
'c'
Source code in ibis/expr/types/generic.py
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 |
|
lead(offset=None, default=None)
¶
Return the row located at offset
rows after the current row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int | ir.IntegerValue | None
|
Index of row to select |
None
|
default |
Value | None
|
Value used if no row exists at |
None
|
Source code in ibis/expr/types/generic.py
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
|
max(where=None)
¶
Return the maximum of a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
The maximum value in |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.body_mass_g.max()
6300
>>> t.body_mass_g.max(where=t.species == "Chinstrap")
4800
Source code in ibis/expr/types/generic.py
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
|
min(where=None)
¶
Return the minimum of a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
The minimum value in |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.body_mass_g.min()
2700
>>> t.body_mass_g.min(where=t.species == "Adelie")
2850
Source code in ibis/expr/types/generic.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
|
mode(where=None)
¶
Return the mode of a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter in values when |
None
|
Returns:
Type | Description |
---|---|
Scalar
|
The mode of |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.body_mass_g.mode()
3800
>>> t.body_mass_g.mode(where=(t.species == "Gentoo") & (t.sex == "male"))
5550
Source code in ibis/expr/types/generic.py
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
|
nth(n)
¶
Return the n
th value (0-indexed) over a window.
.nth(0)
is equivalent to .first()
. Negative will result in NULL
.
If the value of n
is greater than the number of rows in the window,
NULL
will be returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int | ir.IntegerValue
|
Desired rank value |
required |
Returns:
Type | Description |
---|---|
Column
|
The nth value over a window |
Source code in ibis/expr/types/generic.py
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 |
|
ntile(buckets)
¶
Return the integer number of a partitioning of the column values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buckets |
int | ir.IntegerValue
|
Number of buckets to partition into |
required |
Source code in ibis/expr/types/generic.py
1545 1546 1547 1548 1549 1550 1551 1552 1553 |
|
nunique(where=None)
¶
Compute the number of distinct rows in an expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
where |
ir.BooleanValue | None
|
Filter expression |
None
|
Returns:
Type | Description |
---|---|
IntegerScalar
|
Number of distinct elements in an expression |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t.body_mass_g.nunique()
94
>>> t.body_mass_g.nunique(where=t.species == "Adelie")
55
Source code in ibis/expr/types/generic.py
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 |
|
percent_rank()
¶
Return the relative rank of the values in the column.
Source code in ibis/expr/types/generic.py
1497 1498 1499 |
|
rank()
¶
Compute position of first element within each equal-value group in sorted order.
Equivalent to SQL's RANK()
window function.
Returns:
Type | Description |
---|---|
Int64Column
|
The min rank |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"values": [1, 2, 1, 2, 3, 2]})
>>> t.mutate(rank=t.values.rank())
┏━━━━━━━━┳━━━━━━━┓
┃ values ┃ rank ┃
┡━━━━━━━━╇━━━━━━━┩
│ int64 │ int64 │
├────────┼───────┤
│ 1 │ 0 │
│ 1 │ 0 │
│ 2 │ 2 │
│ 2 │ 2 │
│ 2 │ 2 │
│ 3 │ 5 │
└────────┴───────┘
Source code in ibis/expr/types/generic.py
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 |
|
topk(k, by=None)
¶
Return a "top k" expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
int
|
Return this number of rows |
required |
by |
ir.Value | None
|
An expression. Defaults to |
None
|
Returns:
Type | Description |
---|---|
TableExpr
|
A top-k expression |
Source code in ibis/expr/types/generic.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
|
value_counts()
¶
Compute a frequency table.
Returns:
Type | Description |
---|---|
Table
|
Frequency table expression |
Examples:
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable({"chars": char} for char in "aabcddd")
>>> t
┏━━━━━━━━┓
┃ chars ┃
┡━━━━━━━━┩
│ string │
├────────┤
│ a │
│ a │
│ b │
│ c │
│ d │
│ d │
│ d │
└────────┘
>>> t.chars.value_counts()
┏━━━━━━━━┳━━━━━━━━━━━━━┓
┃ chars ┃ chars_count ┃
┡━━━━━━━━╇━━━━━━━━━━━━━┩
│ string │ int64 │
├────────┼─────────────┤
│ a │ 2 │
│ b │ 1 │
│ c │ 1 │
│ d │ 3 │
└────────┴─────────────┘
Source code in ibis/expr/types/generic.py
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 |
|
Scalar
¶
Bases: Value
Source code in ibis/expr/types/generic.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
|
Functions¶
as_table()
¶
Promote the scalar expression to a table.
Returns:
Type | Description |
---|---|
Table
|
A table expression |
Examples:
Promote an aggregation to a table
>>> import ibis
>>> import ibis.expr.types as ir
>>> t = ibis.table(dict(a="str"), name="t")
>>> expr = t.a.length().sum().name("len").as_table()
>>> isinstance(expr, ir.Table)
True
Promote a literal value to a table
>>> import ibis.expr.types as ir
>>> lit = ibis.literal(1).name("a").as_table()
>>> isinstance(lit, ir.Table)
True
Source code in ibis/expr/types/generic.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 |
|