title: copy all but one part of an object in python
body: <p>How would one <code>copy.deepcopy()</code> all but one part of an object in python?</p>
  
  <p>I have an object which is basically a wrapper with some settings and some extra bits of metadata around a potentially huge pandas DataFrame. The DataFrame can contain arbitrarily huge amounts of data. I want to make a copy the object that consists of a <em>shallow copy of the dataframe and a deepcopy() of the settings and metadata</em> (both of which which can be mutable objects).</p>
  
  <p><em>I don't know at run time if all of the settings and metadata exist when the copy is needed</em>. There is also the possibility to people may set additional parts of the object using <code>my_object.extra_setting</code>. This means that I can not just explicitly deepcopy all the parts of the object except the large dataframe.</p>
  
  <p>The class is:</p>
  
  <pre><code>    class my_class(object):
  
          def __init__(self, lots_of_data, small_amount_of_data, setting_1, setting_2, setting_3):
              self.lots_of_data = lots_of_data
              self.small_amount_of_data = small_amount_of_data
              self.setting_1 = setting_1
              self.setting_2 = setting_2
  
          def set_setting_3(self, setting_3):
              self.setting_3 = setting_3
  
          def set_more_metadata(metadata):
              self.more_metadata = metadata
  </code></pre>
  
  <p>And in pseudocode the copy method is:</p>
  
  <pre><code>        def __deepcopy__(self):
  
              copy_of_object = copy.deepcopy(self[all but object_in.lots_of_data])
              copy_of_object.lots_of_data = self.lots_of_data
  
              return copy_of_object
  </code></pre>