code: def test_to_frame_patches(self):
      dataset = fo.Dataset()
  
      sample1 = fo.Sample(
          filepath="video1.mp4",
          metadata=fo.VideoMetadata(total_frame_count=4),
          tags=["test"],
          weather="sunny",
      )
      sample1.frames[1] = fo.Frame(hello="world")
      sample1.frames[2] = fo.Frame(
          ground_truth=fo.Detections(
              detections=[
                  fo.Detection(label="cat"),
                  fo.Detection(label="dog"),
              ]
          )
      )
      sample1.frames[3] = fo.Frame(hello="goodbye")
  
      sample2 = fo.Sample(
          filepath="video2.mp4",
          metadata=fo.VideoMetadata(total_frame_count=5),
          tags=["test"],
          weather="cloudy",
      )
      sample2.frames[1] = fo.Frame(
          hello="goodbye",
          ground_truth=fo.Detections(
              detections=[
                  fo.Detection(label="dog"),
                  fo.Detection(label="rabbit"),
              ]
          ),
      )
      sample2.frames[3] = fo.Frame()
      sample2.frames[5] = fo.Frame(hello="there")
  
      dataset.add_samples([sample1, sample2])
  
      # User must first convert to frames, then patches
      with self.assertRaises(ValueError):
          dataset.to_patches("frames.ground_truth")
  
      frames = dataset.to_frames(sample_frames="dynamic")
      patches = frames.to_patches("ground_truth")
  
      self.assertSetEqual(
          set(patches.get_field_schema().keys()),
          {
              "id",
              "filepath",
              "metadata",
              "tags",
              "sample_id",
              "frame_id",
              "frame_number",
              "ground_truth",
          },
      )
  
      self.assertSetEqual(
          set(patches.select_fields().get_field_schema().keys()),
          {
              "id",
              "filepath",
              "metadata",
              "tags",
              "sample_id",
              "frame_id",
              "frame_number",
          },
      )
  
      with self.assertRaises(ValueError):
          patches.exclude_fields(
              "sample_id"
          )  # can't exclude default field
  
      with self.assertRaises(ValueError):
          patches.exclude_fields(
              "frame_id"
          )  # can't exclude default field
  
      with self.assertRaises(ValueError):
          patches.exclude_fields(
              "frame_number"
          )  # can't exclude default field
  
      index_info = patches.get_index_information()
      indexes = patches.list_indexes()
  
      default_indexes = {
          "id",
          "filepath",
          "sample_id",
          "frame_id",
          "_sample_id_1_frame_number_1",
      }
      self.assertSetEqual(set(index_info.keys()), default_indexes)
      self.assertSetEqual(set(indexes), default_indexes)
  
      with self.assertRaises(ValueError):
          patches.drop_index("id")  # can't drop default index
  
      with self.assertRaises(ValueError):
          patches.drop_index("filepath")  # can't drop default index
  
      with self.assertRaises(ValueError):
          patches.drop_index("sample_id")  # can't drop default index
  
      with self.assertRaises(ValueError):
          patches.drop_index("frame_id")  # can't drop default index
  
      self.assertEqual(
          dataset.count("frames.ground_truth.detections"), 4
      )
      self.assertEqual(patches.count(), 4)
      self.assertEqual(len(patches), 4)
  
      patch = patches.first()
      self.assertIsInstance(patch.id, str)
      self.assertIsInstance(patch._id, ObjectId)
      self.assertIsInstance(patch.sample_id, str)
      self.assertIsInstance(patch._sample_id, ObjectId)
      self.assertIsInstance(patch.frame_id, str)
      self.assertIsInstance(patch._frame_id, ObjectId)
      self.assertIsInstance(patch.frame_number, int)
  
      for _id in patches.values("id"):
          self.assertIsInstance(_id, str)
  
      for oid in patches.values("_id"):
          self.assertIsInstance(oid, ObjectId)
  
      for _id in patches.values("sample_id"):
          self.assertIsInstance(_id, str)
  
      for oid in patches.values("_sample_id"):
          self.assertIsInstance(oid, ObjectId)
  
      for _id in patches.values("frame_id"):
          self.assertIsInstance(_id, str)
  
      for oid in patches.values("_frame_id"):
          self.assertIsInstance(oid, ObjectId)
  
      self.assertDictEqual(dataset.count_sample_tags(), {"test": 2})
      self.assertDictEqual(patches.count_sample_tags(), {"test": 4})
  
      patches.tag_samples("patch")
  
      self.assertEqual(patches.count_sample_tags()["patch"], 4)
      self.assertNotIn("patch", frames.count_sample_tags())
      self.assertNotIn("patch", dataset.count_sample_tags())
  
      patches.untag_samples("patch")
  
      self.assertNotIn("patch", patches.count_sample_tags())
      self.assertNotIn("patch", frames.count_sample_tags())
      self.assertNotIn("patch", dataset.count_sample_tags())
  
      patches.tag_labels("test")
  
      self.assertDictEqual(patches.count_label_tags(), {"test": 4})
      self.assertDictEqual(frames.count_label_tags(), {"test": 4})
      self.assertDictEqual(
          dataset.count_label_tags("frames.ground_truth"), {"test": 4}
      )
  
      # Including `select_labels()` here tests an important property: if the
      # contents of a `view` changes after a save operation occurs, the
      # original view still needs to be synced with the source dataset
      patches.select_labels(tags="test").untag_labels("test")
  
      self.assertDictEqual(patches.count_label_tags(), {})
      self.assertDictEqual(frames.count_label_tags(), {})
      self.assertDictEqual(dataset.count_label_tags(), {})
  
      view2 = patches.limit(2)
  
      values = [l.upper() for l in view2.values("ground_truth.label")]
      view2.set_values("ground_truth.label_upper", values)
  
      self.assertEqual(dataset.count(), 2)
  
      # Empty frames were added based on metadata frame counts
      self.assertEqual(frames.count(), 9)
  
      self.assertEqual(patches.count(), 4)
      self.assertEqual(view2.count(), 2)
      self.assertEqual(
          dataset.count("frames.ground_truth.detections"), 4
      )
      self.assertEqual(frames.count("ground_truth.detections"), 4)
      self.assertEqual(patches.count("ground_truth"), 4)
      self.assertEqual(view2.count("ground_truth"), 2)
      self.assertEqual(
          dataset.count("frames.ground_truth.detections.label_upper"), 2
      )
      self.assertEqual(
          frames.count("ground_truth.detections.label_upper"), 2
      )
      self.assertEqual(patches.count("ground_truth.label_upper"), 2)
      self.assertEqual(view2.count("ground_truth.label_upper"), 2)
      self.assertIsNone(patches.get_field("ground_truth.label_upper"))
      self.assertIsNone(
          frames.get_field("ground_truth.detections.label_upper")
      )
      self.assertIsNone(
          dataset.get_field(
              "frames.ground_truth.detections.label_upper"
          )
      )
  
      view2.set_values(
          "ground_truth.label_dynamic", values, dynamic=True
      )
      self.assertIsNotNone(
          patches.get_field("ground_truth.label_dynamic")
      )
      self.assertIsNotNone(
          frames.get_field("ground_truth.detections.label_dynamic")
      )
      self.assertIsNotNone(
          dataset.get_field(
              "frames.ground_truth.detections.label_dynamic"
          )
      )
  
      values = {
          _id: v
          for _id, v in zip(
              *view2.values(["ground_truth.id", "ground_truth.label"])
          )
      }
      patches.set_label_values("ground_truth.also_label", values)
  
      self.assertEqual(patches.count("ground_truth.also_label"), 2)
      self.assertEqual(
          frames.count("ground_truth.detections.also_label"), 2
      )
      self.assertEqual(
          dataset.count("frames.ground_truth.detections.also_label"), 2
      )
      self.assertDictEqual(
          patches.count_values("ground_truth.also_label"),
          dataset.count_values(
              "frames.ground_truth.detections.also_label"
          ),
      )
      self.assertDictEqual(
          frames.count_values("ground_truth.detections.also_label"),
          dataset.count_values(
              "frames.ground_truth.detections.also_label"
          ),
      )
  
      view3 = patches.skip(2).set_field(
          "ground_truth.label", F("label").upper()
      )
  
      self.assertEqual(patches.count(), 4)
      self.assertEqual(view3.count(), 2)
      self.assertEqual(
          dataset.count("frames.ground_truth.detections"), 4
      )
      self.assertNotIn(
          "rabbit", view3.count_values("ground_truth.label")
      )
      self.assertEqual(
          view3.count_values("ground_truth.label")["RABBIT"], 1
      )
      self.assertNotIn(
          "RABBIT", patches.count_values("ground_truth.label")
      )
      self.assertNotIn(
          "RABBIT",
          dataset.count_values("frames.ground_truth.detections.label"),
      )
  
      view3.save()
  
      self.assertEqual(patches.count(), 4)
      self.assertEqual(frames.count(), 9)
      self.assertEqual(dataset.count(), 2)
      self.assertEqual(patches.count("ground_truth"), 4)
      self.assertEqual(frames.count("ground_truth.detections"), 4)
      self.assertEqual(dataset.count("frames"), 6)
      self.assertEqual(
          dataset.count("frames.ground_truth.detections"), 4
      )
      self.assertIn(
          "RABBIT", patches.count_values("ground_truth.label")
      )
      self.assertIn(
          "RABBIT", frames.count_values("ground_truth.detections.label")
      )
      self.assertIn(
          "RABBIT",
          dataset.count_values("frames.ground_truth.detections.label"),
      )
  
      view3.keep()
  
      self.assertEqual(patches.count(), 2)
      self.assertEqual(frames.count(), 9)
      self.assertEqual(dataset.count(), 2)
      self.assertEqual(patches.count("ground_truth"), 2)
      self.assertEqual(frames.count("ground_truth.detections"), 2)
      self.assertEqual(dataset.count("frames"), 6)
      self.assertEqual(
          dataset.count("frames.ground_truth.detections"), 2
      )
  
      sample = patches.first()
  
      sample.ground_truth["hello"] = "world"
      sample.save()
  
      self.assertEqual(
          patches.count_values("ground_truth.hello")["world"], 1
      )
      self.assertEqual(
          frames.count_values("ground_truth.detections.hello")["world"],
          1,
      )
      self.assertEqual(
          dataset.count_values("frames.ground_truth.detections.hello")[
              "world"
          ],
          1,
      )
  
      dataset.untag_samples("test")
      patches.reload()
  
      self.assertDictEqual(dataset.count_sample_tags(), {})
      self.assertDictEqual(frames.count_sample_tags(), {})
      self.assertDictEqual(patches.count_sample_tags(), {})
  
      patches.tag_labels("test")
  
      self.assertDictEqual(
          patches.count_label_tags(), frames.count_label_tags()
      )
      self.assertDictEqual(
          patches.count_label_tags(), dataset.count_label_tags()
      )
  
      # Including `select_labels()` here tests an important property: if the
      # contents of a `view` changes after a save operation occurs, the
      # original view still needs to be synced with the source dataset
      patches.select_labels(tags="test").untag_labels("test")
  
      self.assertDictEqual(
          patches.count_values("ground_truth.tags"), {}
      )
      self.assertDictEqual(
          frames.count_values("ground_truth.detections.tags"), {}
      )
      self.assertDictEqual(
          dataset.count_values("frames.ground_truth.detections.tags"),
          {},
      )
  
      patches.select_fields().keep_fields()
  
      self.assertNotIn("ground_truth", patches.get_field_schema())
      self.assertNotIn("ground_truth", frames.get_field_schema())
      self.assertNotIn("ground_truth", dataset.get_frame_field_schema())
  
      patch_view = patches.first()
      with self.assertRaises(KeyError):
          patch_view["ground_truth"]
  
      frame_view = frames.first()
      with self.assertRaises(KeyError):
          frame_view["ground_truth"]
  
      frame = dataset.first().frames.first()
      with self.assertRaises(KeyError):
          frame["ground_truth"]
  
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 31 for calling the VideoTests obj's underlying member method code with example usage: obj.test_to_frame_patches() without return types