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

[PLT-1725] Changed ontology dataclasses to pydantic dataclasses #1910

Closed
wants to merge 9 commits into from

Conversation

Gabefire
Copy link
Collaborator

@Gabefire Gabefire commented Nov 17, 2024

Description

  • Pydantic V2 has a standin replacement for python dataclasses but with more features and better validation.
  • Changed ontology creation to take advantage of pydantic features

For example for this code:

classification_features = [
    lb.Classification(
        class_type="test",
        name=1,
        options=[
            lb.Option(value="blurry", label="Blurry"),
            lb.Option(value="distorted", label="Distorted"),
        ],
    )
]

ontology_builder = lb.OntologyBuilder(classifications=classification_features).asdict()

class_type and name is given the wrong type for the classification feature (string instead of an enum value and int instead of string). Before change, it would give this error
image
With pydantic validation it gives this error (catching the name being an int as well)
image

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

All Submissions

  • Have you followed the guidelines in our Contributing document?
  • Have you provided a description?
  • Are your changes properly formatted?

@Gabefire Gabefire requested a review from a team as a code owner November 17, 2024 13:46
@Gabefire Gabefire changed the title [PLT-1725] Changed ontology dataclasses to pydantic dataclasses [PLT-1725] Changed dataclasses to pydantic dataclasses Nov 17, 2024
@Gabefire Gabefire added the hold do not review yet! label Nov 17, 2024
@Gabefire Gabefire force-pushed the gu/pydantic_dataclasses branch from 597095c to 46fe4d1 Compare November 17, 2024 15:03
@Gabefire Gabefire force-pushed the gu/pydantic_dataclasses branch from 46fe4d1 to 378f851 Compare November 17, 2024 15:05
@Gabefire Gabefire changed the title [PLT-1725] Changed dataclasses to pydantic dataclasses [PLT-1725] Changed ontology dataclasses to pydantic dataclasses Nov 17, 2024
@Gabefire Gabefire removed the hold do not review yet! label Nov 17, 2024
@Gabefire Gabefire added the hold do not review yet! label Nov 19, 2024
@Gabefire Gabefire requested a review from a team as a code owner November 22, 2024 21:25
@Gabefire Gabefire requested a review from vbrodsky January 20, 2025 15:01
@Gabefire Gabefire closed this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hold do not review yet!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants