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

DOC: Add "Examples" to docstrings #7168

Open
WarrenWeckesser opened this issue Mar 14, 2017 · 65 comments · Fixed by #7208, #8440 or #8447
Open

DOC: Add "Examples" to docstrings #7168

WarrenWeckesser opened this issue Mar 14, 2017 · 65 comments · Fixed by #7208, #8440 or #8447
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution task A straightforward change, verification or fix.

Comments

@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Mar 14, 2017

Many of the functions in scipy do not include examples in their docstrings. Even a simple example can be helpful for a new user, so we should try to include examples wherever possible.

A script called find_functions_missing_examples.py is now maintained in my github repository analyze-scipy-code. This script reports the names of functions that are missing the "Examples" section.

Below is the output that I get when run with the current master branch. Some of these functions have proper docstrings, so all they need is the addition of an "Examples" section containing one or more illustrative examples. Many of them, however, do not comply with the numpy docstring guidelines, and may be missing the "Parameters" and "Returns" sections. In particular, the docstrings of many of the functions in scipy.special are quite terse. Anyone who works on this task should ensure that the final docstring complies with the guidelines. See, for example, #7148, where the sections "Parameters", "Returns" and "Examples" were added to the docstring of scipy.special.gamma.

I have added the tag "good first issue" to this task, because it is usually very easy to add one or two examples to a function. (How to edit the docstring of the functions in scipy.special is not obvious, but take a look at #7148 or #7143 for examples.) The tag does not mean it will be easy to complete this task. As you can see below, there is a lot of work to be done! Anyone who wants to help should feel free to pick a function or two to work on.

The script ignores functions that have the string "is deprecated" in their docstring. The names of other functions that should be ignored can be added to the list skip. If you find such a function, add a comment about it here.

Functions missing "Examples" (last updated 26-May-2024):

scipy version 1.14.0.dev0+1320.0c590f4

datasets (1)
    download_all
fft (7)
    dst
    hfft2
    idst
    ifht
    ihfft2
    irfft2
    rfft2
ndimage (6)
    affine_transform
    generic_filter1d
    generic_gradient_magnitude
    generic_laplace
    morphological_laplace
    watershed_ift
odr (1)
    odr
optimize (5)
    excitingmixing
    fmin_ncg
    fmin_tnc
    linearmixing
    linprog_verbose_callback
signal (22)
    abcd_normalize
    band_stop_obj
    besselap
    buttap
    cheb1ap
    cheb2ap
    cspline2d
    ellipap
    hilbert2
    invres
    invresz
    lfiltic
    medfilt
    qspline2d
    residue
    residuez
    sos2zpk
    ss2zpk
    symiirorder1
    symiirorder2
    vectorstrength
    zpk2ss
sparse (1)
    kronsum
special (134)
    assoc_laguerre
    bdtr
    bdtrc
    bdtri
    bdtrik
    bdtrin
    bei_zeros
    beip
    beip_zeros
    ber_zeros
    berp
    berp_zeros
    btdtria
    btdtrib
    c_roots
    cg_roots
    chebyc
    chebys
    chndtr
    chndtridf
    chndtrinc
    chndtrix
    clpmn
    ellipeinc
    ellipj
    ellipk
    ellipkinc
    ellipkm1
    entr
    eval_chebyt
    eval_chebyu
    eval_gegenbauer
    eval_genlaguerre
    eval_hermite
    eval_hermitenorm
    eval_jacobi
    eval_laguerre
    eval_sh_chebyt
    eval_sh_chebyu
    eval_sh_jacobi
    eval_sh_legendre
    fresnel_zeros
    fresnelc_zeros
    fresnels_zeros
    h_roots
    hankel1
    hankel1e
    hankel2
    hankel2e
    he_roots
    hermitenorm
    j_roots
    jnjnp_zeros
    js_roots
    kei_zeros
    keip
    keip_zeros
    kelvin
    kelvin_zeros
    ker_zeros
    kerp
    kerp_zeros
    kl_div
    l_roots
    la_roots
    lmbda
    loggamma
    lpmn
    lpmv
    lpn
    lqmn
    lqn
    mathieu_a
    mathieu_b
    mathieu_cem
    mathieu_even_coef
    mathieu_modcem1
    mathieu_modcem2
    mathieu_modsem1
    mathieu_modsem2
    mathieu_odd_coef
    mathieu_sem
    modfresnelm
    modfresnelp
    obl_ang1
    obl_ang1_cv
    obl_cv
    obl_cv_seq
    obl_rad1
    obl_rad1_cv
    obl_rad2
    obl_rad2_cv
    pbdn_seq
    pbdv
    pbdv_seq
    pbvv
    pbvv_seq
    pbwa
    pro_ang1
    pro_ang1_cv
    pro_cv
    pro_cv_seq
    pro_rad1
    pro_rad1_cv
    pro_rad2
    pro_rad2_cv
    ps_roots
    rel_entr
    riccati_jn
    riccati_yn
    roots_chebyc
    roots_chebys
    roots_chebyt
    roots_chebyu
    roots_gegenbauer
    roots_genlaguerre
    roots_hermite
    roots_hermitenorm
    roots_jacobi
    roots_laguerre
    roots_sh_chebyt
    roots_sh_chebyu
    roots_sh_jacobi
    roots_sh_legendre
    s_roots
    sh_chebyt
    sh_chebyu
    sh_jacobi
    sh_legendre
    sph_harm
    t_roots
    ts_roots
    u_roots
    us_roots
stats (2)
    epps_singleton_2samp
    kstatvar
stats.mstats (46)
    f_oneway
    friedmanchisquare
    hdmedian
    hdquantiles_sd
    idealfourths
    kendalltau
    kendalltau_seasonal
    ks_1samp
    ks_2samp
    ks_twosamp
    kstest
    kurtosis
    kurtosistest
    mannwhitneyu
    median_cihs
    meppf
    mjci
    moment
    mquantiles_cimj
    msign
    normaltest
    obrientransform
    plotting_positions
    pointbiserialr
    rankdata
    rsh
    scoreatpercentile
    siegelslopes
    skew
    skewtest
    spearmanr
    theilslopes
    trimboth
    trimmed_mean
    trimmed_mean_ci
    trimmed_std
    trimmed_stde
    trimmed_var
    trimr
    trimtail
    tsem
    ttest_1samp
    ttest_ind
    ttest_onesamp
    ttest_rel
    tvar

Found 225 functions

(This issue was created March 13, 2017. At that time, version 0.19.0 had just been released a few days earlier. When I run this script on that version (with 'fft' removed from modules), it finds 674 functions without examples.)

Note: if your PR only adds documentation, please add [docs only] on a new line in the commit message. This will help save our CI credits.

@WarrenWeckesser WarrenWeckesser added Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution task A straightforward change, verification or fix. labels Mar 14, 2017
@pv pv closed this as completed in #7208 Mar 25, 2017
@SKPsanjeevi
Copy link

I am a newbie here. I exactly do not understand what the task is. Are the above commands do not have relevant examples for them?

@WarrenWeckesser
Copy link
Member Author

@pssk1988 Yes. The docstrings of those functions do not have an "Examples" section.

The docstring standard that scipy tries to follow is https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt; in particular, "Sections" defines the sections that should be included in a docstring. "Examples" is the last section described in the docstring standard. According to the numpy docstring standard, "Examples" is an optional section, but many of us think it is a very important section, so we would like to ensure that as many functions as possible include it.

@SKPsanjeevi
Copy link

@WarrenWeckesser Okay. Thats interesting! I will take up a section of them, probably start with simpler ones.

@SKPsanjeevi
Copy link

I just started to add to examples. I forked scipy and performed build as mentioned here. However, while trying to import scipy in Python, I get the following error:

>>> import scipy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named scipy

I know I can do pip install scipy, but that's not the point of building the developer version of scipy, I guess. Can someone help?

@drhagen
Copy link
Contributor

drhagen commented May 20, 2017

The docstring standard that scipy tries to follow is https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt

There doesn't appear to be an example of an Examples section in that reference. Could someone add a few examples to this issue illustrating the desired format for the section to follow? E.g. where does it go relative to the other sections?

@ilayn
Copy link
Member

ilayn commented May 20, 2017

I've casually browsed through the examples in the current docs. It looked like that it comes at the very end after notes and references and Added in version x.xxx. But I'm not sure if this was intentional. It doesn't seem like this behavior is consistent.

I would like to correct the recent examples if this was not the case. To me before notes and references seems a better place content wise but if somebody just looks up the docstring on the prompt, the examples show up as the last thing which is also good avoiding the scroll in case of long Notes sections.

@WarrenWeckesser
Copy link
Member Author

The "Examples" section is the last section. My understanding is that the recommended order of the sections in the docstring is the same as the order they are described at https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt#sections. I'm pretty sure that's the intent, and that's what we've been doing for years. Any exceptions to that were probably accidental.

@ss-is-master-chief
Copy link

ss-is-master-chief commented Dec 3, 2017

@WarrenWeckesser This is my first contribution to an issue, so I started with a simple one. If it caters to the docstrings, how should I ask for a merge?

numpy.average()

"""The following module describes how to use 
the average function of the numpy class"""

# From the existing set of classes we import numpy
import numpy as np
# We can rename numpy as np. Once may use anything

# -----METHOD 1-----
"""What is Average?
average = [Sum of all the elements of array]/[Number of elements in array]"""

# Let us declare an array of integers as follows
data = [1,2,3,4]

# Let us store the average in a variable 'av'
av = np.average(data)

print('The average using Method 1 is:', av)

# -----METHOD 2 - Weights -----
"""What is Weighted Average?
Given data=[1,2,3,4] and weight=[0.1,0.2,0.3,0.4]
average = [(1*0.2)+(2*0.2)+(3*0.3)+(4*0.4)]/[0.1+0.2+0.3+0.4]
"""
# We are going to use the same data as in METHOD 1
# Here we are going to have weight as [0.1,0.2,0.3,0.4]

weight_array = [0.1,0.2,0.3,0.4]

"""SYNTAX for Weighted Average
Weighted_Average = numpy.average(<data_name>, weights = <weight_array>)
Remember, here, 'weights' is a Python Keyword"""

weighted_av = np.average(data, weights = weight_array)

print('The Weighted Average using Method 2 is: ', weighted_av)

@ilayn
Copy link
Member

ilayn commented Dec 3, 2017

@ss-is-master-chief Roughly summarizing:

  • You can start by forking the official SciPy repository. You can simply do it from the upper right corner.
  • Then you create a branch of a name you have chosen. And then you modify the necessary function docstring and commit your changes to that branch.
  • Then you can create a Pull Request and people can review it and suggest changes and if it goes through gets merged with the official repository.

The branch creation is really important because if later on you would like to do something else then we have to sort out subtle conflicts between the master of SciPy and your master branch. Hence, to keep things contained we work in branches and only merge if we are fully sure that it doesn't break anything.

Please have a look at the similar function docstrings for examples. However note that average is a NumPy function so it is not related here.

@ss-is-master-chief
Copy link

@ilayn Could you suggest me some functions which I could work upon?

@ilayn
Copy link
Member

ilayn commented Dec 3, 2017

@ss-is-master-chief Pick your favorite from the list above 😃 (except the linalg ones I'm about to submit a PR for them)

@brunolnetto
Copy link

Suggestion: may we make an up-to-date list of uncovered functions? Thank you! :)

@dschmitz89
Copy link
Contributor

Suggestion: may we make an up-to-date list of uncovered functions? Thank you! :)

The list at the top of this issue is pretty much up to date, only #19433 is not accounted for. From what I see, there are currently two PRs addressing this issue: #19434 and #19058. Any other function you are very much welcome to have a look at :).

@lucascolley lucascolley added the sprint Mentored-Sprint. Please do not work on this unless you're participating to a sprint label Nov 29, 2023
anupriyakkumari added a commit to anupriyakkumari/scipy that referenced this issue Dec 9, 2023
towards scipy#7168

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
anupriyakkumari added a commit to anupriyakkumari/scipy that referenced this issue Dec 9, 2023
towards scipy#7168

Co-authored-by: Daniel Schmitz <40656107+dschmitz89@users.noreply.github.com>
@lucascolley lucascolley removed the sprint Mentored-Sprint. Please do not work on this unless you're participating to a sprint label Dec 11, 2023
@lucascolley
Copy link
Member

lucascolley commented Dec 11, 2023

Can someone update the last line of the issue description from [skip actions] [skip cirrus] to [docs only] please?

@rgommers
Copy link
Member

sure, done

thalassemia pushed a commit to thalassemia/scipy that referenced this issue Jan 10, 2024
towards scipy#7168

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
thalassemia pushed a commit to thalassemia/scipy that referenced this issue Jan 10, 2024
towards scipy#7168

Co-authored-by: Daniel Schmitz <40656107+dschmitz89@users.noreply.github.com>
thalassemia pushed a commit to thalassemia/scipy that referenced this issue Jan 11, 2024
towards scipy#7168

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
thalassemia pushed a commit to thalassemia/scipy that referenced this issue Jan 11, 2024
towards scipy#7168

Co-authored-by: Daniel Schmitz <40656107+dschmitz89@users.noreply.github.com>
mabatalla added a commit to mabatalla/scipy that referenced this issue Jan 24, 2024
scipy#19434.

What does this implement/fix?
Adds example for interpolate.spalde

[skip actions] [skip cirrus]
mabatalla added a commit to mabatalla/scipy that referenced this issue Jan 24, 2024
scipy#19434.

What does this implement/fix?
Adds example for interpolate.spalde. Fixes dosctrings to pass doc build and refgude-check.

[skip actions] [skip cirrus]
mabatalla added a commit to mabatalla/scipy that referenced this issue Jan 24, 2024
… of scipy#19434.

What does this implement/fix?
Adds example for interpolate.spalde and unifies descriptions along the docstrings. Fixes dosctrings to pass doc build and refgude-check.

[skip actions] [skip cirrus]
omarghanem1210 pushed a commit to omarghanem1210/scipy that referenced this issue Mar 28, 2024
scipy#19434.

What does this implement/fix?
Adds example for interpolate.spalde

[skip actions] [skip cirrus]
omarghanem1210 pushed a commit to omarghanem1210/scipy that referenced this issue Mar 28, 2024
scipy#19434.

What does this implement/fix?
Adds example for interpolate.spalde. Fixes dosctrings to pass doc build and refgude-check.

[skip actions] [skip cirrus]
omarghanem1210 pushed a commit to omarghanem1210/scipy that referenced this issue Mar 28, 2024
… of scipy#19434.

What does this implement/fix?
Adds example for interpolate.spalde and unifies descriptions along the docstrings. Fixes dosctrings to pass doc build and refgude-check.

[skip actions] [skip cirrus]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org good first issue Good topic for first contributor pull requests, with a relatively straightforward solution task A straightforward change, verification or fix.
Projects
None yet