Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fixing Indentation for Docstring Generators #3650

Merged

Conversation

mdemoret-nv
Copy link
Contributor

When using the decorator @insert_into_docstring, the indentation level of the docstring is not taken into consideration. This causes documentation errors. For example, the generated docstring for RandomForestClassifier.predict() is:

Help on function predict in module cuml.ensemble.randomforestclassifier:

predict(self, X, predict_model='GPU', threshold=0.5, algo='auto', num_classes=None, convert_dtype=True, fil_sparse_format='auto') -> cuml.common.array.CumlArray
    RandomForestClassifier.predict(self, X, predict_model=u'GPU', threshold=0.5, algo=u'auto', num_classes=None, convert_dtype=True, fil_sparse_format=u'auto') -> CumlArray
    
        Predicts the labels for X.
    
        Parameters
        ----------
        X : array-like (device or host) shape = (n_samples, n_features)
    Dense matrix containing floats or doubles.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
        predict_model : String (default = 'GPU')
            'GPU' to predict using the GPU, 'CPU' otherwise. The 'GPU' can only
            be used if the model was trained on float32 data and `X` is float32
            or convert_dtype is set to True. Also the 'GPU' should only be
            used for binary classification problems.

The incorrect indentation for the X parameter is shown in the generated documentation:
image

This PR uses inspect.getdoc() to correctly normalize any docstrings indentation. This results in the following docstring:

Help on function predict in module cuml.ensemble.randomforestclassifier:

predict(self, X, predict_model='GPU', threshold=0.5, algo='auto', num_classes=None, convert_dtype=True, fil_sparse_format='auto') -> cuml.common.array.CumlArray
    RandomForestClassifier.predict(self, X, predict_model=u'GPU', threshold=0.5, algo=u'auto', num_classes=None, convert_dtype=True, fil_sparse_format=u'auto') -> CumlArray
    
    Predicts the labels for X.
    
    Parameters
    ----------
    X : array-like (device or host) shape = (n_samples, n_features)
        Dense matrix containing floats or doubles.
        Acceptable formats: CUDA array interface compliant objects like
        CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
        DataFrame/Series.
    predict_model : String (default = 'GPU')
        'GPU' to predict using the GPU, 'CPU' otherwise. The 'GPU' can only
        be used if the model was trained on float32 data and `X` is float32
        or convert_dtype is set to True. Also the 'GPU' should only be
        used for classification problems.

And the generated html docs look better as well:
image

@mdemoret-nv mdemoret-nv added 2 - In Progress Currenty a work in progress doc Documentation non-breaking Non-breaking change labels Mar 24, 2021
@mdemoret-nv mdemoret-nv added this to PR-WIP in v0.19 Release via automation Mar 24, 2021
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Mar 24, 2021
@mdemoret-nv
Copy link
Contributor Author

rerun tests

@mdemoret-nv
Copy link
Contributor Author

rerun tests

@mdemoret-nv mdemoret-nv marked this pull request as ready for review March 26, 2021 21:23
@mdemoret-nv mdemoret-nv requested a review from a team as a code owner March 26, 2021 21:23
@mdemoret-nv mdemoret-nv added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currenty a work in progress labels Mar 26, 2021
@codecov-io
Copy link

Codecov Report

Merging #3650 (4d31252) into branch-0.19 (fd9ec89) will increase coverage by 0.51%.
The diff coverage is 94.71%.

Impacted file tree graph

@@               Coverage Diff               @@
##           branch-0.19    #3650      +/-   ##
===============================================
+ Coverage        80.70%   81.22%   +0.51%     
===============================================
  Files              227      228       +1     
  Lines            17615    17870     +255     
===============================================
+ Hits             14217    14515     +298     
+ Misses            3398     3355      -43     
Flag Coverage Δ
dask 45.01% <55.76%> (+0.01%) ⬆️
non-dask 73.30% <69.71%> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
python/cuml/cluster/kmeans.pyx 91.95% <ø> (ø)
python/cuml/fil/fil.pyx 92.85% <ø> (+1.02%) ⬆️
python/cuml/neighbors/__init__.py 100.00% <ø> (ø)
python/cuml/preprocessing/encoders.py 95.10% <ø> (+0.02%) ⬆️
python/cuml/common/memory_utils.py 79.26% <50.00%> (+0.15%) ⬆️
python/cuml/neighbors/ann.pyx 90.80% <80.00%> (+29.17%) ⬆️
python/cuml/solvers/qn.pyx 97.20% <85.71%> (-0.43%) ⬇️
python/cuml/linear_model/logistic_regression.pyx 89.16% <88.88%> (+0.20%) ⬆️
python/cuml/dask/ensemble/base.py 83.90% <97.14%> (+2.78%) ⬆️
python/cuml/common/doc_utils.py 100.00% <100.00%> (ø)
... and 59 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0883026...4d31252. Read the comment docs.

v0.19 Release automation moved this from PR-WIP to PR-Reviewer approved Mar 29, 2021
@dantegd
Copy link
Member

dantegd commented Mar 30, 2021

@gpucibot merge

@rapids-bot rapids-bot bot merged commit feaddae into rapidsai:branch-0.19 Mar 30, 2021
v0.19 Release automation moved this from PR-Reviewer approved to Done Mar 30, 2021
@mdemoret-nv mdemoret-nv deleted the 019-fix-docstring-gen-indent branch March 30, 2021 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team Cython / Python Cython or Python issue doc Documentation non-breaking Non-breaking change
Projects
No open projects
v0.19 Release
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants