I have a DataFrame which contains a lot of repeated values. An aggregated, distinct count of it looks like below
> df.groupby('fruits').count().sort(F.desc('count')).show()
| fruits | count |
| ----------- | ----------- |
| [Apples] | 123 |
| [] | 344 |
| [Apples, plum]| 444 |
My goal is to filter all rows where the value is either [Apples] or [].
Suprisingly, the following works for an non-empty array but for empty it doesn't
import pyspark.sql.types as T
is_apples = F.udf(lambda arr: arr == ['Apples'], T.BooleanType())
df.filter(is_apples(df.fruits).count() # WORKS! shows 123 correctly.
is_empty = F.udf(lambda arr: arr == [], T.BooleanType())
df.filter(is_empty(df.fruits).count() # Doesn't work! Should show 344 but shows zero.
Any idea what I am doing wrong?