File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -827,6 +827,11 @@ def test_transforms_v2_wrapper_spawn(self):
827
827
with self .create_dataset (transform = v2 .Resize (size = expected_size )) as (dataset , _ ):
828
828
datasets_utils .check_transforms_v2_wrapper_spawn (dataset , expected_size = expected_size )
829
829
830
+ def test_slice_error (self ):
831
+ with self .create_dataset () as (dataset , _ ):
832
+ with pytest .raises (ValueError , match = "Index must be of type integer" ):
833
+ dataset [:2 ]
834
+
830
835
831
836
class CocoCaptionsTestCase (CocoDetectionTestCase ):
832
837
DATASET_CLASS = datasets .CocoCaptions
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ def _load_target(self, id: int) -> List[Any]:
44
44
return self .coco .loadAnns (self .coco .getAnnIds (id ))
45
45
46
46
def __getitem__ (self , index : int ) -> Tuple [Any , Any ]:
47
+
48
+ if not isinstance (index , int ):
49
+ raise ValueError (f"Index must be of type integer, got { type (index )} instead." )
50
+
47
51
id = self .ids [index ]
48
52
image = self ._load_image (id )
49
53
target = self ._load_target (id )
You can’t perform that action at this time.
0 commit comments