You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用DeepChem 2.0.0遇TypeError:需字符串/缓冲区而非NoneType

Solution for TypeError: coercing to Unicode in DeepChem 2.0.0 (Python 2.7 Conda Env)

This error pops up because one of the variables you’re trying to stitch into the file path is None—Python 2.7 doesn’t let you add None to a string, which triggers the "coercing to Unicode" type mismatch. Let’s walk through how to fix this:

Root Cause

Looking at the error line:

save_dir = os.path.join(data_dir, "bace_c/" + featurizer + "/" + str(split))

The issue is almost certainly that featurizer is None (since split has a default value of 'random', and a missing data_dir would throw a different error). Even though load_bace_classification defines a default featurizer='ECFP', your call to run_benchmark (in test_run_benchmark_models.py line 30) is probably passing None for this parameter.

Step-by-Step Fixes

1. Correct the run_benchmark Call

First, check your code in test_run_benchmark_models.py line 30. Make sure you’re passing a valid string for featurizer, not None. For example:

# Example of a valid call
run_benchmark(
    # Your other parameters here...
    featurizer='ECFP',  # Use a valid featurizer like 'ECFP' or 'GraphConv'
    seed=123
)

2. Make the load_bace_classification Function More Robust

To prevent this issue from recurring, add parameter validation and use safer path concatenation:

def load_bace_classification(featurizer='ECFP', split='random', reload=True):
  """Load bace datasets."""
  # Add checks to catch invalid parameters early
  if not isinstance(featurizer, basestring):
      raise ValueError(f"featurizer must be a string (e.g., 'ECFP'), got {type(featurizer)} instead")
  if not isinstance(split, basestring):
      raise ValueError(f"split must be a string (e.g., 'random'), got {type(split)} instead")
  
  # Featurize bace dataset
  print("About to featurize bace dataset.")
  data_dir = deepchem.utils.get_data_dir()
  if reload:
    # Use os.path.join with separate arguments instead of string concatenation
    save_dir = os.path.join(data_dir, "bace_c", featurizer, str(split))
    dataset_file = os.path.join(data_dir, "bace.csv")
    if not os.path.exists(dataset_file):
      deepchem.utils.download_url('http://deepchem.io.s3-website-us-west-1.amazonaws.com/datasets/bace.csv' )

Using os.path.join with multiple arguments avoids string addition pitfalls, and the validation checks will give you a clearer error message if invalid parameters are passed.

3. Verify get_data_dir() Returns a Valid Path (Optional)

If the above fixes don’t work, double-check that deepchem.utils.get_data_dir() returns a valid string path. Add a print statement to confirm:

data_dir = deepchem.utils.get_data_dir()
print(f"Data directory: {data_dir}, type: {type(data_dir)}")

If it returns None, you may need to set the DEEPCHEM_DATA_DIR environment variable or check your DeepChem configuration.


内容的提问来源于stack exchange,提问作者Ha Young Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:30:31