Skip to content

Commit d085cfb

Browse files
committed
fixed minor typos and typing hint errors
1 parent daf86c6 commit d085cfb

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

mmif/utils/video_document_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def extract_frames_as_images(video_document: Document, framenums: List[int], as_
102102

103103
def get_mid_framenum(mmif: Mmif, time_frame: Annotation) -> int:
104104
warnings.warn('This function is deprecated. Use ``get_representative_framenums()`` instead.', DeprecationWarning, stacklevel=2)
105-
_get_mid_framenum(mmif, time_frame)
105+
return _get_mid_framenum(mmif, time_frame)
106106

107107

108108
def _get_mid_framenum(mmif: Mmif, time_frame: Annotation) -> int:
@@ -116,7 +116,7 @@ def _get_mid_framenum(mmif: Mmif, time_frame: Annotation) -> int:
116116
timeunit = time_frame.get_property('timeUnit')
117117
video_document = mmif[time_frame.get_property('document')]
118118
fps = get_framerate(video_document)
119-
return convert(time_frame.get_property('start') + time_frame.get_property('end'), timeunit, 'frame', fps) // 2
119+
return int(convert(time_frame.get_property('start') + time_frame.get_property('end'), timeunit, 'frame', fps) // 2)
120120

121121

122122
def extract_mid_frame(mmif: Mmif, time_frame: Annotation, as_PIL: bool = False):
@@ -159,7 +159,7 @@ def get_representative_framenums(mmif: Mmif, time_frame: Annotation) -> List[int
159159
rep_anno = mmif[rep_long_id]
160160
except KeyError:
161161
raise ValueError(f'Representative timepoint {rep_long_id} not found in any view.')
162-
ref_frams.append(convert(rep_anno.get_property('timePoint'), timeunit, 'frame', fps))
162+
ref_frams.append(int(convert(rep_anno.get_property('timePoint'), timeunit, 'frame', fps)))
163163
return ref_frams
164164

165165

@@ -185,7 +185,7 @@ def extract_representative_frame(mmif: Mmif, time_frame: Annotation, as_PIL: boo
185185
:return: frame as a :py:class:`numpy.ndarray` or :py:class:`PIL.Image.Image`
186186
"""
187187
video_document = mmif[time_frame.get_property('document')]
188-
rep_frame_num = [get_representative_framenum(mmif, time_frame)] if first_only else: get_representative_framenums(mmif, time_frame)
188+
rep_frame_num = [get_representative_framenum(mmif, time_frame)] if first_only else get_representative_framenums(mmif, time_frame)
189189
return extract_frames_as_images(video_document, rep_frame_num, as_PIL=as_PIL)[0]
190190

191191

tests/test_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ def test_extract_representative_frame(self):
5252
rep_frame_num = vdh.get_representative_framenum(self.mmif_obj, tf)
5353
expected_frame_num = vdh.millisecond_to_framenum(self.video_doc, tp.get_property('timePoint'))
5454
self.assertEqual(expected_frame_num, rep_frame_num)
55-
# check there is an error if no representatives
55+
# and should work even if no representatives are provided
5656
tf = self.a_view.new_annotation(AnnotationTypes.TimeFrame, start=1000, end=2000, timeUnit='milliseconds', document='d1')
57-
with pytest.raises(ValueError):
58-
vdh.get_representative_framenum(self.mmif_obj, tf)
59-
# check there is an error if there is a representative referencing a timepoint that
60-
# does not exist
57+
self.assertEqual(vdh.get_representative_framenum(self.mmif_obj, tf), vdh.get_mid_framenum(self.mmif_obj, tf))
58+
# check there is an error if there is a representative referencing a timepoint that does not exist
6159
tf.add_property('representatives', ['fake_tp_id'])
6260
with pytest.raises(ValueError):
6361
vdh.get_representative_framenum(self.mmif_obj, tf)

0 commit comments

Comments
 (0)