Skip to content

Commit

Permalink
Coerce pd.Series to dicts in Metadata.custom. Closes #232.
Browse files Browse the repository at this point in the history
  • Loading branch information
polyatail committed Mar 27, 2019
1 parent f03800b commit 57fdb0d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions onecodex/models/sample.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from requests.exceptions import HTTPError
from six import string_types
import warnings
Expand Down Expand Up @@ -184,6 +185,19 @@ def __hash__(self):
class Metadata(OneCodexBase):
_resource_path = '/api/v1/metadata'

def __setattr__(self, key, value):
# At some point we should validate that these match the schema
if key == 'custom':
try:
import pandas as pd

if isinstance(value, pd.Series):
value = json.loads(value.to_json())
except ImportError:
pass

super(Metadata, self).__setattr__(key, value)

def save(self):
if self.id is None:
super(Metadata, self).save() # Create
Expand Down

0 comments on commit 57fdb0d

Please sign in to comment.