Commit 6497f58
authored
Fix sample validation for complex types (#1973)
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
* Updated the `_validate_attribute_type` method in
`src/datumaro/experimental/dataset.py` to correctly handle type
validation for generic types by using `origin` when available, improving
support for complex type annotations.
### Test enhancements
* Added a new test, `test_sample_with_is_list`, in
`tests/unit/experimental/test_sample.py` to verify that samples with
list-type fields (using `is_list=True` in `score_field`) are created
without validation errors.
Resolves #1971
---------
Signed-off-by: Jort Bergfeld <[email protected]>1 parent 42138a8 commit 6497f58
File tree
2 files changed
+22
-5
lines changed- src/datumaro/experimental
- tests/unit/experimental
2 files changed
+22
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
0 commit comments