PyDom
PyDom

Reputation: 31

Module run inside module returns - TypeError: 'numpy.float64' object cannot be interpreted as an integer

I am running a function inside another function in a loop and having a problem when the first module (Mod1) uses values defined in the second module (Mod2) to generate the result for the equation called Overall.

The error returned is thus: TypeError: 'numpy.float64' object cannot be interpreted as an integer

The code is as follows

def Mod1(A,
       B,
       C):
    As = pd.read_csv('AProps.csv',index_col='AName')
    As = As.dropna(0,how='all',thresh=None,subset=None,inplace=False)
    AvailAs = As.index.tolist()

    Bs = pd.read_csv('BProps.csv',index_col='BName')
    Bs = Matrices.dropna(0,how='all',thresh=None, subset=None,inplace=False)
    AvailBs = Bs.index.tolist()

    Prop1_A = As['Prop1'][A]
    Prop2_A = As['Prop2'][A]
    Prop3_A = As['Prop3'][A]
    Prop4_A = Prop1_A/(2*(1+Prop3_A))
    Prop1_B = Bs['Prop1'][B]
    Prop3_B = Bs['Prop3'][B]
    Prop4 = Prop1_B/(2*(1+Prop3_B)

    Overall = Prop1_A*C+Prop1_B*(1-C)

    Return Overall


def Mod2(NumItems):
    A_List = []
    B_List = []      
    C_List = []


    for i in range(NumItems):

        A_List.append(input('Choose the A_Input for item {0}:  '.format(i+1)))
        B_List.append(input('Choose the B_input for item {0}:  '.format(i+1)))
        C_List.append(input('Choose the C_input for item {0}:  '.format(i+1)))


    for i in range (NumLams):
        Func1(A_List[i],B_List[i],C_List[i])

Just to be clear, the intention of the code is that Mod2 creates lists of inputs which are then used within Mod1. In Mod1 inputs A and B are used to pull outputs from csv files which are read into As and Bs. Input C is used in functions within Mod1, ie Overall.

When I run Mod1 manually, there are no issues at all. But when run in conjunction with Mod2 as outlined above...

The code in Mod1 runs through using the values Prop1_A and Prop1_B pulled from As and Bs without issue, but when it comes to run the function for Overall the aforementioned error is returned within Python.

I am certain that the issue is with the way the value for C is interpreted, ie as a float64, but don’t understand why python might be expecting to see an integer there.

I am using Spyder 3.2.6 as installed with the Anaconda package.

Any help given is gratefully received.

Upvotes: 0

Views: 125

Answers (1)

PyDom
PyDom

Reputation: 31

I solved the problem by explicitly defining all the selections from the csv, Prop_1 etc, in Mod1 as floats. A simple answer really.

Upvotes: 1

Related Questions