code: def test_field_add_delete_in_dataset(self):
      dataset = fo.Dataset()
      id1 = dataset.add_sample(fo.Sample("1.jpg"))
      id2 = dataset.add_sample(fo.Sample("2.jpg"))
      sample1 = dataset[id1]
      sample2 = dataset[id2]
  
      # redeclaring an existing field is allowed
      dataset.add_sample_field("filepath", fo.StringField)
  
      # but the types must match
      with self.assertRaises(ValueError):
          dataset.add_sample_field("filepath", fo.IntField)
  
      # delete default field
      with self.assertRaises(ValueError):
          dataset.delete_sample_field("filepath")
  
      field_name = "field1"
      ftype = fo.StringField
      wrong_ftype = fo.IntField
      field_test_value = "test_field_value"
  
      # access non-existent field
      with self.assertRaises(KeyError):
          dataset.get_field_schema()[field_name]
  
      for sample in [sample1, sample2, dataset[id1], dataset[id2]]:
          with self.assertRaises(AttributeError):
              sample.get_field(field_name)
  
          with self.assertRaises(KeyError):
              sample[field_name]
  
          with self.assertRaises(AttributeError):
              getattr(sample, field_name)
  
          with self.assertRaises(KeyError):
              sample.to_dict()[field_name]
  
      # add field (new)
      dataset.add_sample_field(field_name, ftype)
      setattr(sample1, field_name, field_test_value)
  
      # check field exists and is of correct type
      field = dataset.get_field_schema()[field_name]
      self.assertIsInstance(field, ftype)
      for sample in [sample1, dataset[id1]]:
          # check field exists on sample and is set correctly
          self.assertEqual(
              sample.get_field(field_name), field_test_value
          )
          self.assertEqual(sample[field_name], field_test_value)
          self.assertEqual(
              getattr(sample, field_name), field_test_value
          )
          self.assertEqual(
              sample.to_dict()[field_name], field_test_value
          )
  
      for sample in [sample2, dataset[id2]]:
          self.assertIsInstance(field, ftype)
          # check field exists on sample and is None
          self.assertIsNone(sample.get_field(field_name))
          self.assertIsNone(sample[field_name])
          self.assertIsNone(getattr(sample, field_name))
          self.assertIsNone(sample.to_dict()[field_name])
  
      # redeclaring an existing field is allowed
      dataset.add_sample_field(field_name, ftype)
  
      # but the types must match
      with self.assertRaises(ValueError):
          dataset.add_sample_field(field_name, wrong_ftype)
  
      # delete field
      dataset.delete_sample_field(field_name)
  
      # access non-existent field
      with self.assertRaises(KeyError):
          dataset.get_field_schema()[field_name]
  
      for sample in [sample1, sample2, dataset[id1], dataset[id2]]:
          with self.assertRaises(AttributeError):
              sample.get_field(field_name)
  
          with self.assertRaises(KeyError):
              sample[field_name]
  
          with self.assertRaises(AttributeError):
              getattr(sample, field_name)
  
          with self.assertRaises(KeyError):
              sample.to_dict()[field_name]
  
      # add deleted field with new type
      ftype = fo.IntField
      field_test_value = 51
      dataset.add_sample_field(field_name, ftype)
      setattr(sample1, field_name, field_test_value)
  
      # check field exists and is of correct type
      field = dataset.get_field_schema()[field_name]
      self.assertIsInstance(field, ftype)
      for sample in [sample1, dataset[id1]]:
          self.assertIsInstance(field, ftype)
          # check field exists on sample and is set correctly
          self.assertEqual(
              sample.get_field(field_name), field_test_value
          )
          self.assertEqual(sample[field_name], field_test_value)
          self.assertEqual(
              getattr(sample, field_name), field_test_value
          )
          self.assertEqual(
              sample.to_dict()[field_name], field_test_value
          )
  
      for sample in [sample2, dataset[id2]]:
          self.assertIsInstance(field, ftype)
          # check field exists on sample and is None
          self.assertIsNone(sample.get_field(field_name))
          self.assertIsNone(sample[field_name])
          self.assertIsNone(getattr(sample, field_name))
          self.assertIsNone(sample.to_dict()[field_name])
  
imports: import os
  import tempfile
  import unittest
  from bson import Binary, ObjectId
  import numpy
  from PIL import ExifTags, Image
  import fiftyone
  from fiftyone import ViewField
  import fiftyone.core.odm
  import fiftyone.core.sample
  from decorators import drop_datasets
label_desc: Use image node_id 1 for calling the SampleFieldTests obj's underlying member method code with example usage: obj.test_field_add_delete_in_dataset() without return types