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

Update composition.py #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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