Esempio n. 1
0
 def testIsFloats(self):
     self.assertTrue(cell_types.isFloats(4.1))
     self.assertFalse(cell_types.isFloats(4.0))
     self.assertTrue(cell_types.isFloats([4.1, 3.0]))
     self.assertTrue(cell_types.isFloats([4.1, np.nan, 3.0]))
     self.assertFalse(cell_types.isFloats(range(4)))
     self.assertFalse(cell_types.isFloats([3, 4, None]))
     self.assertFalse(cell_types.isFloats([3, 4, None, "a"]))
     self.assertFalse(cell_types.isFloats([3, 4, np.nan, "a"]))
     self.assertTrue(cell_types.isFloats([3, 4, np.nan, 0]))
Esempio n. 2
0
def compareIterables(iter1, iter2):
  """
  Compares two iterables. Considered equal if different lengths
  but one iterable is filled with NaN or None.
  :param Iterable iter1: iterable possibly with None values
  :param Iterable iter2: iterable possibly with None values
  :return: True if equivalent; otherwise false
  """
  def makeList(val):
    result = cell_types.makeIterable(val)
    pruned_result = pruneNulls(result)
    if isinstance(pruned_result, list):
      return pruned_result
    else:
      return [v for v in pruned_result]

  # Make sure the inputs are iterables
  iter1 = makeList(iter1)
  iter2 = makeList(iter2)
  if len(iter1) != len(iter2):
    return False
  pairs = zip(iter1, iter2)
  try:
    if cell_types.isFloats(iter1):
      return all([cell_types.isEquivalentFloats(i1, i2) for i1, i2 in pairs])
  except TypeError as err:
    return False
  return all([i1 == i2 for i1, i2 in pairs])