Skip to content

Replace assert to check int in get_el_sp#4527

Merged
shyuep merged 1 commit intomaterialsproject:masterfrom
DanielYang59:fix-get_el_sp-assert
Oct 31, 2025
Merged

Replace assert to check int in get_el_sp#4527
shyuep merged 1 commit intomaterialsproject:masterfrom
DanielYang59:fix-get_el_sp-assert

Conversation

@DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Oct 22, 2025

Currently get_el_sp uses assert to check if obj is integar, this could be bypassed by the optimization flag (-O) and results in surprising behaviour, for example:

python3 -c "from pymatgen.core.periodic_table import get_el_sp; print(get_el_sp(4.5))"
>>> ValueError: Can't parse Element or Species from 4.5

However with -O it bypasses assert and gives Be because of int(flt):

python3 -O -c "from pymatgen.core.periodic_table import get_el_sp; print(get_el_sp(4.5))"
>>> Be

@DanielYang59 DanielYang59 marked this pull request as ready for review October 22, 2025 12:02
@shyuep shyuep merged commit 83f06f3 into materialsproject:master Oct 31, 2025
44 checks passed
@DanielYang59 DanielYang59 deleted the fix-get_el_sp-assert branch October 31, 2025 17:01
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