-
Notifications
You must be signed in to change notification settings - Fork 40
Description
Since pyparsing 3.3.0 (December 2025), periodictable now emits PyparsingDeprecationWarnings during formula parsing due to use of now-deprecated camelCase pyparsing methods (e.g. setParseAction, setName, parseString). periodictable uses the old names, so when warnings are enabled (such as during tests), this causes many warnings to be emitted.
For example, this simple program:
import warnings
warnings.simplefilter("default")
from periodictable.formulas import formula
# Triggers PyparsingDeprecationWarnings under pyparsing 3.3.0+
f = formula("H2O")
print(f)
produces this output with pyparsing 3.3.0 or later:
periodictable/formulas.py:714: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
symbol = symbol.setParseAction(lambda s, l, t: table.symbol(t[0]))
periodictable/formulas.py:721: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
isotope = isotope.setParseAction(lambda s, l, t: int(t[0]) if t[0] else 0)
periodictable/formulas.py:728: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
ion = ion.setParseAction(lambda s, l, t: int(t[0][-1]+(t[0][:-1] if len(t[0]) > 1 else '1')))
periodictable/formulas.py:733: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
fract = fract.setParseAction(lambda s, l, t: float(t[0]) if t[0] else 1)
periodictable/formulas.py:735: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
whole = whole.setParseAction(lambda s, l, t: int(t[0]) if t[0] else 1)
periodictable/formulas.py:739: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
sub_fract = sub_fract.setParseAction(lambda s, l, t: float(from_subscript(t[0])) if t[0] else 1)
periodictable/formulas.py:741: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
sub_whole = sub_whole.setParseAction(lambda s, l, t: int(from_subscript(t[0])) if t[0] else 1)
periodictable/formulas.py:757: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
fasta.setParseAction(convert_fasta)
periodictable/formulas.py:770: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
element = element.setParseAction(convert_element)
periodictable/formulas.py:780: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
implicit_group = implicit_group.setParseAction(convert_implicit)
periodictable/formulas.py:792: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
explicit_group = explicit_group.setParseAction(convert_explicit)
periodictable/formulas.py:827: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
compound = compound.setParseAction(convert_compound)
periodictable/formulas.py:859: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
mixture_by_weight = by_weight.setParseAction(convert_by_weight)
periodictable/formulas.py:868: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
mixture_by_volume = by_volume.setParseAction(convert_by_volume)
periodictable/formulas.py:894: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
mixture_by_layer = mixture_by_layer.setParseAction(convert_by_layer)
periodictable/formulas.py:928: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
mixture_by_absmass = mixture_by_absmass.setParseAction(convert_by_absmass)
periodictable/formulas.py:942: PyparsingDeprecationWarning: 'setParseAction' deprecated - use 'set_parse_action'
grouped_mixture = grouped_mixture.setParseAction(convert_mixture)
periodictable/formulas.py:948: PyparsingDeprecationWarning: 'setName' deprecated - use 'set_name'
grammar.setName('Chemical Formula')
periodictable/formulas.py:962: PyparsingDeprecationWarning: 'parseString' deprecated - use 'parse_string'
return parser.parseString(formula_str)[0]
H2O
The preferred snake_case names were introduced in pyparsing 3.0.0 in 2021. Thankfully, since it's been about five years now, switching to them here generally wouldn't even require users to upgrade pyparsing.
This is fixed in PR #113, which updates all affected calls in periodictable/formulas.py to their new names, eliminating the warnings without changing behavior. This also future-proofs periodictable, since the deprecated names are likely to be removed later.