-
Notifications
You must be signed in to change notification settings - Fork 68
Fix annotation data type coersion by Pydantic #1009
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
Conversation
assert label.annotations[0].confidence == 0.914 | ||
|
||
|
||
def test_initialize_label_no_coersion(): |
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.
small typo here, coersion
=> coercion
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.
Good catch! fixed!
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.
awesome work BTW!
class DicomData(BaseData): | ||
... | ||
class DicomData(BaseData, _NoCoercionMixin): | ||
data_type: Literal["DicomData"] = "DicomData" |
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.
should this be class_name
?
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.
good catch! fixed it.
""" | ||
uid: Optional[Cuid] = None | ||
data: Union[VideoData, ImageData, TextData, TiledImageData] | ||
data: DataType |
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.
is this a generic pydantic type? sorry pydantic documentation links do not work for me for some reason
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've defined this type on line 19 above since the list was getting too long.
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.
Fantastic, we should extend it to all our union types... as you know they are all susceptible
9ace2a2
to
3e47e5c
Compare
3e47e5c
to
a50ca2b
Compare
a50ca2b
to
2959247
Compare
2959247
to
5ffc6dc
Compare
When creating a
Label
, the annotation data type class was being changed and the global_key field was disappearing. Example:Output
The problem was that Pydantic tries to coerce objects to the first class listed in a Union. See Pydantic docs for more details.
This is fixed by adding a discriminator field (
class_name
) which is ignored during serialization.