| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 65afa9a commit 693f877
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | Type, | |
| 11 | 11 | TypeVar, | |
| 12 | 12 | Union, | |
| 13 | + cast, | ||
| 13 | 14 | overload, | |
| 14 | 15 | ) | |
| 15 | 16 | ||
@@ -267,8 +268,18 @@ def validate( | |||
| 267 | 268 | ): | |
| 268 | 269 | from docarray.array.doc_vec.doc_vec import DocVec | |
| 269 | 270 | ||
| 270 | - if isinstance(value, (cls, DocVec)): | ||
| 271 | + if isinstance(value, cls): | ||
| 271 | 272 | return value | |
| 273 | + elif isinstance(value, DocVec): | ||
| 274 | + if ( | ||
| 275 | + issubclass(value.doc_type, cls.doc_type) | ||
| 276 | + or value.doc_type == cls.doc_type | ||
| 277 | + ): | ||
| 278 | + return cast(T, value.to_doc_list()) | ||
| 279 | + else: | ||
| 280 | + raise ValueError( | ||
| 281 | + f'DocList[value.doc_type] is not compatible with {cls}' | ||
| 282 | + ) | ||
| 272 | 283 | elif isinstance(value, cls): | |
| 273 | 284 | return cls(value) | |
| 274 | 285 | elif isinstance(value, Iterable): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -293,6 +293,14 @@ def validate( | |||
| 293 | 293 | ) -> T: | |
| 294 | 294 | if isinstance(value, cls): | |
| 295 | 295 | return value | |
| 296 | + elif isinstance(value, DocList): | ||
| 297 | + if ( | ||
| 298 | + issubclass(value.doc_type, cls.doc_type) | ||
| 299 | + or value.doc_type == cls.doc_type | ||
| 300 | + ): | ||
| 301 | + return cast(T, value.to_doc_vec()) | ||
| 302 | + else: | ||
| 303 | + raise ValueError(f'DocVec[value.doc_type] is not compatible with {cls}') | ||
| 296 | 304 | elif isinstance(value, DocList.__class_getitem__(cls.doc_type)): | |
| 297 | 305 | return cast(T, value.to_doc_vec()) | |
| 298 | 306 | elif isinstance(value, Sequence): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -359,7 +359,7 @@ def test_to_device(): | |||
| 359 | 359 | ||
| 360 | 360 | def test_to_device_with_nested_da(): | |
| 361 | 361 | class Video(BaseDoc): | |
| 362 | - images: DocList[ImageDoc] | ||
| 362 | + images: DocVec[ImageDoc] | ||
| 363 | 363 | ||
| 364 | 364 | da_image = DocVec[ImageDoc]( | |
| 365 | 365 | [ImageDoc(tensor=torch.zeros(3, 5))], tensor_type=TorchTensor | |
| Back | FazBrowse Home | New Git URL |
0 commit comments