code: def testDynamicWindowSize(self):
      components = np.arange(100).astype(np.int64)
  
      # Key fn: even/odd
      # Reduce fn: batches of 5
      # Window size fn: even=5, odd=10
  
      def window_size_func(key):
          window_sizes = constant_op.constant(
              [5, 10], dtype=dtypes.int64
          )
          return window_sizes[key]
  
      dataset = dataset_ops.Dataset.from_tensor_slices(components)
      dataset = dataset.group_by_window(
          key_func=lambda x: x % 2,
          reduce_func=lambda _, xs: xs.batch(20),
          window_size=None,
          window_size_func=window_size_func,
      )
  
      get_next = self.getNext(dataset)
      with self.assertRaises(errors.OutOfRangeError):
          batches = 0
          while True:
              result = self.evaluate(get_next())
              is_even = all(x % 2 == 0 for x in result)
              is_odd = all(x % 2 == 1 for x in result)
              self.assertTrue(is_even or is_odd)
              expected_batch_size = 5 if is_even else 10
              self.assertEqual(expected_batch_size, result.shape[0])
              batches += 1
  
      self.assertEqual(batches, 15)
  
imports: from absl.testing import parameterized
  import numpy
  from tensorflow.core.lib.core import error_codes_pb2
  from tensorflow.python.data.kernel_tests import checkpoint_test_base
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import string_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 5 for calling the GroupByWindowTest obj's underlying member method code with example usage: obj.testDynamicWindowSize() and returns: window_sizes