From 3e93cfff7bdb1d386274ec2d6171c0c1ba3480ae Mon Sep 17 00:00:00 2001 From: MercierC Date: Mon, 29 Mar 2021 09:00:52 +1300 Subject: [PATCH] import: Columns are now rewritten in OBI_FLOAT if a value is > INT32_MAX --- python/obitools3/commands/import.pyx | 6 +++--- python/obitools3/dms/capi/obitypes.pxd | 2 ++ python/obitools3/utils.pyx | 5 +++-- src/obitypes.h | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/python/obitools3/commands/import.pyx b/python/obitools3/commands/import.pyx index 711dc47..b2d4a9e 100755 --- a/python/obitools3/commands/import.pyx +++ b/python/obitools3/commands/import.pyx @@ -371,8 +371,8 @@ def run(config): # Fill value dcols[tag][0][i] = value - except IndexError : - + except (IndexError, OverflowError): + value_type = type(value) old_column = dcols[tag][0] old_nb_elements_per_line = old_column.nb_elements_per_line @@ -419,7 +419,7 @@ def run(config): dcols[tag][0][i] = value except Exception as e: - print("\nCould not import sequence id:", entry.id, "(error raised:", e, ")") + print("\nCould not import sequence:", entry, "(error raised:", e, ")") if 'skiperror' in config['obi'] and not config['obi']['skiperror']: raise e else: diff --git a/python/obitools3/dms/capi/obitypes.pxd b/python/obitools3/dms/capi/obitypes.pxd index 7b403cb..ed0b7d7 100755 --- a/python/obitools3/dms/capi/obitypes.pxd +++ b/python/obitools3/dms/capi/obitypes.pxd @@ -53,6 +53,8 @@ cdef extern from "obitypes.h" nogil: extern const_char_p OBIQual_char_NA extern uint8_t* OBIQual_int_NA extern void* OBITuple_NA + + extern obiint_t OBI_INT_MAX const_char_p name_data_type(int data_type) diff --git a/python/obitools3/utils.pyx b/python/obitools3/utils.pyx index 3959aa0..28c1367 100755 --- a/python/obitools3/utils.pyx +++ b/python/obitools3/utils.pyx @@ -9,7 +9,8 @@ from obitools3.dms.capi.obitypes cimport is_a_DNA_seq, \ OBI_QUAL, \ OBI_SEQ, \ OBI_STR, \ - index_t + index_t, \ + OBI_INT_MAX from obitools3.dms.capi.obierrno cimport OBI_LINE_IDX_ERROR, \ OBI_ELT_IDX_ERROR, \ @@ -258,7 +259,7 @@ cdef obitype_t update_obitype(obitype_t obitype, object new_value) : new_type = type(new_value) if obitype == OBI_INT : - if new_type == float : + if new_type == float or new_value > OBI_INT_MAX : return OBI_FLOAT # TODO BOOL vers INT/FLOAT elif new_type == str or new_type == bytes : diff --git a/src/obitypes.h b/src/obitypes.h index f7e4441..ea773dd 100755 --- a/src/obitypes.h +++ b/src/obitypes.h @@ -29,6 +29,8 @@ #define OBIQual_int_NA (NULL) /**< NA value for the type OBI_QUAL if the quality is in integer format */ #define OBITuple_NA (NULL) /**< NA value for tuples of any type */ +#define OBI_INT_MAX (INT32_MAX) /**< Maximum value for the type OBI_INT */ + /** * @brief enum for the boolean OBIType.