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-42935: Refactor tap module to use the Pydantic data model #49
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #49 +/- ##
==========================================
+ Coverage 91.14% 91.58% +0.43%
==========================================
Files 21 21
Lines 2225 2198 -27
Branches 468 458 -10
==========================================
- Hits 2028 2013 -15
+ Misses 131 125 -6
+ Partials 66 60 -6 ☔ View full report in Codecov by Sentry. |
51c0aab
to
db1de2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, a couple of minor comments.
db1de2d
to
37b235e
Compare
@gpdf Following our discussion of validating the new |
37b235e
to
17ca2bb
Compare
17ca2bb
to
95c017f
Compare
@gpdf As per discussion today, I reverted addition of the |
@andy-slac I invalidated your review, as there are some fix-ups needed here related to setting the TAP_SCHEMA index. I'll have @gpdf review this in its final form. |
95c017f
to
8e8d967
Compare
votable_utype: str | None = Field(None, alias="votable:utype") | ||
"""The VOTable utype (usage-specific or unique type) of the object.""" | ||
|
||
@model_validator(mode="after") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are a fix to the Pydantic model_validator
as it was using the wrong function signature.
f96594d
to
8e8d967
Compare
The tap module is updated to use the Pydantic data model, instead of the raw YAML. The "load-tap" command in the command line interface was also updated to use the Pydantic schema object. The PYLD transformations were removed from the cli function, as they seemed to be unnecessary. A few changes were made to the Pydantic data model to support setting of reasonable defaults. A "votable_datatype" annotation was added to Colum. The Column datatype was changed to return the enum instead of a string, as this setting seemed to confuse mypy. Tests were changed to conform to the new tap module and the minor changes to the data model. Testing showed that the schema was loaded correctly into a live PostgreSQL database.
8e8d967
to
9d639fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general. Please make the one change about the handling of missing table_index
values.
python/felis/datamodel.py
Outdated
@@ -391,7 +393,7 @@ class Table(BaseObject): | |||
primary_key: str | list[str] | None = Field(None, alias="primaryKey") | |||
"""The primary key of the table.""" | |||
|
|||
tap_table_index: int | None = Field(None, alias="tap:table_index") | |||
tap_table_index: int = Field(0, alias="tap:table_index") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please retain the ability for the model to distinguish between "missing" and zero table_index
values. We may wish to make the handling more sophisticated in the (near) future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think column_index still allows None
anyway, right?
python/felis/tap.py
Outdated
table.table_index = int(table_obj.get("tap:table_index", 0)) | ||
table.utype = table_obj.votable_utype | ||
table.description = table_obj.description | ||
table.table_index = table_obj.tap_table_index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line would have to be changed as well, perhaps to something like
table.table_index = 0 if table_obj.tap_table_index is None else table_obj.tap_table_index
Make the table index None by default instead of 0 and update the logic in the tap module accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
The tap module is updated to use the Pydantic data model, instead of the raw YAML. The "load-tap" command in the command line interface was also updated to use the Pydantic schema object. The PYLD transformations were removed from the cli function, as they seemed to be unnecessary. A few changes were made to the Pydantic data model to support setting of reasonable defaults. A "votable_datatype" annotation was added to Colum. The Column datatype was changed to return the enum instead of a string, as this setting seemed to confuse mypy. Tests were changed to conform to the new tap module and the minor changes to the data model. Testing showed that the schema was loaded correctly into a live PostgreSQL database.