sphinx 警告:自动摘要:找不到 class 方法的存根文件。检查您的 autosummary_generate 设置
sphinx warning: autosummary: stub file not found for the methods of the class. check your autosummary_generate settings
我有一个开源包,其中有很多 classes 在不同的子模块上。所有 classes 都有方法 fit
和 transform
,并从 sklearn 继承 fit_transform
。所有 classes 都有 numpydoc 之后的文档字符串,副标题为参数、属性、注释、另见和方法,我在其中列出了 fit
、transform
和 fit_transform
。我复制了一个 class:
的例子
class DropFeatures(BaseEstimator, TransformerMixin):
"""
Some description.
Parameters
----------
features_to_drop : str or list, default=None
Variable(s) to be dropped from the dataframe
Methods
-------
fit
transform
fit_transform
"""
def __init__(self, features_to_drop: List[Union[str, int]]):
some init parameters
def fit(self, X: pd.DataFrame, y: pd.Series = None):
"""
This transformer does not learn any parameter.
Verifies that the input X is a pandas dataframe, and that the variables to
drop exist in the training dataframe.
Parameters
----------
X : pandas dataframe of shape = [n_samples, n_features]
The input dataframe
y : pandas Series, default = None
y is not needed for this transformer. You can pass y or None.
Returns
-------
self
"""
some functionality
return self
def transform(self, X: pd.DataFrame):
"""
Drop the variable or list of variables from the dataframe.
Parameters
----------
X : pandas dataframe
The input dataframe from which features will be dropped
Returns
-------
X_transformed : pandas dataframe,
shape = [n_samples, n_features - len(features_to_drop)]
The transformed dataframe with the remaining subset of variables.
"""
some more functionality
return X
在 Sphinx 的 conf.py 中,我包括:
extensions = [
"sphinx.ext.autodoc", # Core Sphinx library for auto html doc generation from docstrings
"sphinx.ext.autosummary", # Create neat summary tables for modules/classes/methods etc
"sphinx.ext.intersphinx", # Link to other project's documentation (see mapping below)
"sphinx_autodoc_typehints", # Automatically document param types (less noise in class signature)
"numpydoc",
"sphinx.ext.linkcode",
]
numpydoc_show_class_members = False
# generate autosummary even if no references
autosummary_generate = True
autosummary_imported_members = True
当我使用 sphinx-build -b html docs build
构建文档时,文档构建得非常好,但是每个 class 我收到 3 个警告,每个方法一个,上面写着:
warning: autosummary: stub file not found for the methods of the class. check your autosummary_generate settings
我已经用尽了所有的搜索资源,我准备放弃了。有人知道如何防止该警告或如何使 sphinx 不将其打印到控制台吗?
我附上错误的副本,如果需要,我可以向回购的 PR 提供 link
好的,3 天后,我搞定了。秘诀是在“方法”标题后为文档字符串中的方法添加简短描述,而不是像我那样将它们留空。
所以:
class DropFeatures(BaseEstimator, TransformerMixin):
Some description.
Parameters
----------
features_to_drop : str or list, default=None
Variable(s) to be dropped from the dataframe
Methods
-------
fit:
some description
transform:
some description
fit_transform:
some description
在我的例子中,doc
文件夹中 setup.py
的以下添加删除了警告:
numpydoc_show_class_members = False
添加方法将方法限制在固定列表中,这不是我想要的行为。
我有一个开源包,其中有很多 classes 在不同的子模块上。所有 classes 都有方法 fit
和 transform
,并从 sklearn 继承 fit_transform
。所有 classes 都有 numpydoc 之后的文档字符串,副标题为参数、属性、注释、另见和方法,我在其中列出了 fit
、transform
和 fit_transform
。我复制了一个 class:
class DropFeatures(BaseEstimator, TransformerMixin):
"""
Some description.
Parameters
----------
features_to_drop : str or list, default=None
Variable(s) to be dropped from the dataframe
Methods
-------
fit
transform
fit_transform
"""
def __init__(self, features_to_drop: List[Union[str, int]]):
some init parameters
def fit(self, X: pd.DataFrame, y: pd.Series = None):
"""
This transformer does not learn any parameter.
Verifies that the input X is a pandas dataframe, and that the variables to
drop exist in the training dataframe.
Parameters
----------
X : pandas dataframe of shape = [n_samples, n_features]
The input dataframe
y : pandas Series, default = None
y is not needed for this transformer. You can pass y or None.
Returns
-------
self
"""
some functionality
return self
def transform(self, X: pd.DataFrame):
"""
Drop the variable or list of variables from the dataframe.
Parameters
----------
X : pandas dataframe
The input dataframe from which features will be dropped
Returns
-------
X_transformed : pandas dataframe,
shape = [n_samples, n_features - len(features_to_drop)]
The transformed dataframe with the remaining subset of variables.
"""
some more functionality
return X
在 Sphinx 的 conf.py 中,我包括:
extensions = [
"sphinx.ext.autodoc", # Core Sphinx library for auto html doc generation from docstrings
"sphinx.ext.autosummary", # Create neat summary tables for modules/classes/methods etc
"sphinx.ext.intersphinx", # Link to other project's documentation (see mapping below)
"sphinx_autodoc_typehints", # Automatically document param types (less noise in class signature)
"numpydoc",
"sphinx.ext.linkcode",
]
numpydoc_show_class_members = False
# generate autosummary even if no references
autosummary_generate = True
autosummary_imported_members = True
当我使用 sphinx-build -b html docs build
构建文档时,文档构建得非常好,但是每个 class 我收到 3 个警告,每个方法一个,上面写着:
warning: autosummary: stub file not found for the methods of the class. check your autosummary_generate settings
我已经用尽了所有的搜索资源,我准备放弃了。有人知道如何防止该警告或如何使 sphinx 不将其打印到控制台吗?
我附上错误的副本,如果需要,我可以向回购的 PR 提供 link
好的,3 天后,我搞定了。秘诀是在“方法”标题后为文档字符串中的方法添加简短描述,而不是像我那样将它们留空。
所以:
class DropFeatures(BaseEstimator, TransformerMixin):
Some description.
Parameters
----------
features_to_drop : str or list, default=None
Variable(s) to be dropped from the dataframe
Methods
-------
fit:
some description
transform:
some description
fit_transform:
some description
在我的例子中,doc
文件夹中 setup.py
的以下添加删除了警告:
numpydoc_show_class_members = False
添加方法将方法限制在固定列表中,这不是我想要的行为。