diff --git a/src/python/turicreate/data_structures/sframe.py b/src/python/turicreate/data_structures/sframe.py index cb5db0c05f..23a31f42f4 100644 --- a/src/python/turicreate/data_structures/sframe.py +++ b/src/python/turicreate/data_structures/sframe.py @@ -5881,6 +5881,17 @@ def _group(self, key_columns): """ gsf = GroupedSFrame(self, key_columns) return gsf + + def to_dict(self): + dict_sframe = {} + for key in self.column_names(): + sa = SArray(self[key]) + val_list = [] + for val in sa: + val_list.append(val) + dict_sframe.update({key:val_list}) + del val_list + return dict_sframe @property def shape(self): diff --git a/src/python/turicreate/test/test_sframe.py b/src/python/turicreate/test/test_sframe.py index 91a0c8cfcd..c2d5418e23 100644 --- a/src/python/turicreate/test/test_sframe.py +++ b/src/python/turicreate/test/test_sframe.py @@ -3787,6 +3787,12 @@ def test_export_empty_SFrame(self): sf2 = SFrame.read_json(f.name) _assert_sframe_equal(sf, sf2) + def test_to_dict(self): + sf = SFrame({'col1': [1, 2],'col2': [0.5, 0.75]}) + result = sf.to_dict() + expected = {'col1': [1, 2], 'col2': [0.5, 0.75]} + self.assertEqual(result, expected) + if __name__ == "__main__": import sys