Skip to content

Add distribution parameters as named positional arguments #5880

@thomasaarholt

Description

@thomasaarholt

Description of your problem

PyMC sideliner here, who is finally taking a proper crack at it with 4.0. I find the distribution docstrings difficult to parse when viewing them in my editor. As an example, the Bernoulli distribution in jupyter notebook (I imagine a lot of people are using notebooks):

import pymc as pm
pm.Bernoulli()

image

And with VSCode (I am using this):
image

Two points:

  1. My main gripe is with the arguments being shown as pm.Bernoulli(name, *args, **kwargs)/(name: Unknown, *args: Unknown, **kwargs: Unknown) -> TensorVariable. It would be much nicer to actually show the parameters taken by the distribution (in this case, p).
  2. The second point is a bit more complicated: VSCode tries to show the docstring of the __init__ method rather than the class docstring*. Since Bernoulli doesn't have an explicit init method, it inherits from the first one it finds, which seems to be the __new__ method of the Distribution class. Note that if you position the cursor (|) as Bernoulli|() when invoking the documentation, you get the Bernoulli class docs and not the parent new doc. It would be nice to supply a simple docstring to the init method in order to override the confusing parent DIstribution docstring.

I am quite happy to take a crack at this, though I do recognise that there are several other issues concerned with similar things #5308, #5353, #5358)

  • class docstring vs init docstring:
class A:
    "class docstring"
    def __init__(self, a: int, b: str = "hi"):
        "init docstring"
        print(a, b)

Versions and main components

  • PyMC/PyMC3 Version: 4.0
  • Python Version: 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    majorInclude in major changes release notes section

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions