On 01/09/2016 04:45 AM, Franc Carter wrote: > > Hi, > > I'm trying to write a short function that returns the last sunday of > the week of a given date, code below > > def getSunday(day): > > day = day.cast("date") > > sun = next_day(day, "Sunday") > > n = datediff(sun,day) > > if (n == 7): > > return day > > else: > > return sun > > > this gives me > > ValueError: Cannot convert column into bool: > > > Can someone point out what I am doing wrong
You operate on expressions so conditional should be an expression as well: def getSunday(day): day = day.cast("date") sun = next_day(day, "Sunday") n = datediff(sun,day) return when(n == 7, day).otherwise(sun) > > thanks > > > -- > Franc
signature.asc
Description: OpenPGP digital signature