From c7893edfdc70f1ca9e3f90684454c0fadfaacbad Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Tue, 29 May 2018 15:45:50 +1000 Subject: [PATCH] Fix bug in which the cached data check always failed Makes the decoding less aggressive. This was causing various things to be coerced into a list when they where dictionaries etc. --- tupak/result.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tupak/result.py b/tupak/result.py index ce6e5465f..50d680392 100644 --- a/tupak/result.py +++ b/tupak/result.py @@ -39,7 +39,8 @@ class Result(dict): def __init__(self, dictionary=None): if type(dictionary) is dict: for key in dictionary: - setattr(self, key, self._decode_object(dictionary[key], key)) + val = self._standardise_strings(dictionary[key], key) + setattr(self, key, val) def __getattr__(self, name): try: @@ -62,21 +63,17 @@ class Result(dict): else: return '' - def _decode_object(self, item, name=None): - """ When reading in data, ensure all bytes are decoded to strings """ - if type(item) == pd.DataFrame: - return item - try: + def _standardise_a_string(self, item): + """ When reading in data, ensure all strings are decoded correctly """ + if type(item) in [bytes]: return item.decode() - except AttributeError: - pass - - try: - return [i.decode() for i in item] - except (AttributeError, TypeError): - pass + else: + return item - logging.debug("Unable to decode item {}".format(name)) + def _standardise_strings(self, item, name=None): + if type(item) in [list]: + item = [self._standardise_a_string(i) for i in item] + #logging.debug("Unable to decode item {}".format(name)) return item def get_result_dictionary(self): -- GitLab