Skip to content

Validate isotope substitution proportions - #147

Open
swf1996120 wants to merge 1 commit into
python-periodictable:masterfrom
swf1996120:validate-replace-portion
Open

swf1996120 wants to merge 1 commit into
python-periodictable:masterfrom
swf1996120:validate-replace-portion

Conversation

@swf1996120

Copy link
Copy Markdown

This patch accompanies #146.

Formula.replace() documents portion as the fraction of source material to substitute, but previously accepted negative, greater-than-one, and non-finite values. Those inputs produced negative or NaN atom counts and could propagate invalid compositions into mass, density, and scattering calculations.

The patch validates that portion is finite and lies in [0, 1], while preserving all existing valid cases. It adds a regression test for -1, 2, nan, and inf.

Validation performed locally:

  • direct probes confirm invalid values raise ValueError and 0, 0.5, and 1 retain their existing compositions;
  • 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