Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot roundtrip to/from pandas #408

Open
lilyminium opened this issue Nov 16, 2021 · 0 comments
Open

Cannot roundtrip to/from pandas #408

lilyminium opened this issue Nov 16, 2021 · 0 comments

Comments

@lilyminium
Copy link
Contributor

lilyminium commented Nov 16, 2021

I'm using an old version of Evaluator (0.3.5), but looking at the code I don't think it's changed in the relevant parts.

I have converted my dataset to a dataframe for filtering, but I can't convert it back. The reason is ExactAmounts are interpreted as floats. The reason is that I have mixed Nones and integers in the column, which Pandas interprets as float64; nan is a float. A column of all Nones does not have this problem, because Pandas does not convert None to NaN and keeps it as an object. The relevant code is here:

if not numpy.isclose(exact_amount, 0.0):
substance.add_component(component, ExactAmount(exact_amount))

IMO code changes should go in from_pandas because then you can read from general CSV files.

I also noticed this line:

for _, data_row in data_frame.iterrows():

This doesn't seem to have caused problems yet, but I would generally recommend changing this to itertuples. iterrows does not preserve column type, but converts the row into a Series (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iterrows.html). This is another great way to change an integer into a float without realising. However, itertuples may be hard to work with as there spaces in the column headings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant