Repository: stitchfix/nodebook

Issue:
In python3, strings in dictionaries are de-serialized as bytes
Eg, `foo = {'key':42}` is deserialized as `{b'key':42}`

Discussion:

Patch:
diff --git a/nodebook/pickledict.py b/nodebook/pickledict.py
index 01740f4..33a32e3 100644
--- a/nodebook/pickledict.py
+++ b/nodebook/pickledict.py
@@ -66,7 +66,6 @@ class PickleDict(DictMixin):
         persist_path: if provided, perform serialization to/from disk to this path
         """
         self.persist_path = persist_path
-        self.encodings = {}
         self.dump = partial(msgpack.dump, default=msgpack_serialize)
         self.load = partial(msgpack.load, ext_hook=msgpack_deserialize)
         self.dict = {}
@@ -96,25 +95,21 @@ class PickleDict(DictMixin):
         if self.persist_path is not None:
             path = self.dict[key]
             with open(path, 'rb') as f:
-                value = self.load(f, encoding=self.encodings[key])
+                value = self.load(f, raw=False)
         else:
             f = StringIO(self.dict[key])
-            value = self.load(f, encoding=self.encodings[key])
+            value = self.load(f, raw=False)
         return value
 
     def __setitem__(self, key, value):
-        encoding = None
-        if isinstance(value, six.string_types):
-            encoding = 'utf-8'
-        self.encodings[key] = encoding
         if self.persist_path is not None:
             path = os.path.join(self.persist_path, '%s.pak' % key)
             with open(path, 'wb') as f:
-                self.dump(value, f, encoding=encoding)
+                self.dump(value, f, strict_types=True, use_bin_type=True)
             self.dict[key] = path
         else:
             f = StringIO()
-            self.dump(value, f, encoding=encoding)
+            self.dump(value, f, strict_types=True, use_bin_type=True)
             serialized = f.getvalue()
             self.dict[key] = serialized
 
diff --git a/setup.py b/setup.py
index d54a7f5..eb22642 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ import sys
 
 setup(
     name='nodebook',
-    version='0.3.0',
+    version='0.3.1',
     author='Kevin Zielnicki',
     author_email='kzielnicki@stitchfix.com',
     license='Stitch Fix 2018',


Test patch:
diff --git a/tests/test_pickledict.py b/tests/test_pickledict.py
index 30ac34b..de2cc45 100644
--- a/tests/test_pickledict.py
+++ b/tests/test_pickledict.py
@@ -25,10 +25,33 @@ class TestPickleDict(object):
         mydict['test_string'] = 'foo'
         assert mydict['test_string'] == 'foo'
 
+        d = {'foo':'bar'}
+        mydict['test_string_dict'] = d
+        assert mydict['test_string_dict'] == d
+
     def test_bytes(self, mydict):
         mydict['test_bytes'] = b'foo'
         assert mydict['test_bytes'] == b'foo'
 
+        d = {b'foo':b'bar'}
+        mydict['test_bytes_dict'] = d
+        assert mydict['test_bytes_dict'] == d
+
+    def test_list(self, mydict):
+        l = [1,2,3]
+        mydict['test_list'] = l
+        assert mydict['test_list'] == l
+
+    def test_tuple(self, mydict):
+        t = (1,2,3)
+        mydict['test_tuple'] = t
+        assert mydict['test_tuple'] == t
+
+    def test_set(self, mydict):
+        s = {1,2,3}
+        mydict['test_set'] = s
+        assert mydict['test_set'] == s
+
     def test_df(self, mydict):
         df = pd.DataFrame({'a': [0, 1, 2], 'b': ['foo', 'bar', 'baz']})
         mydict['test_df'] = df