random.choice error due to np.linspace and np.logspace during Sphinx build

独自空忆成欢 提交于 2020-07-03 13:24:06

问题


I'm having a hard time with Sphinx where it won't import all the modules. There error it is encountering reads as follows:

  File “file path”, line 36, in Individual
    ml_params = {'C': random.choice(svr_C), 'gamma': random.choice(svr_gamma)}
  File "/usr/local/Cellar/sphinx-doc/3.1.1/libexec/lib/python3.8/random.py", line 290, in choice
    raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence

I set sphinx up per the instructions in the following post: Getting Started with Sphinx...

I have followed the recommended steps in the layout and it works well for the most part, except that it gets hung up on random.choice() from random.py. The python code runs without error and does not hang up on random.choice() from random.py.

In the python code, this is how random.choice is used:

svr_C = list(np.linspace(50, 300, 10))
svr_gamma = list(np.logspace(-4, -2, 3))

ml_params = {'C': random.choice(svr_C), 'gamma': random.choice(svr_gamma)}

I need to ignore numpy in the conf.py file, otherwise Sphinx will hang up on the numpy import. I don't know why Sphinx sees this 'np.linspace(50,300,10)' as an empty sequence. Seems like I need a way to convince Sphinx that random.choice() is in fact not empty.

My conf.py is set up as follows:

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join('..', '..')))

extensions = ['sphinx.ext.autodoc']
autodoc_mock_imports = ["matplotlib", "pandas", "scipy", "statsmodels", "numpy", "xlrd", "sklearn", "fpdf", "rpy2", "joblib", "pathos", "fire", "psutil"]

The file/directory structure:

.
├── Makefile
├── build
│   ├── doctrees
│   │   ├── src_lib.doctree
│   │   ├── environment.pickle
│   │   ├── index.doctree
│   │   └── modules.doctree
│   └── html
│       ├── _sources
│       │   ├── agora_lib.rst.txt
│       │   ├── index.rst.txt
│       │   └── modules.rst.txt
│       ├── _static
│       │   ├── numerous_css_files.css
│       │   ├── numerous_js_files.js
│       │   ├── 1.js
│       │   └── underscore.js
│       ├── src_lib.html
│       ├── genindex.html
│       ├── index.html
│       ├── modules.html
│       ├── objects.inv
│       ├── py-modindex.html
│       ├── search.html
│       └── searchindex.js
├── make.bat
└── source
    ├── _static
    ├── _templates
    ├── src_lib.rst
    ├── conf.py
    ├── index.rst
    └── modules.rst

Please see this question reposted Here: Sphinx autodoc (sphinx-apidoc) gets stuck on random.choice()

来源:https://stackoverflow.com/questions/62588629/random-choice-error-due-to-np-linspace-and-np-logspace-during-sphinx-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!