Commit 45009705 authored by alat-rights's avatar alat-rights
Browse files

Minor formatting changes

parent 204bab59
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -49,9 +49,11 @@ class OneHotFeaturizer(MolecularFeaturizer):
                log_every_n: int = 1000) -> np.ndarray:
    datapoints = list(datapoints)
    if (len(datapoints) < 1):
      print("No datapoints are present in the parameter Iterable, so we return an empty array.")
      print(
          "No datapoints are present in the parameter Iterable, so we return an empty array."
      )
      return np.array([])
    ic(type(datapoints[0]))

    # Featurize Mol data
    if (type(datapoints[0]) == RDKitMol):  # Mol
      return MolecularFeaturizer.featurize(self, datapoints, log_every_n)
@@ -59,7 +61,9 @@ class OneHotFeaturizer(MolecularFeaturizer):
    elif (type(datapoints[0]) == str):  # String
      return Featurizer.featurize(self, datapoints, log_every_n)
    else:
      print("One hot featurizer only supports strings and mols at this time, so returning {}")
      print(
          "One hot featurizer only supports strings and mols at this time, so returning {}"
      )
      return np.array([])

  def _featurize(self, datapoint: Any):
@@ -69,7 +73,9 @@ class OneHotFeaturizer(MolecularFeaturizer):
    elif (type(datapoint) == RDKitMol):
      return self._featurizeMol(datapoint)
    else:
      print("One hot featurizer only supports strings and mols at this time, so returning {}")
      print(
          "One hot featurizer only supports strings and mols at this time, so returning {}"
      )
      return np.array([])

  def _featurizeString(self, string: str) -> np.ndarray:
+2 −8
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ import numpy as np

from deepchem.feat import OneHotFeaturizer
from deepchem.feat.molecule_featurizers.one_hot_featurizer import ZINC_CHARSET
from icecream import ic


class TestOneHotFeaturizert(unittest.TestCase):
  """
@@ -20,9 +20,6 @@ class TestOneHotFeaturizert(unittest.TestCase):
    length = len(charset) + 1
    featurizer = OneHotFeaturizer(charset)
    feature = featurizer([string])  # Implicit call to featurize()
    ic(len(feature))
    ic(len(feature[0]))
    ic(len(feature[0][0]))
    assert feature.shape == (1, 100, length)
    # untransform
    undo_string = featurizer.untransform(feature[0])
@@ -47,14 +44,11 @@ class TestOneHotFeaturizert(unittest.TestCase):
    """
    Test one hot encoding with max_length.
    """
    string = "abcdefghijklmnopqrstuvwxyz"
    string = "abcdefghijklmnopqrstuvwxyzvewqmc"
    charset = "abcdefghijklmnopqrstuvwxyz"
    length = len(charset) + 1
    featurizer = OneHotFeaturizer(charset, max_length=120)
    feature = featurizer([string])
    ic(len(feature))
    ic(len(feature[0]))
    ic(len(feature[0][0]))
    assert feature.shape == (1, 120, length)
    # untranform
    undo_string = featurizer.untransform(feature[0])