Srivatsan
Srivatsan

Reputation: 9363

TypeError: unsupported operand type(s) for &: 'float' and 'float', but I have no &

Here is part of my code:

import numpy as np
import pyfits 
from astropy.io import ascii

def create_randoms(min_z,max_z,min_mass):

        Do some calculations and use it to 
        write into a file 


        if (max_z == 1.0 and min_mass == 1e13):
                ascii.write(data_1, '/home/Documents/0.0_zphot_1.0.dat', Writer=ascii.FixedWidthNoHeader, delimiter=None)

Exactly in the if statement, I get the error:

TypeError: unsupported operand type(s) for &: 'float' and 'float'

I call the function by:

create_randoms(0.0,1.0,1e13)

I don't know why it doesn't seem to like the values 1.0 and 1e13. I am not using the bitwise & here, and instead I am correctly using the logical operator and. But still it is throwing me with the error.

Full error traceback:

TypeError                                 Traceback (most recent call last)
<ipython-input-83-d5f507b12cc0> in <module>()
----> 1 create_randoms(0.0,1.0,1e13,0,0,1,0,0,0,0,1)

/home/ssridhar/Documents/PhD_materials/Python/correlation_func/100_Hband_halos/jackknife_random_creation.py in create_randoms(min_z, max_z, min_mass, r1, r2, r3, r4, d1, d2, d3, d4)
    119         """ WRITING FILES ACCORDINGLY """
    120 
--> 121         if (max_z == '1.0' and min_mass == '1e13'):
    122                 ascii.write(data_1, '/home/ssridhar/Documents/PhD_materials/2pt_correlation_master_2/Input/100_Hband_halos/jackknife/M200>1e13/K1_100sq_M200>1e13_xyz_0.0<zphot0.001<1.0.dat', Writer=ascii.FixedWidthNoHeader, delimiter=None)
    123 

TypeError: unsupported operand type(s) for &: 'float' and 'float'

Upvotes: 0

Views: 684

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1122242

Python compiles your code to bytecode, then runs that. But bytecode doesn't make for a readable error message. When an error occurs, Python loads the original source code from disk to show what lines are causing the error.

So when you edit your code, but don't reload the bytecode in Python or restart the Python interpreter, your error messages will by out of sync. Old code with the problem is run, but the traceback shows the new code.

In ipython, reload the code, or to be 100% sure, restart the interpreter.

Upvotes: 2

Related Questions