From b63926165c60b6a6e7ee309d70534e07012b3946 Mon Sep 17 00:00:00 2001 From: Jeremy McCormick Date: Thu, 26 Sep 2024 16:48:39 -0500 Subject: [PATCH] Fix bugs in how size and arraysize were being handled Fix obvious bug where wrong arraysize variable was being used in setting size. Do not set arraysize automatically for fields with length of 1. --- python/felis/tap.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/felis/tap.py b/python/felis/tap.py index d7e91e26..efb116ba 100644 --- a/python/felis/tap.py +++ b/python/felis/tap.py @@ -407,7 +407,9 @@ def visit_column(self, column_obj: datamodel.Column, table_obj: Table) -> Tap11B felis_type = FelisType.felis_type(felis_datatype.value) column.datatype = column_obj.votable_datatype or felis_type.votable_name - column.arraysize = column_obj.votable_arraysize or column_obj.length + column.arraysize = column_obj.votable_arraysize or ( + column_obj.length if (column_obj.length is not None and column_obj.length > 1) else None + ) if (felis_type.is_timestamp or column_obj.datatype == "text") and column.arraysize is None: column.arraysize = "*" @@ -419,7 +421,7 @@ def _is_int(s: str) -> bool: return False # Handle the deprecated size attribute - arraysize = column_obj.votable_arraysize + arraysize = column.arraysize if arraysize is not None and arraysize != "": if isinstance(arraysize, int): column.size = arraysize @@ -427,8 +429,9 @@ def _is_int(s: str) -> bool: column.size = int(arraysize) elif bool(re.match(r"^[0-9]+\*$", arraysize)): column.size = int(arraysize.replace("*", "")) - if column.size is not None: - logger.debug(f"Set size to {column.size} for {column.column_name} from arraysize {arraysize}") + + if column.size is not None: + logger.debug(f"Set size to {column.size} for {column.column_name} with arraysize {arraysize}") column.xtype = column_obj.votable_xtype column.description = column_obj.description