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

Enhancement request: Ignore NaN #210

Open
colinalexander opened this issue Feb 20, 2016 · 3 comments
Open

Enhancement request: Ignore NaN #210

colinalexander opened this issue Feb 20, 2016 · 3 comments

Comments

@colinalexander
Copy link

colinalexander commented Feb 20, 2016

Similar to simplejson, would it be possible to include a parameter to ignore NaNs?

d = {0: -0.8285523717159029, 1: nan}

Current Behavior

>>> ujson.dumps(d)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-88-77a2055a90c0> in <module>()
----> 1 ujson.dumps(d)

OverflowError: Invalid Nan value when encoding double

Desired Behavior

>>> simplejson.dumps(d, ignore_nan=True)
'{"0": -0.8285523717159029, "1": null}'
@jzwinck
Copy link

jzwinck commented Aug 9, 2016

Pandas' version of ujson does just this. Try it:

import pandas
print(pandas.json.dumps({'foo': np.nan}))

{"foo":null}

You might be able to use it in the meantime.

@Jahaja
Copy link
Contributor

Jahaja commented Feb 11, 2017

This is a duplicate of #146, but I'm leaning towards in adding after all due to our ongoing effort to align more with the standard json module in v2.0.

@hexvolt
Copy link

hexvolt commented Aug 27, 2021

in newer pandas versions:

pandas.io.json.dumps({'foo': np.nan})

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

No branches or pull requests

4 participants