Created
October 7, 2015 18:44
-
-
Save adnelson/b2a0911882dbaaf480f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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