Skip to content

Commit

Permalink
Merge pull request #35 from portfoliome/nan-none
Browse files Browse the repository at this point in the history
Nan and None converters.
  • Loading branch information
pmart123 authored Dec 14, 2017
2 parents d085785 + 2b20103 commit b66d8cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion foil/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version_info = (0, 2, 6)
version_info = (0, 2, 7)

__version__ = '.'.join(map(str, version_info))
10 changes: 9 additions & 1 deletion foil/converters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from math import isnan, nan

# moved to foil/records.py
from foil.records import replace_keys, rename_keys


def nan_to_none(value):
return None if isnan(value) else value


def none_to_nan(value):
return nan if value is None else value
15 changes: 15 additions & 0 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest
from math import isnan, nan

from foil.converters import nan_to_none, none_to_nan


class TestNanConverters(unittest.TestCase):

def test_nan_to_none(self):
self.assertIsNone(nan_to_none(nan))
self.assertEqual(1, nan_to_none(1))

def test_none_to_nan(self):
self.assertTrue(isnan(none_to_nan(None)))
self.assertEqual(1, none_to_nan(1))

0 comments on commit b66d8cf

Please sign in to comment.