Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Floating point issue with NaN values

See original GitHub issue

Hi, there. Thanks for providing this nice library!

I found myself in a problem here that is related to the following lines:

from strictyaml import Map, Float, load

schema = Map(
        "number_one": Float(),
        "not_a_number": Float(),

yaml_string = (
    "number_one: 1.0\n"
    "not_a_number: .nan"

load(yaml_string=yaml_string, schema=schema)

and I got this:

strictyaml.exceptions.YAMLValidationError: when expecting a float
found arbitrary text
  in "<unicode string>", line 2, column 1:
    not_a_number: '.nan'
    ^ (line: 2)

According to, .nan, .inf or -.inf are part of the canonical form of the floating point representation.

(In fact, I would like to do that using dirty_load, as I need a readable representation for my matrices (I’m using Seq(Seq(Float))), but that’s another story, as dirty_load seems to be just another way of calling generic_load with allow_flow_style.)

Am I missing something here or is there a workaround for it?

Thank you

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

shooglecommented, Aug 12, 2020

I would say accept only INF and NaN (think this form is least likely to be mistaken for a standard string). StrictYAML aims to be fully roundtripable, which means there should only be one valid representation. It is a restricted subset of YAML, so no need to support every variation. You could check for other variations and print an error saying to use INF or NaN.

crdoconnorcommented, Aug 10, 2020

Yes, please do. I’ll merge and release a new version on pypi once you’re done.

Thank you for doing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NaN - Wikipedia
In computing, NaN standing for Not a Number, is a member of a numeric data type that can be interpreted as a value...
Read more >
Why does IEEE 754 reserve so many NaN values?
It seems that the IEEE 754 standard defines 16,777,214 32-bit floating point values as NaNs, or 0.4% of all possible values.
Read more >
If it's not a number, what is it? Demystifying NaN ... - Lucidchart
The problem is that floating-point numbers look and act almost like the numbers we all learned about in school. The word “almost“ hides...
Read more >
IEEE Floating-point overview - IBM
If the data or program code contains signaling NaN values (NAN), include nans among the -qfloat suboptions. (A signaling NaN is different from...
Read more >
Infinity and NaN (The GNU C Library)
An expression representing a value which is “not a number”. This macro is a GNU extension, available only on machines that support the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found