Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in how size and arraysize were being handled #106

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions python/felis/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where column_obj.votable_arraysize is None column_obj_length == 1 and we want column.arraysize set to that?

Copy link
Collaborator Author

@JeremyMcCormick JeremyMcCormick Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says in the TAP 1.1 spec that arraysize should never be set to 1 but should be null instead in this case.

)
if (felis_type.is_timestamp or column_obj.datatype == "text") and column.arraysize is None:
column.arraysize = "*"

Expand All @@ -419,16 +421,17 @@ 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
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}")

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
Expand Down
Loading