Missing sexagesimal support
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
The sexagesimal support is missing than sometimes we get some incoherence with PyYAML
With this example we can see the issue:
import yaml
import ruamel.yaml
import sys
data = {'a': '1:3','b': '1:3.1'}
print(f'PyYAML dump:\n{yaml.dump(data)}')
ruamel = ruamel.yaml.YAML()
print(f'ruamel.yaml dump:')
ruamel.dump(data, sys.stdout)
print("The ruamel yaml dump looks correct, but when we reload it....")
str_data = 'a: 1:3\nb: 1:3.1'
print(f'PyYAML load: {yaml.safe_load(str_data)}')
print(f'ruamel.yaml load: {ruamel.load(str_data)}')
print("We don't get the expected result with PyYAML")
That to almost fix the dump to don't have an issue when we open the generated file with PyYAMLl
Related reference documentation:
https://yaml.org/type/float.html
https://yaml.org/type/int.html
This is a support question and belongs on StackOverflow,
You are mistaken that sexagesimal support is misisng.
PyYAML suyports a subset of the YAML 1.1 specifcation, and in the specification sexagesimals are included.
In the YAML 1.2 specification (from 2009) sexagesimals were removed (as were Yes/On/No/Off as booleans values).
If you need to processs output from
ruamel.yaml
with PyYAML, you have to dump a YAML version 1.1 files, (by setting attributeversion
on theYAML()
instance to(1, 1)
) , that wayruamel.yaml
understands you want the outdated format, knows that reading back1:3
would not create a string and quotes the output (and it would also quote the alternative booleans for the same reason).Effectively, I miss that I didn't see the last version of the specifications, thanks.
I cannot recommend it as bedtime lecture.