turi-code / SFrame

SFrame: Scalable tabular and graph data-structures built for out-of-core data analysis and machine learning.
BSD 3-Clause "New" or "Revised" License
890 stars 331 forks source link

Deepcopy an sframe #85

Open sb2nov opened 8 years ago

sb2nov commented 8 years ago
import sframe
sf = sframe.SFrame()
sf['a'] = [1,1,1,1,             2,2,2,           3,     4,4,      5]
sf['b'] = [1,2,1,2,             3,3,1,           4,     None, 2,  3]
sf2= deepcopy(sf)

Error logs


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-f0d0a6912fba> in <module>()
----> 1 sf2= deepcopy(sf)

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
    188                             raise Error(
    189                                 "un(deep)copyable object of type %s" % cls)
--> 190                 y = _reconstruct(x, rv, 1, memo)
    191 
    192     memo[d] = y

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in _reconstruct(x, info, deep, memo)
    332     if state:
    333         if deep:
--> 334             state = deepcopy(state, memo)
    335         if hasattr(y, '__setstate__'):
    336             y.__setstate__(state)

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
    161     copier = _deepcopy_dispatch.get(cls)
    162     if copier:
--> 163         y = copier(x, memo)
    164     else:
    165         try:

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in _deepcopy_tuple(x, memo)
    235     y = []
    236     for a in x:
--> 237         y.append(deepcopy(a, memo))
    238     d = id(x)
    239     try:

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
    161     copier = _deepcopy_dispatch.get(cls)
    162     if copier:
--> 163         y = copier(x, memo)
    164     else:
    165         try:

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in _deepcopy_dict(x, memo)
    255     memo[id(x)] = y
    256     for key, value in x.iteritems():
--> 257         y[deepcopy(key, memo)] = deepcopy(value, memo)
    258     return y
    259 d[dict] = _deepcopy_dict

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
    188                             raise Error(
    189                                 "un(deep)copyable object of type %s" % cls)
--> 190                 y = _reconstruct(x, rv, 1, memo)
    191 
    192     memo[d] = y

/Users/sbajaj/miniconda/lib/python2.7/copy.pyc in _reconstruct(x, info, deep, memo)
    327     if deep:
    328         args = deepcopy(args, memo)
--> 329     y = callable(*args)
    330     memo[id(x)] = y
    331 

/Users/sbajaj/miniconda/lib/python2.7/copy_reg.pyc in __newobj__(cls, *args)
     91 
     92 def __newobj__(cls, *args):
---> 93     return cls.__new__(cls, *args)
     94 
     95 def _slotnames(cls):

sframe/cython/cy_sframe.pyx in sframe.cython.cy_sframe.UnitySFrameProxy.__cinit__()

TypeError: __cinit__() takes at least 1 positional argument (0 given)
ylow commented 8 years ago

Copy should be fine. Either sf.copy() or copy.copy(sf).

Since SArrays are immutable, copy is sufficient.

hoytak commented 8 years ago

@ylow: Yes, but we should support the __deepcopy__ method so the above works correctly.