Replies: 2 comments
-
|
Hi João, This is a bug/feature of pyyaml: >>> import yaml
>>> yaml.safe_load("foo: 1")
{'foo': 1}
>>> yaml.safe_load("foo: 1e5")
{'foo': '1e5'}
>>> yaml.safe_load("foo: 1.0e5")
{'foo': '1.0e5'}✅ Fix options1. Tag explicitly: divisor: !!float 1.0E8This forces YAML to interpret it as a float. 2. Use plain decimal: divisor: 100000000.03: Use JSON References:
It's not 100% clear from me in all the above whether this is an annoying feature of the yaml spec, or a bug in pyyaml. rueyaml seems to fix it. So we could in principle have an option to use alternative yaml parsers. But this could cause confusion. We have previously had discussions about schema-driven coercion and type disambiguation during loading, but this is explicitly in the context of TSV/CSV, where there is no explicit type system. See #1996 |
Beta Was this translation helpful? Give feedback.
-
|
Hi Chris, With Yes, probably could be better to have other parser or we could choose which parser to use in a particular code. Thanks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have this field
divisor: 1.0E8
defined as
divisor:
description: Divisor for conversion.
range: float
but in runtime when doing the validation
report = default_validator.validate_source(loader, target_class=classinst)
gives the error
message="'1.0E8' is not of type 'number'
It seems that is treated as string instead of number.
Is something native, as it sees E convert to string?
Do we have any workaround or should I do some customization?
Thanks for your help.
João.
Beta Was this translation helpful? Give feedback.
All reactions