Got it, I needed to use the when/otherwise construct - code below

def getSunday(day):

    day = day.cast("date")

    sun = next_day(day, "Sunday")

    n = datediff(sun,day)

    x = when(n==7,day).otherwise(sun)

    return x


On 10 January 2016 at 08:41, Franc Carter <franc.car...@gmail.com> wrote:

>
> My Python is not particularly good, so I'm afraid I don't understand what
> that mean
>
> cheers
>
>
> On 9 January 2016 at 14:45, Franc Carter <franc.car...@gmail.com> 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
>>
>> thanks
>>
>>
>> --
>> Franc
>>
>
>
>
> --
> Franc
>



-- 
Franc

Reply via email to