-
Notifications
You must be signed in to change notification settings - Fork 150
Fix sample validation for complex types #1973
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR fixes type validation for complex generic types in the experimental dataset module. The validation logic was incorrectly handling generic type annotations, causing validation errors for fields with list-type specifications.
Key Changes:
- Fixed
_validate_attribute_typeto use the origin type for generic type validation - Added test coverage for samples with list-type fields
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/datumaro/experimental/dataset.py | Updated type validation to handle generic types by checking the origin type |
| tests/unit/experimental/test_sample.py | Added test for creating samples with list-type fields to verify the validation fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1bbdec3 to
5e15aa8
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
5e15aa8 to
6431a18
Compare
leoll2
left a comment
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.
Fix looks good to me, only one comment
Signed-off-by: Jort Bergfeld <[email protected]>
Signed-off-by: Jort Bergfeld <[email protected]>
Signed-off-by: Jort Bergfeld <[email protected]>
Signed-off-by: Jort Bergfeld <[email protected]>
5751690 to
f075b50
Compare
This pull request fixes a problem with type validation in the experimental dataset and sample modules. When we use the is_list boolean of score_field, a complex ndarray type is generated that includes an Any type, which is not accepted by isinstance. To circumvent problems with complex types, whenever isintance fails with a type error, we only validate against the origin type (ndarray instead of ndarray[float32], for example)
Type validation improvements
_validate_attribute_typemethod insrc/datumaro/experimental/dataset.pyto correctly handle type validation for generic types by usingoriginwhen available, improving support for complex type annotations.Test enhancements
test_sample_with_is_list, intests/unit/experimental/test_sample.pyto verify that samples with list-type fields (usingis_list=Trueinscore_field) are created without validation errors.Resolves #1971