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

DM-44878: Fill in the TAP_SCHEMA size attribute #83

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions python/felis/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import logging
from collections.abc import Mapping, Sequence
from enum import StrEnum, auto
from typing import Annotated, Any, Literal, TypeAlias
from typing import Annotated, Any, TypeAlias

from astropy import units as units # type: ignore
from astropy.io.votable import ucd # type: ignore
Expand Down Expand Up @@ -178,7 +178,7 @@ class Column(BaseObject):
tap_principal: int | None = Field(0, alias="tap:principal", ge=0, le=1)
"""Whether this is a TAP_SCHEMA principal column."""

votable_arraysize: int | Literal["*"] | None = Field(None, alias="votable:arraysize")
votable_arraysize: int | str | None = Field(None, alias="votable:arraysize")
"""VOTable arraysize of the column."""

tap_std: int | None = Field(0, alias="tap:std", ge=0, le=1)
Expand Down
22 changes: 21 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 @@
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,25 @@
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

Check warning on line 419 in python/felis/tap.py

View check run for this annotation

Codecov / codecov/patch

python/felis/tap.py#L415-L419

Added lines #L415 - L419 were not covered by tests

# Handle the deprecated size attribute
arraysize = column_obj.votable_arraysize
if arraysize is not None and arraysize != "":
if isinstance(arraysize, int):
column.size = arraysize

Check warning on line 425 in python/felis/tap.py

View check run for this annotation

Codecov / codecov/patch

python/felis/tap.py#L425

Added line #L425 was not covered by tests
elif _is_int(arraysize):
column.size = int(arraysize)

Check warning on line 427 in python/felis/tap.py

View check run for this annotation

Codecov / codecov/patch

python/felis/tap.py#L427

Added line #L427 was not covered by tests
elif bool(re.match(r"^[0-9]+\*$", arraysize)):
column.size = int(arraysize.replace("*", ""))

Check warning on line 429 in python/felis/tap.py

View check run for this annotation

Codecov / codecov/patch

python/felis/tap.py#L429

Added line #L429 was not covered by tests
if column.size is not None:
logger.debug(f"Set size to {column.size} for {column.column_name} from arraysize {arraysize}")

Check warning on line 431 in python/felis/tap.py

View check run for this annotation

Codecov / codecov/patch

python/felis/tap.py#L431

Added line #L431 was not covered by tests

column.xtype = column_obj.votable_xtype
column.description = column_obj.description
column.utype = column_obj.votable_utype
Expand Down
4 changes: 1 addition & 3 deletions tests/test_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import shutil
import tempfile
import unittest
from collections.abc import MutableMapping
from typing import Any

import sqlalchemy
import yaml
Expand All @@ -39,7 +37,7 @@
class VisitorTestCase(unittest.TestCase):
"""Test the TAP loading visitor."""

schema_obj: MutableMapping[str, Any] = {}
schema_obj: Schema

def setUp(self) -> None:
"""Load data from a test file."""
Expand Down
Loading