Skip to content

Commit

Permalink
Implement handling of the deprecated size attribute in TAP
Browse files Browse the repository at this point in the history
Use the value for arraysize to set the size attribute in the TAP data.
  • Loading branch information
JeremyMcCormick committed Jul 22, 2024
1 parent 31936df commit ab3f7c9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion python/felis/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from __future__ import annotations

import logging
import re
from collections.abc import Iterable, MutableMapping
from typing import Any

Expand Down Expand Up @@ -125,7 +126,7 @@ class Tap11Columns(Tap11Base):
arraysize = Column(String(10))
xtype = Column(String(SIMPLE_FIELD_LENGTH))
# Size is deprecated
# size = Column(Integer(), quote=True)
size = Column("size", Integer(), quote=True)
description = Column(String(TEXT_FIELD_LENGTH))
utype = Column(String(SIMPLE_FIELD_LENGTH))
unit = Column(String(SIMPLE_FIELD_LENGTH))
Expand Down Expand Up @@ -410,6 +411,24 @@ def visit_column(self, column_obj: datamodel.Column, table_obj: Table) -> Tap11B
if (felis_type.is_timestamp or column_obj.datatype == "text") and column.arraysize is None:
column.arraysize = "*"

def _is_int(s: str) -> bool:
try:
int(s)
return True
except ValueError:
return False

# Handle the deprecated size attribute
if column_obj.votable_arraysize is not None and column_obj.votable_arraysize != "":
if isinstance(arraysize, int):
column.size = arraysize
elif _is_int(arraysize):
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}")

column.xtype = column_obj.votable_xtype
column.description = column_obj.description
column.utype = column_obj.votable_utype
Expand Down

0 comments on commit ab3f7c9

Please sign in to comment.