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

pre-commit hook for docstring format #1944

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Qazalbash
Copy link
Contributor

This hook will format the docstrings. See PyCQA/docformatter#265 for multiline docstring format.

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what the max length is?

Number of hits has a Binomial distribution with independent
probability of success, $\phi_i$. Each $\phi_i$ follows a Beta
r"""Number of hits has a Binomial distribution with independent probability of success, $\phi_i$. Each $\phi_i$
follows a Beta.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the format is wrong - this is "Beta distribution".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems to be wrong. It also messed with the license which failed the CI.

Copy link
Member

@fehiepsi fehiepsi Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re license: maybe update those lines: https://github.com/pyro-ppl/numpyro/blob/master/scripts/update_headers.py#L54-L57 ?

if lineno < len(lines) and not lines[lineno].isspace() and not lines[lineno] == '"""\n':

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in abef925.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still failing, my jugaad was to add a comment before the docstring that will create a line between the license header and the docstring.

@Qazalbash
Copy link
Contributor Author

Qazalbash commented Jan 2, 2025

Do you know what the max length is?

I have set it to 120 in the pyproject.toml (minus 4 for tabs).

@fehiepsi
Copy link
Member

fehiepsi commented Jan 2, 2025

Could you change it to 88 instead? Currently, we use 88 for ruff https://github.com/pyro-ppl/numpyro/blob/master/pyproject.toml#L34

@Qazalbash
Copy link
Contributor Author

Sure, let me push the updated code!

Lotka–Volterra equations. Real positive parameters `alpha`, `beta`, `gamma`, `delta`
"""Lotka–Volterra equations.
Real positive parameters `alpha`, `beta`, `gamma`, `delta`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this line is shorter than the other ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the formatter takes the first sentence as a summary and the rest of the docstring as an extended summary.

pass


class RBFKernel(SteinKernel):
"""Calculates the Gaussian RBF kernel function used in [1]. The kernel is given by
"""Calculates the Gaussian RBF kernel function used in [1]. The kernel is given
by.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no dot at the end here I think. Maybe move The kernel is given by to a new paragraph.

@@ -119,7 +116,7 @@ def mode(self):


class IMQKernel(SteinKernel):
"""Calculates the IMQ kernel from Theorem 8 of [1]. The kernel is given by
"""Calculates the IMQ kernel from Theorem 8 of [1]. The kernel is given by.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for here

@@ -161,8 +158,7 @@ def kernel(x, y):


class LinearKernel(SteinKernel):
"""
Calculates the linear kernel from Theorem 3.3 in [1]. The kernel is given by
"""Calculates the linear kernel from Theorem 3.3 in [1]. The kernel is given by.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like above

@@ -191,7 +187,8 @@ def kernel(x, y):


class RandomFeatureKernel(SteinKernel):
"""Calculates the Gaussian variate of random kernel in eq. 5 and 6 of [1]. The kernel is given by
"""Calculates the Gaussian variate of random kernel in eq. 5 and 6 of [1]. The
kernel is given by.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like above


[1] https://en.wikipedia.org/wiki/Matrix_normal_distribution
:param array_like scale_tril_column: Lower cholesky of columns correlation
matrix. **References** [1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference should be in a separate paragraph

[1] https://github.com/pymc-devs/pymc/blob/244fb97b01ad0f3dadf5c3837b65839e2a59a0e8/pymc/distributions/transforms.py#L266
[2] https://www.pymc.io/projects/docs/en/stable/api/distributions/generated/pymc.ZeroSumNormal.html
[3] https://learnbayesstats.com/episode/74-optimizing-nuts-developing-zerosumnormal-distribution-adrian-seyboldt/
**References** [1] https://github.com/pymc-devs/pymc/blob/244fb97b01ad0f3dad
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference should be in a separate paragraph


*** References *** [1] Luc Devroye "Non-Uniform Random Variate Generation",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference should be in a separate paragraph

**References:**

[1] On Markov chain Monte Carlo Methods For Tall Data
**References:** [1] On Markov chain Monte Carlo Methods For Tall Data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference should be in a separate paragraph

This `Differential evolution proposal
<http://www.stat.columbia.edu/~gelman/stuff_for_blog/cajo.pdf>`_ is
implemented following `Nelson et al. (2013)
"""A proposal using differential evolution.\n\nThis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would \n\n be the right thing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run the pre-commit multiple times in a row, the docformatter pushes the line starting with "is" one space to the right each time, causing the pre-commit to fail. This is due to the max length we have set. I found this trick to reproduce the same docstring while rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants