Skip to content

Handle zero-mass formula fractions - #151

Open
swf1996120 wants to merge 1 commit into
python-periodictable:masterfrom
swf1996120:guard-zero-mass-fraction
Open

swf1996120 wants to merge 1 commit into
python-periodictable:masterfrom
swf1996120:guard-zero-mass-fraction

Conversation

@swf1996120

Copy link
Copy Markdown

Problem

Formula.mass_fraction raised ZeroDivisionError for formulas accepted by the grammar with zero element counts, such as formula("H0") and formula("C0H0").

Fix

Return zero mass fractions when the total formula mass is zero, while preserving ordinary mass-fraction calculations. Add regression coverage for zero-count and normal formulas.

Closes #150

Validation

  • direct checks for H0, C0H0, and H2O
  • python -m compileall -q periodictable test
  • git diff --check

This patch was prepared as part of a chemical-repository testing study with LLM assistance; the reproducer and fix were run locally.

This branch has not been deployed

No deployments
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.

Formula.mass_fraction raises ZeroDivisionError for zero-count formulas

1 participant