Commit 5faff89c authored by nd-02110114's avatar nd-02110114
Browse files

🐛 fix print bug

parent 510f1829
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import numpy as np
import multiprocessing
from typing import Any, Dict, List, Iterable, Sequence, Tuple, Union


from deepchem.utils import get_print_threshold
from deepchem.utils.typing import PymatgenStructure

logger = logging.getLogger(__name__)
@@ -96,7 +98,15 @@ class Featurizer(object):
    args_names = [arg for arg in args_spec.args if arg != 'self']
    args_info = ''
    for arg_name in args_names:
      args_info += arg_name + '=' + str(self.__dict__[arg_name]) + ', '
      value = self.__dict__[arg_name]
      # for str
      if isinstance(value, str):
        value = "'" + value + "'"
      # for list
      if isinstance(value, list):
        threshold = get_print_threshold()
        value = np.array2string(np.array(value), threshold=threshold)
      args_info += arg_name + '=' + str(value) + ', '
    return self.__class__.__name__ + '[' + args_info[:-2] + ']'

  def __str__(self) -> str:
@@ -126,6 +136,15 @@ class Featurizer(object):
    override_args_info = ''
    for arg_name, default in zip(args_names, args_default_values):
      arg_value = self.__dict__[arg_name]
      # validation
      # skip list
      if isinstance(arg_value, list):
        continue
      if isinstance(arg_value, str):
        # skip path string
        if "\\/." in arg_value or "/" in arg_value or '.' in arg_value:
          continue
      # main logic
      if default != arg_value:
        override_args_info += '_' + arg_name + '_' + str(arg_value)
    return self.__class__.__name__ + override_args_info
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ class MolGraphConvFeaturizer(MolecularFeaturizer):
    ----------
    add_self_edges: bool, default False
      Whether to add self-connected edges or not. If you want to use DGL,
      you sometimes need to add explict self-connected edges.
      you sometimes need to add explicit self-connected edges.
    """
    self.add_self_edges = add_self_edges

+3 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ ZINC_CHARSET = [
class OneHotFeaturizer(MolecularFeaturizer):
  """Encodes SMILES as a one-hot array.

  This featurizer encodes its SMILES string as a one-hot array.
  This featurizer encodes SMILES string as a one-hot array.

  Notes
  ----
@@ -34,7 +34,8 @@ class OneHotFeaturizer(MolecularFeaturizer):
    charset: List[str], optional (default ZINC_CHARSET)
      A list of strings, where each string is length 1 and unique.
    max_length: int, optional (default 100)
      length to pad the SMILES strings to.
      The max length for SMILES string. If the length of SMILES string is
      shorter than max_length, the SMILES is padded using space.
    """
    if len(charset) != len(set(charset)):
      raise ValueError("All values in charset must be unique.")