Skip to content

Conversation

@dcf1007
Copy link

@dcf1007 dcf1007 commented Dec 14, 2019

When you have a formula with only 1 atom of the element (let's say H2O or HPO4), the function "parse_formula(formula)" would crash in line 123 composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) with error:

ValueError: invalid literal for int() with base 10: ''

Changing the line to: composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) if number else 1 fixes that error

When you have a formula with only 1 atom of the element (let's say H2O or HPO4), the function "parse_formula(formula)" would crash with error "ValueError: invalid literal for int() with base 10: ''" in line 123 ("composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number)"). Changing the line to: "composition[_make_isotope_string(elem, int(isotope) if isotope else 0)] += int(number) if number else 1" fixes that error
@mobiusklein
Copy link
Owner

Thank you again for taking the time to read through and find the solution to your problem. I mention in my comment on #2 that the C-extension parser also has this issue, but would be much harder to fix.

I can merge this PR if you don't plan to use the C extension and would still find this useful.

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

Successfully merging this pull request may close these issues.

2 participants