Skip to content

Commit

Permalink
tap_schema.py: rewrite _get_size function
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Oct 3, 2024
1 parent 398f6cd commit f74ea89
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions python/felis/tap_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,24 +605,20 @@ def _get_size(column: datamodel.Column) -> int | None:
int or None
The size of the column or None if not applicable.
"""
arraysize = column.votable_arraysize

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

size = None
arraysize = column.votable_arraysize
if arraysize is not None and str(arraysize) != "":
if isinstance(arraysize, int):
size = arraysize
elif _is_int(arraysize):
size = int(arraysize)
elif bool(re.match(r"^[0-9]+\*$", arraysize)):
size = int(arraysize.replace("*", ""))
return size
arraysize_str = str(arraysize)
if arraysize_str.isdigit():
return int(arraysize_str)

match = re.match(r"^([0-9]+)\*$", arraysize_str)
if match and match.group(1) is not None:
return int(match.group(1))

return None

@staticmethod
def _is_indexed(column: datamodel.Column, table: datamodel.Table) -> int:
Expand Down

0 comments on commit f74ea89

Please sign in to comment.