8

I'm using sphinx autodoc extension together with sphinx.ext.napoleon. I'm following numpydoc style guide since I think it is more readable than google's one. However, I've noticed the following issue which I wasn't able to fix.

I have the following question. Is it possible to allow in a Parameters section (or Returns etc) to have a list? I would like to have something like:

UPDATE I've removed some initial issues according to Steve Piercy's answer. Here is the python file:

class Test:

def f(param_1, param_2):

    r"""
    This is a test docstring.

    Parameters
    ----------
    param_1 : pandas data frame
        This would be really cool to allow the following list and make
        it more readable:

        * **index:** Array-like, integer valued representing
          days. Has to be sorted and increasing.
        * **dtype:** float64. Value of temperature.
        * **columns:** location description, e.g. 'San Diego'
    param_2 : int
        nice number!
    """
    pass

Unfortunately this still gives the issue that the font of "This would be..." is too large and not placed next to param_1 as for param_2:

enter image description here

If I remove the bullet list I get a properly looking output. Changing the above code to:

class Test:

    def f(param_1, param_2):

        r"""
        This is a test docstring.

        Parameters
        ----------
        param_1 : pandas data frame
            This would be really cool to allow the following list and make
            it more readable: **index:** Array-like, integer valued representing
            days. Has to be sorted and increasing. **dtype:** float64. Value of temperature.
            **columns:** location description, e.g. 'San Diego'
        param_2 : int
            nice number!
        """
        pass

which leads to the following proper output:

enter image description here

The .rst file to generate the documentation is simply:

.. automethod:: test.Test.f

If I'm using numpydoc instead of sphinx.ext.napleon it seems I get a correct output:

enter image description here

at least the font of "pandas data frame" and "This...." is the same. However I would prefer the napoleon style where everything is smaller and no grey line at the beginning.

Finally also deleting the blank line before the bullet points doesn't help. It makes it worse:

enter image description here

bad_coder
  • 11,289
  • 20
  • 44
  • 72
math
  • 1,868
  • 4
  • 26
  • 60

1 Answers1

0

It looks like you are not following the example NumPy Style Python Docstrings.

  • Parameters should have no spaces in their names.
  • The Python type should be valid (I am uncertain about "pandas data frame"
  • There should be no blank line above param 2
Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • many thanks for your help. I resolved your first and third bullet point and changed the "pandas data frame" to "int". However, I still get the same as in picture one above. – math Oct 26 '17 at 09:58
  • Let's see the code in an update to your question, and a screenshot. Also remove any blank lines, then try removing the bullet list temporarily, just to see if that gives a proper display without the list. IOW a known good syntax example should display properly. – Steve Piercy Oct 26 '17 at 10:30
  • I've updated my answer with the full code. Removing the bullet list works. Hope this is helpful. Many thanks for your help – math Oct 26 '17 at 11:43
  • I guess that the parser chokes on the type of "pandas data frame" because it has spaces in it. Try removing spaces, "pandas.data.frame", or "pandas_data_frame". Does that help? White space matters, especially in docstrings. – Steve Piercy Oct 26 '17 at 19:57
  • I even changed it to `int` as for param_2 but I get the same result (big font, and not next to the "-". – math Oct 26 '17 at 20:38
  • Did you try removing the blank line before the bullet list? I'm making wild guesses here. Another help resource might be in the [issue tracker for Sphinx](https://github.com/sphinx-doc/sphinx/issues/). – Steve Piercy Oct 27 '17 at 11:06
  • yes I did. It makes it even worse, pls see last added picture. – math Oct 27 '17 at 12:00
  • Bummer. Your options are (1) dive into the source code of `sphinx.ext.napoleon` and Sphinx to identify and resolve the parsing and rendering, then submit a PR to fix the issue, (2) submit an issue only at the appropriate issue tracker, (3) use plain old docstring syntax without the extension, (4) live with it, or (5) something else. Sorry, I've exhausted my knowledge. – Steve Piercy Oct 27 '17 at 21:01
  • in any case thanks for the help. really appreciated it. I might open an issue on github. – math Oct 28 '17 at 07:54
  • The numpy example link is dead, is there an updated link? – Ken Williams Nov 12 '19 at 04:16