Skip to content

Reject invalid mixture quantities - #149

Open
swf1996120 wants to merge 1 commit into
python-periodictable:masterfrom
swf1996120:reject-negative-mixture-quantities
Open

swf1996120 wants to merge 1 commit into
python-periodictable:masterfrom
swf1996120:reject-negative-mixture-quantities

Conversation

@swf1996120

Copy link
Copy Markdown

This patch accompanies #148.

mix_by_weight() and mix_by_volume() previously filtered material quantities with q > 0, silently treating negative or non-finite amounts as zero. That can turn a typo into a different chemical composition or an empty formula without a diagnostic.

The patch validates that all relative quantities are finite and non-negative before the existing zero-quantity filtering. Zero and positive quantities preserve their current behavior. Regression tests cover negative, NaN, and infinity inputs for both mixture helpers.

Local validation:

  • direct probes confirm invalid quantities raise ValueError and zero quantities remain accepted;
  • compileall passes;
  • git diff --check passes.

This report and patch were prepared as part of an LLM-assisted testing study of chemistry repositories. Each reproducer was run locally and minimized before filing.

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.

1 participant