Commit 1b4cba66 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Adding in test for complete_shuffle

parent 10d484e3
Loading
Loading
Loading
Loading
+29 −30
Original line number Diff line number Diff line
@@ -12,36 +12,35 @@ import unittest
import deepchem as dc
import numpy as np

#def test_shuffle():
#  """Test that datasets can be merged."""
#  current_dir = os.path.dirname(os.path.realpath(__file__))

#  dataset_file = os.path.join(
#      current_dir, "../../models/tests/example.csv")

#  featurizer = dc.feat.CircularFingerprint(size=1024)
#  tasks = ["log-solubility"]
#  loader = dc.data.CSVLoader(
#      tasks=tasks, smiles_field="smiles", featurizer=featurizer)
#  dataset = loader.featurize(dataset_file, shard_size=2)

#  X_orig, y_orig, w_orig, orig_ids = (dataset.X, dataset.y, dataset.w,
#                                      dataset.ids)
#  orig_len = len(dataset)

#  dataset.shuffle(iterations=5)
#  X_new, y_new, w_new, new_ids = (dataset.X, dataset.y, dataset.w,
#                                  dataset.ids)
#
#  assert len(dataset) == orig_len
#  # The shuffling should have switched up the ordering
#  assert not np.array_equal(orig_ids, new_ids)
#  # But all the same entries should still be present
#  assert sorted(orig_ids) == sorted(new_ids)
#  # All the data should have same shape
#  assert X_orig.shape == X_new.shape
#  assert y_orig.shape == y_new.shape
#  assert w_orig.shape == w_new.shape

def test_complete_shuffle():
  """Test that complete shuffle."""
  current_dir = os.path.dirname(os.path.realpath(__file__))

  dataset_file = os.path.join(current_dir, "../../models/tests/example.csv")

  featurizer = dc.feat.CircularFingerprint(size=1024)
  tasks = ["log-solubility"]
  loader = dc.data.CSVLoader(
      tasks=tasks, smiles_field="smiles", featurizer=featurizer)
  dataset = loader.featurize(dataset_file, shard_size=2)

  X_orig, y_orig, w_orig, orig_ids = (dataset.X, dataset.y, dataset.w,
                                      dataset.ids)
  orig_len = len(dataset)

  dataset = dataset.complete_shuffle()
  X_new, y_new, w_new, new_ids = (dataset.X, dataset.y, dataset.w, dataset.ids)

  assert len(dataset) == orig_len
  # The shuffling should have switched up the ordering
  assert not np.array_equal(orig_ids, new_ids)
  # But all the same entries should still be present
  assert sorted(orig_ids) == sorted(new_ids)
  # All the data should have same shape
  assert X_orig.shape == X_new.shape
  assert y_orig.shape == y_new.shape
  assert w_orig.shape == w_new.shape


def test_sparse_shuffle():