-2

When I execute this code, I get the error IndentationError: unindent does not match any outer indentation level:

def calculate(num1, num2):
    if (num1/num2 > 1): 
        num1 = num2
    result = (num1 - num2) / math.sqrt(1-(num1/num2))
    return result   
df = udf(calculate, FloatType())

What am I doing wrong?

Dinosaurius
  • 8,306
  • 19
  • 64
  • 113
  • Where is the error occurring? I just copied and pasted your function into an ipython session and it worked fine for me. The final line looks like it requires imports from other libraries so I didn't try to execute that. – Angus Williams Jul 28 '17 at 08:20
  • There's no problem of indentation in this piece of code. – Thierry Lathuille Jul 28 '17 at 08:22
  • 2
    You might be mixing tabs and spaces. I have seen tabs converted into spaces when posting code here. – Stop harming Monica Jul 28 '17 at 08:28
  • @AngusWilliams: I get this: `df = udf(calculate, FloatType()) ^`. The sign `^` is put below last `)`. – Dinosaurius Jul 28 '17 at 09:02
  • This is not reproducible with the code shown, even looking at the raw source for the post. The reference for these issues is https://stackoverflow.com/questions/45621722 , but this attempt at a question does not actually exemplify the problem, or any problem. – Karl Knechtel Jul 14 '23 at 20:07

1 Answers1

0

The code you posted does not have an indentation error. Look at the line number that is reported in the error message. You will see something like this:

xxxx
    xxxxx
    xxxxx
   xxxxx
   ^ this is the unindent that is causing the problem
BoarGules
  • 16,440
  • 2
  • 27
  • 44