Skip to content

Commit

Permalink
Change update method in SeqProp to not inherit from Object class, won…
Browse files Browse the repository at this point in the history
…'t work for Python 2

(cherry picked from commit 5abd15b)
  • Loading branch information
nmih committed Feb 17, 2018
1 parent 57ff885 commit c65f57f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ssbio/protein/sequence/seqprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,26 @@ def __repr__(self):
return Object.__repr__(self)

def update(self, newdata, overwrite=False, only_keys=None):
Object.update(self, newdata=newdata, overwrite=overwrite, only_keys=only_keys)
# Filter for list of keys in only_keys
if only_keys:
only_keys = ssbio.utils.force_list(only_keys)
newdata = {k: v for k, v in newdata.items() if k in only_keys}

# Update attributes
for key, value in newdata.items():
# Overwrite flag overwrites all attributes
if overwrite:
setattr(self, key, value)
else:
# Otherwise check if attribute is None and set it if so
if hasattr(self, key):
if not getattr(self, key):
setattr(self, key, value)
else:
continue
# Or just add a new attribute
else:
setattr(self, key, value)

def get_dict(self, only_attributes=None, exclude_attributes=None, df_format=False):
"""Get a dictionary of this object's attributes. Optional format for storage in a Pandas DataFrame.
Expand Down

0 comments on commit c65f57f

Please sign in to comment.