code: def _test_last_batch_handle(data, labels=None, is_image=False):
      # Test the three parameters 'pad', 'discard', 'roll_over'
      last_batch_handle_list = ["pad", "discard", "roll_over"]
      if labels is not None and not is_image and len(labels) != 0:
          labelcount_list = [(124, 100), (100, 96), (100, 96)]
      if is_image:
          batch_count_list = [40, 39, 39]
      else:
          batch_count_list = [8, 7, 7]
  
      for idx in range(len(last_batch_handle_list)):
          dataiter = mx.io.NDArrayIter(
              data,
              labels,
              128,
              False,
              last_batch_handle=last_batch_handle_list[idx],
          )
          batch_count = 0
          if labels is not None and len(labels) != 0 and not is_image:
              labelcount = [0 for i in range(10)]
          for batch in dataiter:
              if len(data) == 2:
                  assert len(batch.data) == 2
              if labels is not None and len(labels) != 0:
                  if not is_image:
                      label = batch.label[0].asnumpy().flatten()
                      # check data if it matches corresponding labels
                      assert (
                          batch.data[0].asnumpy()[:, 0, 0] == label
                      ).all()
                      for i in range(label.shape[0]):
                          labelcount[int(label[i])] += 1
              else:
                  assert not batch.label, "label is not empty list"
              # keep the last batch of 'pad' to be used later
              # to test first batch of roll_over in second iteration
              batch_count += 1
              if (
                  last_batch_handle_list[idx] == "pad"
                  and batch_count == batch_count_list[0]
              ):
                  cache = batch.data[0].asnumpy()
          # check if batchifying functionality work properly
          if labels is not None and len(labels) != 0 and not is_image:
              assert (
                  labelcount[0] == labelcount_list[idx][0]
              ), last_batch_handle_list[idx]
              assert (
                  labelcount[8] == labelcount_list[idx][1]
              ), last_batch_handle_list[idx]
          assert batch_count == batch_count_list[idx]
      # roll_over option
      dataiter.reset()
      assert np.array_equal(dataiter.next().data[0].asnumpy(), cache)
  
imports: import mxnet
  import mxnet.ndarray
  from mxnet.test_utils import *
  from mxnet.base import MXNetError
  import numpy
  import os
  import gzip
  import pickle
  import time
  import sys
  from common import assertRaises
  import pytest
  from itertools import zip_longest
label_desc: Use image node_id 7 for calling a global function with example usage: _test_last_batch_handle(data, labels, is_image) without return types