code: def test_dataframe_iterator(all_test_images, tmpdir):
      num_classes = 2
  
      # save the images in the tmpdir
      count = 0
      filenames = []
      filepaths = []
      filenames_without = []
      for test_images in all_test_images:
          for im in test_images:
              filename = "image-{}.png".format(count)
              filename_without = "image-{}".format(count)
              filenames.append(filename)
              filepaths.append(os.path.join(str(tmpdir), filename))
              filenames_without.append(filename_without)
              im.save(str(tmpdir / filename))
              count += 1
  
      df = pd.DataFrame(
          {
              "filename": filenames,
              "class": [str(random.randint(0, 1)) for _ in filenames],
              "filepaths": filepaths,
          }
      )
  
      # create iterator
      iterator = dataframe_iterator.DataFrameIterator(df, str(tmpdir))
      batch = next(iterator)
      assert len(batch) == 2
      assert isinstance(batch[0], np.ndarray)
      assert isinstance(batch[1], np.ndarray)
      generator = image_data_generator.ImageDataGenerator()
      df_iterator = generator.flow_from_dataframe(df, x_col="filepaths")
      df_iterator_dir = generator.flow_from_dataframe(df, str(tmpdir))
      df_sparse_iterator = generator.flow_from_dataframe(
          df, str(tmpdir), class_mode="sparse"
      )
      assert not np.isnan(df_sparse_iterator.classes).any()
      # check number of classes and images
      assert len(df_iterator.class_indices) == num_classes
      assert len(df_iterator.classes) == count
      assert set(df_iterator.filenames) == set(filepaths)
      assert len(df_iterator_dir.class_indices) == num_classes
      assert len(df_iterator_dir.classes) == count
      assert set(df_iterator_dir.filenames) == set(filenames)
      # test without shuffle
      _, batch_y = next(
          generator.flow_from_dataframe(
              df, str(tmpdir), shuffle=False, class_mode="sparse"
          )
      )
      assert (
          batch_y == df["class"].astype("float")[: len(batch_y)]
      ).all()
      # Test invalid use cases
      with pytest.raises(ValueError):
          generator.flow_from_dataframe(
              df, str(tmpdir), color_mode="cmyk"
          )
      with pytest.raises(ValueError):
          generator.flow_from_dataframe(
              df, str(tmpdir), class_mode="output"
          )
      with pytest.warns(DeprecationWarning):
          generator.flow_from_dataframe(df, str(tmpdir), has_ext=True)
      with pytest.warns(DeprecationWarning):
          generator.flow_from_dataframe(df, str(tmpdir), has_ext=False)
  
      def preprocessing_function(x):
          """This will fail if not provided by a Numpy array.
          Note: This is made to enforce backward compatibility.
          """
  
          assert x.shape == (26, 26, 3)
          assert type(x) is np.ndarray
  
          return np.zeros_like(x)
  
      # Test usage as Sequence
      generator = image_data_generator.ImageDataGenerator(
          preprocessing_function=preprocessing_function
      )
      dir_seq = generator.flow_from_dataframe(
          df,
          str(tmpdir),
          target_size=(26, 26),
          color_mode="rgb",
          batch_size=3,
          class_mode="categorical",
      )
      assert len(dir_seq) == np.ceil(count / 3)
      x1, y1 = dir_seq[1]
      assert x1.shape == (3, 26, 26, 3)
      assert y1.shape == (3, num_classes)
      x1, y1 = dir_seq[5]
      assert (x1 == 0).all()
  
      with pytest.raises(ValueError):
          x1, y1 = dir_seq[9]
  
imports: import os
  import random
  import shutil
  import numpy
  import pandas
  import pytest
  from PIL import Image
  from keras_preprocessing.image import dataframe_iterator, image_data_generator
label_desc: Use image node_id 2 for calling a global function with example usage: test_dataframe_iterator(all_test_images, tmpdir) and returns: np