Menu

#498 Missing sexagesimal support

invalid
nobody
None
major
bug
2023-12-08
2023-12-08
No

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

Discussion

  • Anthon van der Neut

    • status: open --> invalid
     
  • Anthon van der Neut

    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 attribute version on the YAML() instance to (1, 1)) , that way ruamel.yaml understands you want the outdated format, knows that reading back 1:3 would not create a string and quotes the output (and it would also quote the alternative booleans for the same reason).

     
  • Stéphane Brunner @ camptocampSA

    Effectively, I miss that I didn't see the last version of the specifications, thanks.

     
  • Anthon van der Neut

    I cannot recommend it as bedtime lecture.

     

Log in to post a comment.