|
5 | 5 |
|
6 | 6 | from public import public
|
7 | 7 |
|
| 8 | +from ibis.common.exceptions import IbisTypeError |
8 | 9 | from ibis.expr.types.core import _binop
|
9 | 10 | from ibis.expr.types.generic import Column, Scalar, Value
|
10 | 11 |
|
@@ -765,6 +766,75 @@ def convert_base(
|
765 | 766 |
|
766 | 767 | return ops.BaseConvert(self, from_base, to_base).to_expr()
|
767 | 768 |
|
| 769 | + def __and__(self, other: IntegerValue) -> IntegerValue | NotImplemented: |
| 770 | + """Bitwise and `self` with `other`.""" |
| 771 | + from ibis.expr import operations as ops |
| 772 | + |
| 773 | + return _binop(ops.BitwiseAnd, self, other) |
| 774 | + |
| 775 | + __rand__ = __and__ |
| 776 | + |
| 777 | + def __or__(self, other: IntegerValue) -> IntegerValue | NotImplemented: |
| 778 | + """Bitwise or `self` with `other`.""" |
| 779 | + from ibis.expr import operations as ops |
| 780 | + |
| 781 | + return _binop(ops.BitwiseOr, self, other) |
| 782 | + |
| 783 | + __ror__ = __or__ |
| 784 | + |
| 785 | + def __xor__(self, other: IntegerValue) -> IntegerValue | NotImplemented: |
| 786 | + """Bitwise xor `self` with `other`.""" |
| 787 | + from ibis.expr import operations as ops |
| 788 | + |
| 789 | + return _binop(ops.BitwiseXor, self, other) |
| 790 | + |
| 791 | + __rxor__ = __xor__ |
| 792 | + |
| 793 | + def __lshift__(self, other: IntegerValue) -> IntegerValue | NotImplemented: |
| 794 | + """Bitwise left shift `self` with `other`.""" |
| 795 | + from ibis.expr import operations as ops |
| 796 | + |
| 797 | + return _binop(ops.BitwiseLeftShift, self, other) |
| 798 | + |
| 799 | + def __rlshift__( |
| 800 | + self, other: IntegerValue |
| 801 | + ) -> IntegerValue | NotImplemented: |
| 802 | + """Bitwise left shift `self` with `other`.""" |
| 803 | + from ibis.expr import operations as ops |
| 804 | + |
| 805 | + return _binop(ops.BitwiseLeftShift, other, self) |
| 806 | + |
| 807 | + def __rshift__(self, other: IntegerValue) -> IntegerValue | NotImplemented: |
| 808 | + """Bitwise right shift `self` with `other`.""" |
| 809 | + from ibis.expr import operations as ops |
| 810 | + |
| 811 | + return _binop(ops.BitwiseRightShift, self, other) |
| 812 | + |
| 813 | + def __rrshift__( |
| 814 | + self, other: IntegerValue |
| 815 | + ) -> IntegerValue | NotImplemented: |
| 816 | + """Bitwise right shift `self` with `other`.""" |
| 817 | + from ibis.expr import operations as ops |
| 818 | + |
| 819 | + return _binop(ops.BitwiseRightShift, other, self) |
| 820 | + |
| 821 | + def __invert__(self) -> IntegerValue: |
| 822 | + """Bitwise not of `self`. |
| 823 | +
|
| 824 | + Returns |
| 825 | + ------- |
| 826 | + IntegerValue |
| 827 | + Inverted bits of `self`. |
| 828 | + """ |
| 829 | + from ibis.expr import operations as ops |
| 830 | + |
| 831 | + try: |
| 832 | + node = ops.BitwiseNot(self) |
| 833 | + except (IbisTypeError, NotImplementedError): |
| 834 | + return NotImplemented |
| 835 | + else: |
| 836 | + return node.to_expr() |
| 837 | + |
768 | 838 |
|
769 | 839 | @public
|
770 | 840 | class IntegerScalar(NumericScalar, IntegerValue):
|
|
0 commit comments