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

add transformer functions and mappers #2

Merged
merged 9 commits into from
Oct 11, 2023
Merged

add transformer functions and mappers #2

merged 9 commits into from
Oct 11, 2023

Conversation

SeanSCao
Copy link
Collaborator

No description provided.

Copy link
Member

Choose a reason for hiding this comment

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

The python recomendation for module (source file) names is to be snakecased (lowercase with underscores). You'll definitely see some examples in iSamples code that don't follow this but I did those before I knew better. Since you're starting fresh I'd go ahead and rename the filename (and you'll need to redo any associated imports).

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This isn't a hard and fast rule, but we try and conform to these conventions when it makes sense.

@@ -400,7 +398,7 @@ class Sample(SQLModel, table=True):
launch_type: Optional["Launch_Type"] = Relationship()
nav_type: Optional["Nav_Type"] = Relationship()
additional_names: Optional[List["Sample_Additional_Name"]] = Relationship()
sample_type: Optional["Sample_Type"] = Relationship(
sample_type: "Sample_Type" = Relationship(
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious why this changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Every sample in sesar is required to have a sample type and certain assumptions (about a sample type existing) made in the transformer functions were giving errors in mypy.

sample_type_str = sample_type.name
keyword_arr.append({
"keyword": sample_type_str,
"scheme_name": "SESAR: Sample Type"
Copy link
Member

Choose a reason for hiding this comment

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

Generally speaking I think these schemes are supposed to be URIs. I'll double check what OpenContext is doing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is just copying what i saw in the examples


def id_string(self) -> str:
return "https://data.isamples.org/digitalsample/{0}/{1}".format(
'igsn', self.sample.igsn
Copy link
Member

@dannymandel dannymandel Sep 19, 2023

Choose a reason for hiding this comment

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

f strings are the new python coolness, I'd recommend rewriting as

return f"https://data.isamples.org/digitalsample/igsn/{self.sample.igsn}". Under the covers it does the same thing as this. but with much friendlier syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah i'd been using f strings in other spots, but this was probably a copy paste of existing code

Copy link
Member

Choose a reason for hiding this comment

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

It would be good to formalize these as tests. Will post a link to how we do this in iSamples…

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Let me know if you have any questions on these.

Copy link
Member

Choose a reason for hiding this comment

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

You would need to make some test files with the raw SESAR source records as well.

Copy link
Member

Choose a reason for hiding this comment

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

Same comment on filename (module name), should be snake case.

@dannymandel
Copy link
Member

It would be good to add some unit tests to the database layer using sqlite, here's an example of how we do it in iSamples code: https://github.com/isamplesorg/isamples_inabox/blob/develop/tests/test_sqlmodel_database.py

@SeanSCao
Copy link
Collaborator Author

SeanSCao commented Oct 2, 2023

Tests require database connection, should these just be ignored by the github action?

Copy link

@griffin-dann griffin-dann left a comment

Choose a reason for hiding this comment

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

lgtm

)
country = Country(
country_id=1,
name="Wakanda"

Choose a reason for hiding this comment

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

Forever?

@dannymandel
Copy link
Member

@SeanSCao -- the tests should have a database connection to the in-memory database and run as part of the github action. Are some tests trying to connect to postgresql? That definitely shouldn't be happening.

@dannymandel
Copy link
Member

I think I see what you mean -- you have two test files, one against (presumably) a live postgres db and one against sqlite? If that's what you're asking, then yeah you can ignore the one running against postgres like this:

@pytest.mark.skipif(
    os.environ.get("CI") is not None, reason="Don't run live requests in CI"
)

When github runs the action it sets the CI=1 envvar so pytest will skip. Note that this will require you to run that test manually, and it's fine to do so (I have some solr tests I run like that).

@SeanSCao SeanSCao merged commit cb794b9 into main Oct 11, 2023
1 check passed
@SeanSCao SeanSCao deleted the transformer branch October 11, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants