From c67d668989c296528af21bf218e5a9a20741ca99 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Wed, 29 Jan 2020 20:23:39 +0100 Subject: [PATCH] obi import: fixed a bug when the first entry would contain a dictionary with one key. Switch to beta8 --- python/obitools3/commands/import.pyx | 8 ++++++++ python/obitools3/dms/view/view.pyx | 8 +++++++- python/obitools3/version.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/python/obitools3/commands/import.pyx b/python/obitools3/commands/import.pyx index 344a1da..22d59f8 100755 --- a/python/obitools3/commands/import.pyx +++ b/python/obitools3/commands/import.pyx @@ -247,6 +247,8 @@ def run(config): dcols[tag] = (Column.new_column(view, tag, value_obitype, nb_elements_per_line=nb_elts, elements_names=elt_names), value_obitype) # Fill value + if value_type == dict and nb_elts == 1: # special case that makes the OBI3 create a 1 elt/line column which won't read a dict value + value = value[list(value.keys())[0]] # The solution is to transform the value in a simple atomic one acceptable by the column dcols[tag][0][i] = value # TODO else log error? @@ -263,6 +265,12 @@ def run(config): rewrite = True try: + # Check that it's not the case where the first entry contained a dict of length 1 and now there is a new key + if type(value) == dict and \ + dcols[tag][0].nb_elements_per_line == 1 and len(value.keys()) == 1 \ + and dcols[tag][0].elements_names[0] != list(value.keys())[0] : + raise IndexError # trigger column rewrite + # Fill value dcols[tag][0][i] = value diff --git a/python/obitools3/dms/view/view.pyx b/python/obitools3/dms/view/view.pyx index 003c960..8e3a344 100755 --- a/python/obitools3/dms/view/view.pyx +++ b/python/obitools3/dms/view/view.pyx @@ -297,8 +297,14 @@ cdef class View(OBIWrapper) : nb_elements_per_line=new_nb_elements_per_line, elements_names=new_elements_names, comments=old_column.comments, alias=column_name_b+tobytes('___new___')) + switch_to_dict = old_column.nb_elements_per_line == 1 and new_nb_elements_per_line > 1 + ori_key = old_column._elements_names[0] + for i in range(length) : - new_column[i] = old_column[i] + if switch_to_dict : + new_column[i] = {ori_key: old_column[i]} + else: + new_column[i] = old_column[i] # Remove old column from view self.delete_column(column_name_b) diff --git a/python/obitools3/version.py b/python/obitools3/version.py index 0dc7c1f..9edcb42 100755 --- a/python/obitools3/version.py +++ b/python/obitools3/version.py @@ -1,5 +1,5 @@ major = 3 minor = 0 -serial= '0-beta7' +serial= '0-beta8' version ="%d.%02d.%s" % (major,minor,serial)