-
Notifications
You must be signed in to change notification settings - Fork 556
Open
Labels
Description
Hi,
it appears that PyYAML requires a dot in the mantissa as well as a sign in the exponent in order to parse numbers in scientific notation as numbers and otherwise parses them as string:
>>> import yaml
>>> yaml.safe_load('1e+10')
'1e+10'
>>> yaml.safe_load('1.e+10')
10000000000.0
>>> yaml.safe_load('1.0e10')
'1.0e10'According to YAML 1.2 spec the dot is optional as in JSON:
Either
0,.inf,-.inf,.nan, or scientific notation matching the regular expression-? [1-9] ( \. [0-9]* [1-9] )? ( e [-+] [1-9] [0-9]* )?.
Furthermore, JSON makes even the sign in the exponent optional: https://www.json.org/number.gif
Since YAML 1.2 aspires to be a superset of JSON, I believe it should make the sign optional as well.
Others than ran into similar problems:
https://stackoverflow.com/questions/30458977/yaml-loads-5e-6-as-string-and-not-a-number
Best, Thomas
airalcorn2, lumpiluk, sytelus, AdityaSavara, DuaneNielsen and 40 more