Esempio n. 1
0
  def testPandasFeedFnBatchTwoWithOneEpoch(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 37)
    array2 = np.arange(64, 69)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 101))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, batch_size=2, num_epochs=1)

    expected = {
        "index_placeholder": [96, 97],
        "a_placeholder": [32, 33],
        "b_placeholder": [64, 65]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))

    expected = {
        "index_placeholder": [98, 99],
        "a_placeholder": [34, 35],
        "b_placeholder": [66, 67]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))

    expected = {
        "index_placeholder": [100],
        "a_placeholder": [36],
        "b_placeholder": [68]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
  def testPandasFeedFnBatchTwoWithOneEpoch(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 37)
    array2 = np.arange(64, 69)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 101))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, batch_size=2, num_epochs=1)

    expected = {
        "index_placeholder": [96, 97],
        "a_placeholder": [32, 33],
        "b_placeholder": [64, 65]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))

    expected = {
        "index_placeholder": [98, 99],
        "a_placeholder": [34, 35],
        "b_placeholder": [66, 67]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))

    expected = {
        "index_placeholder": [100],
        "a_placeholder": [36],
        "b_placeholder": [68]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
Esempio n. 3
0
  def testPandasFeedFnBatchOneHundredWithSmallDataArrayAndMultipleEpochs(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 34)
    array2 = np.arange(64, 66)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 98))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, batch_size=100, num_epochs=2)

    expected = {
        "index_placeholder": [96, 97, 96, 97],
        "a_placeholder": [32, 33, 32, 33],
        "b_placeholder": [64, 65, 64, 65]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
Esempio n. 4
0
  def testPandasFeedFnBatchOneHundred(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 64)
    array2 = np.arange(64, 96)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 128))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, 100)

    expected = {
        "index_placeholder": list(range(96, 128)) * 3 + list(range(96, 100)),
        "a_placeholder": list(range(32, 64)) * 3 + list(range(32, 36)),
        "b_placeholder": list(range(64, 96)) * 3 + list(range(64, 68))
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
  def testPandasFeedFnBatchOneHundredWithSmallDataArrayAndMultipleEpochs(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 34)
    array2 = np.arange(64, 66)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 98))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, batch_size=100, num_epochs=2)

    expected = {
        "index_placeholder": [96, 97, 96, 97],
        "a_placeholder": [32, 33, 32, 33],
        "b_placeholder": [64, 65, 64, 65]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
  def testPandasFeedFnBatchOneHundred(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 64)
    array2 = np.arange(64, 96)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 128))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, 100)

    expected = {
        "index_placeholder": list(range(96, 128)) * 3 + list(range(96, 100)),
        "a_placeholder": list(range(32, 64)) * 3 + list(range(32, 36)),
        "b_placeholder": list(range(64, 96)) * 3 + list(range(64, 68))
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
Esempio n. 7
0
  def testPandasFeedFnBatchOne(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 64)
    array2 = np.arange(64, 96)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 128))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, 1)

    # cycle around a couple times
    for x in range(0, 100):
      i = x % 32
      expected = {
          "index_placeholder": [i + 96],
          "a_placeholder": [32 + i],
          "b_placeholder": [64 + i]
      }
      actual = aff()
      self.assertEqual(expected, vals_to_list(actual))
  def testPandasFeedFnBatchOne(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 64)
    array2 = np.arange(64, 96)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 128))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, 1)

    # cycle around a couple times
    for x in range(0, 100):
      i = x % 32
      expected = {
          "index_placeholder": [i + 96],
          "a_placeholder": [32 + i],
          "b_placeholder": [64 + i]
      }
      actual = aff()
      self.assertEqual(expected, vals_to_list(actual))
Esempio n. 9
0
  def testPandasFeedFnBatchFive(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 64)
    array2 = np.arange(64, 96)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 128))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, 5)

    # cycle around a couple times
    for _ in range(0, 101, 2):
      aff()

    expected = {
        "index_placeholder": [127, 96, 97, 98, 99],
        "a_placeholder": [63, 32, 33, 34, 35],
        "b_placeholder": [95, 64, 65, 66, 67]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
  def testPandasFeedFnBatchFive(self):
    if not HAS_PANDAS:
      return
    array1 = np.arange(32, 64)
    array2 = np.arange(64, 96)
    df = pd.DataFrame({"a": array1, "b": array2}, index=np.arange(96, 128))
    placeholders = ["index_placeholder", "a_placeholder", "b_placeholder"]
    aff = ff._PandasFeedFn(placeholders, df, 5)

    # cycle around a couple times
    for _ in range(0, 101, 2):
      aff()

    expected = {
        "index_placeholder": [127, 96, 97, 98, 99],
        "a_placeholder": [63, 32, 33, 34, 35],
        "b_placeholder": [95, 64, 65, 66, 67]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))