def test_pickling_sgraph_types(self): sg_test_1 = gl.SGraph().add_vertices([ gl.Vertex(0, {'fluffy': 1}), gl.Vertex(1, {'fluffy': 1, 'woof': 1}), gl.Vertex(2, {})]) sg_test_2 = gl.SGraph() sg_test_2 = sg_test_2.add_vertices([ gl.Vertex(x) for x in [0, 1, 2]]) sg_test_2 = sg_test_2.add_edges([ gl.Edge(0, 1, attr={'relationship': 'dislikes'}), gl.Edge(1, 2, attr={'relationship': 'likes'}), gl.Edge(1, 0, attr={'relationship': 'likes'})]) sarray_list = [ sg_test_1, sg_test_2 ] for obj in sarray_list: pickler = gl_pickle.GLPickler(self.filename) pickler.dump(obj) pickler.close() obj_ret = gl_pickle.GLUnpickler(self.filename).load() assert_sframe_equal(obj.get_vertices(), obj_ret.get_vertices()) assert_sframe_equal(obj.get_edges(), obj_ret.get_edges())
def test_pickling_sframe_types(self): sarray_list = [ gl.SFrame([1,2,3]), gl.SFrame([1.0,2.0,3.5]), gl.SFrame(["foo", "bar"]), ] for obj in sarray_list: pickler = gl_pickle.GLPickler(self.filename) pickler.dump(obj) pickler.close() obj_ret = gl_pickle.GLUnpickler(self.filename).load() assert_sframe_equal(obj, obj_ret)
def test_relative_path(self): # Arrange sf1 = gl.SFrame(range(10)) relative_path = 'tmp/%s' % self.filename # Act pickler = gl_pickle.GLPickler(relative_path) pickler.dump(sf1) pickler.close() sf2 = gl_pickle.GLUnpickler(relative_path).load() # Assert assert_sframe_equal(sf1, sf2) # Clean up shutil.rmtree(relative_path)
def test_save_to_s3(self): # Arrange os.environ['GRAPHLAB_UNIT_TEST'] = 'PredictiveService' os.environ['AWS_ACCESS_KEY_ID'] = '' os.environ['AWS_SECRET_ACCESS_KEY'] = '' BUCKET_NAME = 'foo' boto.connect_s3().create_bucket(BUCKET_NAME) sf1 = gl.SFrame(range(10)) S3_PATH = "s3://%s/foobar" % BUCKET_NAME # Act pickler = gl_pickle.GLPickler(S3_PATH) pickler.dump(sf1) pickler.close() sf2 = gl_pickle.GLUnpickler(S3_PATH).load() # Assert assert_sframe_equal(sf1, sf2) del os.environ['GRAPHLAB_UNIT_TEST']
def _test_backward_compatibility(self): # Arrange file_name = 's3://gl-internal-datasets/models/1.3/gl-pickle.gl' obj = {'foo': gl.SFrame([1,2,3]), 'bar': gl.SFrame(), 'foo-bar': ['foo-and-bar', gl.SFrame([1])]} # Act unpickler = gl_pickle.GLUnpickler(file_name) obj_ret = unpickler.load() # Assert assert_sframe_equal(obj['foo'], obj_ret['foo']) assert_sframe_equal(obj['bar'], obj_ret['bar']) assert_sframe_equal(obj['foo-bar'][1], obj_ret['foo-bar'][1]) self.assertEqual(obj['foo-bar'][0], obj_ret['foo-bar'][0])
def test_combination_gl_python_types(self): sg_test_1 = gl.SGraph().add_vertices([ gl.Vertex(1, {'fluffy': 1}), gl.Vertex(2, {'fluffy': 1, 'woof': 1}), gl.Vertex(3, {})]) sarray_test_1 = gl.SArray([1,2,3]) sframe_test_1 = gl.SFrame([1,2,3]) obj_list = [ [sg_test_1, sframe_test_1, sarray_test_1], {0:sg_test_1, 1:sframe_test_1, 2:sarray_test_1} ] for obj in obj_list: pickler = gl_pickle.GLPickler(self.filename) pickler.dump(obj) pickler.close() obj_ret = gl_pickle.GLUnpickler(self.filename).load() assert_sframe_equal(obj[0].get_vertices(), obj_ret[0].get_vertices()) assert_sframe_equal(obj[0].get_edges(), obj_ret[0].get_edges()) assert_sframe_equal(obj[1], obj_ret[1]) assert list(obj[2]) == list(obj_ret[2])