code: def _assert_equal_ngram(actual_ngram, expected_ngram):
      np.testing.assert_equal(
          sorted(actual_ngram.keys()), sorted(expected_ngram.keys())
      )
      for timestep in actual_ngram:
          actual_dict = actual_ngram[timestep]._asdict()
          expected_dict = expected_ngram[timestep]._asdict()
          np.testing.assert_equal(
              sorted(list(actual_dict.keys())),
              sorted(list(expected_dict.keys())),
          )
          for field_name in actual_dict:
              actual_field = actual_dict[field_name]
              expected_field = expected_dict[field_name]
  
              if isinstance(expected_field, Decimal) or isinstance(
                  expected_field, str
              ):
                  # Tensorflow returns all strings as bytes in python3. So we will need to decode it
                  actual_field = actual_field.decode()
              elif (
                  isinstance(expected_field, np.ndarray)
                  and expected_field.dtype.type == np.unicode_
              ):
                  actual_field = np.array(
                      [item.decode() for item in actual_field]
                  )
  
              if isinstance(expected_field, Decimal):
                  np.testing.assert_equal(
                      expected_field,
                      Decimal(actual_field),
                      "{0} field is different".format(field_name),
                  )
              else:
                  np.testing.assert_equal(
                      expected_field,
                      actual_field,
                      "{0} field is different".format(field_name),
                  )
  
imports: from decimal import Decimal
  import numpy
  import pytest
  import tensorflow.compat.v1
  from unittest import mock
  from petastorm import make_reader
  from petastorm.ngram import NGram
  from petastorm.tests.conftest import SyntheticDataset, maybe_cached_dataset
  from petastorm.tests.test_common import create_test_dataset, TestSchema
  from petastorm.tests.test_tf_utils import create_tf_graph
  from petastorm.tf_utils import tf_tensors
label_desc: Use image node_id 4 for calling a global function with example usage: _assert_equal_ngram(actual_ngram, expected_ngram) without return types