Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an allow_nan keyword argument to dumps, defaults to True #327

Merged
merged 6 commits into from
May 4, 2020

Conversation

segfault
Copy link
Collaborator

with this ujson matches the builtin json behavior for NaN and Inf.
if a user wants to retain the old behavior they can pass allow_nan=False
to ensure strict json compatibility.

This should resolve #311

segfault and others added 3 commits February 20, 2019 09:50
with this ujson matches the builtin json behavior for NaN and Inf.
if a user wants to retain the old behavior they can pass allow_nan=False
to ensure strict json compatibility.
@hugovk hugovk added Python 2 changelog: Added For new features labels Mar 2, 2020
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think matching the stdlib json library is a good idea.

This is failing on Python 2.7, so let's merge it once 2.7 is dropped (#383).

I wonder, should this be considered a breaking change? It's okay if it is, as it'll be a major bump anyway when dropping 2.7.

And if so, do you think there should be a deprecation warning beforehand?

@tcopple
Copy link

tcopple commented May 1, 2020

Is there a timeline on dropping 2.7 support? Would love to have this merged in and released.

@hugovk
Copy link
Member

hugovk commented May 1, 2020

There's been no objections to #383, and 2.7 is now EOL and the final 2.7 has been released, so I think we're good to drop 2.7 pretty much now.

#399 is the only thing in master as yet unreleased, I've left a comment there asking if it's needed in a final release supporting 2.7 first. If so, I'll do that first and we can then drop 2.7 shortly thereafter.

@hugovk
Copy link
Member

hugovk commented May 3, 2020

#399 wasn't needed for Python 2.7, so I've merged #404 and we can make the next release Python 3-only.

@hugovk hugovk changed the title adding an allow_nan keyword argument to dumps defaulted to True Add an allow_nan keyword argument to dumps, defaults to True May 4, 2020
@hugovk hugovk merged commit 73463bc into ultrajson:master May 4, 2020
@hugovk
Copy link
Member

hugovk commented May 4, 2020

Thank you!

@Erotemic
Copy link
Contributor

Erotemic commented Apr 3, 2022

It seems weird that support for dumps was added, but no corresponding support for loads exists.

This means you can dumps things that you can't loads:

MWE:

    import ujson
    data = [float('nan')]
    text = ujson.dumps(data)
    print('data = {!r}'.format(data))
    print('text = {!r}'.format(text))
    try:
        recon = ujson.loads(text)
    except Exception as ex:
        print('ex = {!r}'.format(ex))
    else:
        print('recon = {!r}'.format(recon))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doesn't handle NaN number
4 participants