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

Commit c53dd6d

Browse files
Hoyt KoepkeHoyt Koepke
andauthored
Update to SFrame serialization to fix issues with python 2.7 and cloudpickle. (#3333)
* Update to fix issue with python 2.7 and cloudpickle. * Addressed PR feedback. Co-authored-by: Hoyt Koepke <[email protected]>
1 parent cf86bc5 commit c53dd6d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/python/turicreate/data_structures/serialization.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# SFrames require a disk-backed file or directory to work with. This directory
99
# has to be present to allow for serialization or deserialization.
1010
__serialization_directory = None
11+
from sys import version_info as _version_info
1112

1213

1314
def enable_sframe_serialization(serialization_directory):
@@ -28,6 +29,8 @@ def enable_sframe_serialization(serialization_directory):
2829

2930
import os
3031

32+
if _version_info[0] == 2:
33+
raise RuntimeError("SFrame serialization not supported in python 2.")
3134
global __serialization_directory
3235
if serialization_directory is None:
3336
__serialization_directory = None
@@ -61,7 +64,10 @@ def _safe_serialization_directory():
6164
from pickle import PickleError
6265

6366
if __serialization_directory is None:
64-
raise PickleError("Serialization directory not set to enable pickling or unpickling. "
67+
68+
expected_error = TypeError if (_version_info[0] == 3) else PickleError
69+
70+
raise expected_error("Serialization directory not set to enable pickling or unpickling. "
6571
"Set using turicreate.data_structures.serialization.enable_sframe_serialization().")
6672

6773
return __serialization_directory

src/python/turicreate/test/test_sframe.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..util import _assert_sframe_equal, generate_random_sframe
1313
from .. import _launch, load_sframe, aggregate
1414
from . import util
15+
from sys import version_info
1516

1617
import pandas as pd
1718
from .._cython.cy_flexible_type import GMT
@@ -642,6 +643,7 @@ def test_save_to_csv(self):
642643
f.close()
643644
os.unlink(f.name)
644645

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

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

652654
with util.TempDirectory() as f:
653-
654655

655-
self.assertRaises(pickle.PickleError, lambda: pickle.dumps(X))
656+
expected_error = TypeError if (version_info[0] == 3) else PicklingError
657+
658+
self.assertRaises(expected_error, lambda: pickle.dumps(X))
656659

657660
serialization.enable_sframe_serialization(f)
658661

0 commit comments

Comments
 (0)