Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/pyspark/sql/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def __init__(self, jc):
__ror__ = _bin_op("or")

# container operators
__contains__ = _bin_op("contains")
def __contains__(self, item):
raise ValueError("Cannot apply 'in' operator against a column: please use 'contains' "
"in a string column or 'array_contains' function for an array column.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant here is use

>>> df = spark.range(1)
>>> df.select(df.id.contains(0)).show()
+---------------+
|contains(id, 0)|
+---------------+
|           true|
+---------------+

or

>>> from pyspark.sql.functions import array_contains
>>> df = spark.createDataFrame([[[0]]], ["id"])
>>> df.select(array_contains(df.id, 0)).show()
+---------------------+
|array_contains(id, 0)|
+---------------------+
|                 true|
+---------------------+


# bitwise operators
bitwiseOR = _bin_op("bitwiseOR")
Expand Down
3 changes: 3 additions & 0 deletions python/pyspark/sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,9 @@ def test_column_operators(self):
cs.startswith('a'), cs.endswith('a')
self.assertTrue(all(isinstance(c, Column) for c in css))
self.assertTrue(isinstance(ci.cast(LongType()), Column))
self.assertRaisesRegexp(ValueError,
"Cannot apply 'in' operator against a column",
lambda: 1 in cs)

def test_column_getitem(self):
from pyspark.sql.functions import col
Expand Down