'Use boolean expression multiple lines in pyspark

How can I do this? I want to write these in seperate line, but at the or symbol, '|', I got an error said "cannot convert column into bool please use '&' for 'and'".

I want these two groups to be broken into lines by "|".

    df.filter(
    (F.datediff(F.lit(date), F.col('date')) <= 90) &
    (
        ( 
            (F.col('yyyy')).cast(T.IntegerType()) == F.year(F.date_add(F.lit(date), -1)) &
            (F.col('mm')).cast(T.IntegerType()) == F.month(F.date_add(F.lit(date), -1)) 
        ) |
        ( 
            (F.col('yyyy')).cast(T.IntegerType()) == F.year(F.add_months(F.date_add(F.lit(date), -1), -1)) &
            (F.col('mm')).cast(T.IntegerType()) == F.month(F.add_months(F.date_add(F.lit(date), -1), -1)) 
        ) 
    )
)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source