-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from portfoliome/nan-none
Nan and None converters.
- Loading branch information
Showing
3 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
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
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)) |
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
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 |
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
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)) |