Skip to content

Comments

Allow NaN/Infinity as a Number#56

Open
alex-unearth wants to merge 3 commits intoPaulJuliusMartinez:mainfrom
brewingcode:allow-nan-infinity
Open

Allow NaN/Infinity as a Number#56
alex-unearth wants to merge 3 commits intoPaulJuliusMartinez:mainfrom
brewingcode:allow-nan-infinity

Conversation

@alex-unearth
Copy link

@alex-unearth alex-unearth commented Feb 27, 2022

No description provided.

 Using `jq` as a reference for allowed tokens, except we preserve the
 exact tokens instead of replacing them, as jq does:

 - nan -> `null`
 - inf -> `1.7976931348623157e+308`
@brewingcode brewingcode deleted the allow-nan-infinity branch February 28, 2022 03:07
@wabscale
Copy link

Hey this would be good to add. I use jless for data produced from numerical calculations where NaNs and Infs come up from time to time. Being able to use jless with those would be quite useful for me and my team.

@codeinred
Copy link

As a note - python spits out NaN and Infinity when serializing those values. Python is also able to deserialize NaN and Infinity:

import json
from math import nan, inf

json_str = json.dumps(
    {
        'x': nan,
        'x2': -nan,
        'y': inf,
        'z': -inf,
    },
    indent=4
)

print(f"(json with nan/inf)")
print(json_str)


result = json.loads(json_str)

print(f"x = {result['x']}")
print(f"y = {result['y']}")
print(f"z = {result['z']}")

Output:

(json with nan/inf)
{
    "x": NaN,
    "x2": NaN,
    "y": Infinity,
    "z": -Infinity
}
x = nan
y = inf
z = -inf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants