patsy icon indicating copy to clipboard operation
patsy copied to clipboard

copy.deepcopy strips off .design_info from DesignMatrix

Open chkothe opened this issue 8 years ago • 0 comments

This was reproduced with patsy==0.4.1 and numpy==1.11.2 on Python 3.5.2 (win64).

Example: > val

Out[30]: 
DesignMatrix with shape (4, 5)
  Columns:
    ['Intercept',
     'LastNightAwake[0]',
     'LastNightAwake[1]',
     'LastNightInBed[0]',
     'LastNightInBed[1]']
  Terms:
    'Intercept' (column 0)
    'LastNightAwake' (columns 1:3)
    'LastNightInBed' (columns 3:5)
  (to view full data, use np.asarray(this_obj))

> val.design_info

Out[31]: 
DesignInfo(['Intercept',
            'LastNightAwake[0]',
            'LastNightAwake[1]',
            'LastNightInBed[0]',
            'LastNightInBed[1]'],
           factor_infos={LookupFactor('LastNightAwake'): FactorInfo(factor=LookupFactor('LastNightAwake'),
                                    type='numerical',
                                    state=<factor state>,
                                    num_columns=2),
                         LookupFactor('LastNightInBed'): FactorInfo(factor=LookupFactor('LastNightInBed'),
                                    type='numerical',
                                    state=<factor state>,
                                    num_columns=2)},
           term_codings=OrderedDict([(Term([]),
                                      [SubtermInfo(factors=(),
                                                   contrast_matrices={},
                                                   num_columns=1)]),
                                     (Term([LookupFactor('LastNightAwake')]),
                                      [SubtermInfo(factors=(LookupFactor('LastNightAwake'),),
                                                   contrast_matrices={},
                                                   num_columns=2)]),
                                     (Term([LookupFactor('LastNightInBed')]),
                                      [SubtermInfo(factors=(LookupFactor('LastNightInBed'),),
                                                   contrast_matrices={},
                                                   num_columns=2)])]))

> val2 = copy.deepcopy(val) > val2

Out[33]: 
array([[ 1.        ,  0.70430108,  0.70237576,  0.32473118,  0.33173496],
       [ 1.        ,  0.7       ,  0.70215054,  0.324     ,  0.32436559],
       [ 1.        ,  0.71491228,  0.70745614,  0.31096491,  0.31748246],
       [ 1.        ,  0.69070513,  0.7028087 ,  0.33846154,  0.32471323]])

> val2.design_info

Traceback (most recent call last):
  File "C:\IntelPython35\lib\site-packages\IPython\core\interactiveshell.py", line 2885, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-34-f74f3449fd15>", line 1, in <module>
    val2.design_info
AttributeError: 'DesignMatrix' object has no attribute 'design_info'

> type(val2)

Out[35]: patsy.design_info.DesignMatrix

chkothe avatar Nov 01 '17 07:11 chkothe