def test_bitwise_operations(self): from pyspark.sql import functions row = Row(a=170, b=75) df = self.spark.createDataFrame([row]) result = df.select(df.a.bitwiseAND(df.b)).collect()[0].asDict() self.assertEqual(170 & 75, result['(a & b)']) result = df.select(df.a.bitwiseOR(df.b)).collect()[0].asDict() self.assertEqual(170 | 75, result['(a | b)']) result = df.select(df.a.bitwiseXOR(df.b)).collect()[0].asDict() self.assertEqual(170 ^ 75, result['(a ^ b)']) result = df.select(functions.bitwiseNOT(df.b)).collect()[0].asDict() self.assertEqual(~75, result['~b']) result = df.select(functions.bitwise_not(df.b)).collect()[0].asDict() self.assertEqual(~75, result['~b'])
def invert(self, operand: IndexOpsLike) -> IndexOpsLike: return operand._with_new_scol( F.bitwise_not(operand.spark.column), field=operand._internal.data_fields[0] )