pydata / pydata/patsy

copy.deepcopy strips off .design_info from DesignMatrix

Open
#112 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
990
Forks
106
Avg merge
7d 34m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named in the report. Start by reproducing the copy.deepcopy behavior with a patsy DesignMatrix, then trace how design_info is retained and copied; done means the copied matrix retains design_info and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.