QuentinAndre / pyprocessmacro

A Python library for moderation, mediation and conditional process analysis.
MIT License
92 stars 28 forks source link

dtype error #21

Closed billfinnegan closed 2 years ago

billfinnegan commented 2 years ago

When I try model 4 similar to the examples, I get the following error: UFuncTypeError: Cannot cast ufunc 'inv' input from dtype('O') to dtype('float64') with casting rule 'same_kind'

All of the variables I'm using are floats, so I'm not sure what could be causing this. I tried dropping na and installing the latest version, just in case those helped, but I'm still seeing the error.

Thanks for your help and for creating this invaluable resource for python users!

QuentinAndre commented 2 years ago

Hi Bill,

Thank you for raising the issue. It appears that one of your variables has a type "object", rather than "float".

Could you please convert the columns storing your variables as follow:

df["X"] = df["X"].astype(float)
df["Y"] = df["Y"].astype(float)

Let me know if it fixes the issue!

Best,

Quentin.

billfinnegan commented 2 years ago

🤦 Took me a while to figure this out as all the data columns called in the function are floats. But the dataframe was a multi-index with characters used in one of the indexes. After resetting the index and removing the level_# columns, the function worked like a charm. Thanks!