Skip to content

Instantly share code, notes, and snippets.

@adnelson
Created October 7, 2015 18:44
Show Gist options
  • Save adnelson/b2a0911882dbaaf480f5 to your computer and use it in GitHub Desktop.
Save adnelson/b2a0911882dbaaf480f5 to your computer and use it in GitHub Desktop.
nan = float('nan')
def convert_nans(obj):
if isinstance(obj, list):
return [convert_nans(x) for x in obj]
elif isinstance(obj, dict):
return {k: convert_nans(v) for k, v in obj.iter()}
elif obj is nan or obj is None:
return None
elif isinstance(obj, (str, float, int)):
return obj
else:
raise ValueError('Unserializable value: {}'.format(obj))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment