Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Update to SFrame serialization to fix issues with python 2.7 and clou…
Browse files Browse the repository at this point in the history
…dpickle. (#3333)

* Update to fix issue with python 2.7 and cloudpickle.

* Addressed PR feedback.

Co-authored-by: Hoyt Koepke <[email protected]>
  • Loading branch information
Hoyt Koepke and Hoyt Koepke authored Sep 29, 2020
1 parent cf86bc5 commit c53dd6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/python/turicreate/data_structures/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# SFrames require a disk-backed file or directory to work with. This directory
# has to be present to allow for serialization or deserialization.
__serialization_directory = None
from sys import version_info as _version_info


def enable_sframe_serialization(serialization_directory):
Expand All @@ -28,6 +29,8 @@ def enable_sframe_serialization(serialization_directory):

import os

if _version_info[0] == 2:
raise RuntimeError("SFrame serialization not supported in python 2.")
global __serialization_directory
if serialization_directory is None:
__serialization_directory = None
Expand Down Expand Up @@ -61,7 +64,10 @@ def _safe_serialization_directory():
from pickle import PickleError

if __serialization_directory is None:
raise PickleError("Serialization directory not set to enable pickling or unpickling. "

expected_error = TypeError if (_version_info[0] == 3) else PickleError

raise expected_error("Serialization directory not set to enable pickling or unpickling. "
"Set using turicreate.data_structures.serialization.enable_sframe_serialization().")

return __serialization_directory
7 changes: 5 additions & 2 deletions src/python/turicreate/test/test_sframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..util import _assert_sframe_equal, generate_random_sframe
from .. import _launch, load_sframe, aggregate
from . import util
from sys import version_info

import pandas as pd
from .._cython.cy_flexible_type import GMT
Expand Down Expand Up @@ -642,6 +643,7 @@ def test_save_to_csv(self):
f.close()
os.unlink(f.name)

@pytest.mark.skipif(version_info[0] != 3, "Not a supported feature in python 2.7")
def test_pickling(self):

import pickle
Expand All @@ -650,9 +652,10 @@ def test_pickling(self):
X = generate_random_sframe(100, "ncc")

with util.TempDirectory() as f:


self.assertRaises(pickle.PickleError, lambda: pickle.dumps(X))
expected_error = TypeError if (version_info[0] == 3) else PicklingError

self.assertRaises(expected_error, lambda: pickle.dumps(X))

serialization.enable_sframe_serialization(f)

Expand Down

0 comments on commit c53dd6d

Please sign in to comment.