code: def test_to_clips(self):
      dataset = fo.Dataset()
      dataset.add_sample_field("support", fo.FrameSupportField)
      dataset.add_sample_field(
          "supports", fo.ListField, subfield=fo.FrameSupportField
      )
  
      sample1 = fo.Sample(
          filepath="video1.mp4",
          metadata=fo.VideoMetadata(total_frame_count=4),
          tags=["test"],
          weather="sunny",
          events=fo.TemporalDetections(
              detections=[
                  fo.TemporalDetection(label="meeting", support=[1, 3]),
                  fo.TemporalDetection(label="party", support=[2, 4]),
              ]
          ),
          support=[1, 2],
          supports=[[1, 1], [2, 3]],
      )
      sample1.frames[1] = fo.Frame(hello="world")
      sample1.frames[3] = fo.Frame(hello="goodbye")
  
      sample2 = fo.Sample(
          filepath="video2.mp4",
          metadata=fo.VideoMetadata(total_frame_count=5),
          tags=["test"],
          weather="cloudy",
          events=fo.TemporalDetections(
              detections=[
                  fo.TemporalDetection(label="party", support=[3, 5]),
                  fo.TemporalDetection(label="meeting", support=[1, 3]),
              ]
          ),
          support=[1, 4],
          supports=[[1, 3], [4, 5]],
      )
      sample2.frames[1] = fo.Frame(hello="goodbye")
      sample2.frames[3] = fo.Frame()
      sample2.frames[5] = fo.Frame(hello="there")
  
      dataset.add_samples([sample1, sample2])
      self.assertEqual(dataset.to_clips("support").count("frames"), 3)
      self.assertEqual(dataset.to_clips("supports").count("frames"), 5)
  
      view = dataset.to_clips("events")
  
      self.assertSetEqual(
          set(view.get_field_schema().keys()),
          {
              "id",
              "sample_id",
              "filepath",
              "support",
              "metadata",
              "tags",
              "events",
          },
      )
  
      self.assertEqual(
          view.get_field("metadata").document_type,
          fo.VideoMetadata,
      )
  
      self.assertListEqual(
          view.distinct("dataset_id"),
          [str(view._dataset._doc.id)],
      )
  
      self.assertSetEqual(
          set(view.select_fields().get_field_schema().keys()),
          {
              "id",
              "sample_id",
              "filepath",
              "support",
              "metadata",
              "tags",
          },
      )
  
      with self.assertRaises(ValueError):
          view.exclude_fields(
              "sample_id"
          )  # can't exclude default field
  
      with self.assertRaises(ValueError):
          view.exclude_fields("support")  # can't exclude default field
  
      index_info = view.get_index_information()
      indexes = view.list_indexes()
  
      default_indexes = {
          "id",
          "filepath",
          "sample_id",
          "frames.id",
          "frames._sample_id_1_frame_number_1",
      }
      self.assertSetEqual(set(index_info.keys()), default_indexes)
      self.assertSetEqual(set(indexes), default_indexes)
  
      with self.assertRaises(ValueError):
          view.drop_index("id")  # can't drop default index
  
      with self.assertRaises(ValueError):
          view.drop_index("filepath")  # can't drop default index
  
      with self.assertRaises(ValueError):
          view.drop_index("sample_id")  # can't drop default index
  
      self.assertEqual(len(view), 4)
  
      clip = view.first()
      self.assertIsInstance(clip.id, str)
      self.assertIsInstance(clip._id, ObjectId)
      self.assertIsInstance(clip.sample_id, str)
      self.assertIsInstance(clip._sample_id, ObjectId)
      self.assertIsInstance(clip.support, list)
      self.assertEqual(len(clip.support), 2)
  
      frames = []
      for clip in view:
          frames.append(list(clip.frames.keys()))
  
      self.assertListEqual(frames, [[1, 3], [3], [3, 5], [1, 3]])
  
      clip = view.first()
      clip.frames[1].hello = "there"
      clip.frames[2].hello = "there"
      clip.frames[3].hello = "there"
      clip.save()
  
      sample1.reload()
      for frame_number in [1, 2, 3]:
          frame = sample1.frames[frame_number]
          self.assertEqual(frame.hello, "there")
  
      clip = view.last()
      clip.frames[2]["world"] = "leader"
      clip.save()
  
      self.assertIn("world", view.get_frame_field_schema())
      self.assertIn("world", dataset.get_frame_field_schema())
  
      for _id in view.values("id"):
          self.assertIsInstance(_id, str)
  
      for oid in view.values("_id"):
          self.assertIsInstance(oid, ObjectId)
  
      for _id in view.values("sample_id"):
          self.assertIsInstance(_id, str)
  
      for oid in view.values("_sample_id"):
          self.assertIsInstance(oid, ObjectId)
  
      self.assertDictEqual(dataset.count_sample_tags(), {"test": 2})
      self.assertDictEqual(view.count_sample_tags(), {"test": 4})
  
      view.tag_samples("foo")
  
      self.assertEqual(view.count_sample_tags()["foo"], 4)
      self.assertNotIn("foo", dataset.count_sample_tags())
  
      view.untag_samples("foo")
  
      self.assertNotIn("foo", view.count_sample_tags())
  
      view.tag_labels("test")
  
      self.assertDictEqual(view.count_label_tags(), {"test": 4})
      self.assertDictEqual(dataset.count_label_tags(), {"test": 4})
  
      view.select_labels(tags="test").untag_labels("test")
  
      self.assertDictEqual(view.count_label_tags(), {})
      self.assertDictEqual(dataset.count_label_tags(), {})
  
      view2 = view.skip(2).set_field("events.label", F("label").upper())
  
      self.assertDictEqual(
          view2.count_values("events.label"), {"PARTY": 1, "MEETING": 1}
      )
      self.assertDictEqual(
          view.count_values("events.label"), {"party": 2, "meeting": 2}
      )
      self.assertDictEqual(
          dataset.count_values("events.detections.label"),
          {"meeting": 2, "party": 2},
      )
  
      values = {
          _id: v
          for _id, v in zip(
              *view2.values(["events.id", "events.label"])
          )
      }
      view.set_label_values("events.also_label", values)
  
      self.assertEqual(view.count("events.also_label"), 2)
      self.assertEqual(dataset.count("events.detections.also_label"), 2)
      self.assertDictEqual(
          view.count_values("events.also_label"),
          dataset.count_values("events.detections.also_label"),
      )
  
      view2.save()
  
      self.assertEqual(len(view), 4)
      self.assertEqual(dataset.count("events.detections"), 4)
      self.assertIn("MEETING", view.count_values("events.label"))
      self.assertIn("PARTY", view.count_values("events.label"))
      self.assertIn(
          "MEETING", dataset.count_values("events.detections.label")
      )
      self.assertIn(
          "PARTY", dataset.count_values("events.detections.label")
      )
      self.assertIsNotNone(view.first().id)
      self.assertIsNotNone(dataset.last().id)
  
      view2.keep()
  
      self.assertEqual(len(view), 2)
      self.assertEqual(dataset.count("events.detections"), 2)
      self.assertDictEqual(
          view.count_values("events.label"), {"MEETING": 1, "PARTY": 1}
      )
      self.assertDictEqual(
          dataset.count_values("events.detections.label"),
          {"MEETING": 1, "PARTY": 1},
      )
      self.assertIsNotNone(view.first().id)
      self.assertIsNotNone(dataset.last().id)
  
      sample = view.first()
  
      sample["foo"] = "bar"
      sample["events"].label = "party"
      sample.save()
  
      self.assertIn("foo", view.get_field_schema())
      self.assertNotIn("foo", dataset.get_frame_field_schema())
      self.assertDictEqual(
          view.count_values("events.label"), {"party": 1, "MEETING": 1}
      )
      self.assertDictEqual(
          dataset.count_values("events.detections.label"),
          {"party": 1, "MEETING": 1},
      )
  
      dataset.untag_samples("test")
      view.reload()
  
      self.assertEqual(dataset.count_sample_tags(), {})
      self.assertEqual(view.count_sample_tags(), {})
  
      view.exclude_fields("frames.hello").keep_fields()
  
      self.assertNotIn("hello", view.get_frame_field_schema())
      self.assertNotIn("hello", dataset.get_frame_field_schema())
  
      frame_view = view.first().frames.first()
      with self.assertRaises(KeyError):
          frame_view["hello"]
  
      frame = dataset.first().frames.first()
      with self.assertRaises(KeyError):
          frame["hello"]
  
      view.select_fields().keep_fields()
  
      self.assertNotIn("events", view.get_field_schema())
      self.assertNotIn("events", dataset.get_field_schema())
  
      sample_view = view.first()
      with self.assertRaises(KeyError):
          sample_view["events"]
  
      sample = dataset.first()
      with self.assertRaises(KeyError):
          sample["events"]
  
      # Test saving a clips view
  
      self.assertIsNone(view.name)
  
      view_name = "test"
      dataset.save_view(view_name, view)
      self.assertEqual(view.name, view_name)
      self.assertTrue(view.is_saved)
  
      also_view = dataset.load_saved_view(view_name)
      self.assertEqual(view, also_view)
      self.assertEqual(also_view.name, view_name)
      self.assertTrue(also_view.is_saved)
  
      still_view = deepcopy(view)
      self.assertEqual(still_view.name, view_name)
      self.assertTrue(still_view.is_saved)
      self.assertEqual(still_view, view)
  
imports: from copy import deepcopy
  from datetime import date, datetime
  from bson import ObjectId
  import numpy
  import unittest
  import fiftyone
  import fiftyone.core.odm
  from fiftyone import ViewField
  from decorators import drop_datasets
label_desc: Use image node_id 24 for calling the VideoTests obj's underlying member method code with example usage: obj.test_to_clips() without return types