Skip to content

Commit f96594b

Browse files
Run pydocstyle in pre-commit (#6382)
* Run `pydocstyle` in pre-commit * Remove pydocstyle settings from `setup.cfg` Includes docstring formatting to reduce the number of error codes that had to be silenced for pydocstyle to be happy. Closes #6378
1 parent adf6fff commit f96594b

30 files changed

+63
-64
lines changed

.pre-commit-config.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ repos:
3535
args: [--rcfile=.pylintrc]
3636
files: ^pymc/
3737
exclude: (?x)(pymc/_version.py)
38+
- repo: https://github.com/PyCQA/pydocstyle
39+
rev: 6.1.1
40+
hooks:
41+
- id: pydocstyle
42+
args:
43+
- --ignore=D100,D101,D102,D103,D104,D105,D107,D200,D202,D203,D204,D205,D209,D212,D213,D301,D400,D401,D403,D413,D415,D417
44+
files: ^pymc/
45+
exclude: ^pymc/tests/
3846
- repo: https://github.com/MarcoGorelli/madforhooks
3947
rev: 0.3.0
4048
hooks:

pymc/blocking.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def rmap(
7979
"""Map 1D concatenated array to a dictionary of variables in their original spaces.
8080
8181
Parameters
82-
==========
82+
----------
8383
array
8484
The array to map.
8585
start_point

pymc/distributions/continuous.py

-1
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,6 @@ class LogNormal(PositiveContinuous):
15931593
15941594
Examples
15951595
--------
1596-
15971596
.. code-block:: python
15981597
15991598
# Example to show that we pass in only ``sigma`` or ``tau`` but not both.

pymc/distributions/discrete.py

-1
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,6 @@ class OrderedLogistic:
15491549
15501550
Examples
15511551
--------
1552-
15531552
.. code-block:: python
15541553
15551554
# Generate data for a simple 1 dimensional example problem

pymc/distributions/dist_math.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,19 @@ def grad(self, inp, grads):
355355
def random_choice(p, size):
356356
"""Return draws from categorical probability functions
357357
358-
Args:
359-
p: array
360-
Probability of each class. If p.ndim > 1, the last axis is
361-
interpreted as the probability of each class, and numpy.random.choice
362-
is iterated for every other axis element.
363-
size: int or tuple
364-
Shape of the desired output array. If p is multidimensional, size
365-
should broadcast with p.shape[:-1].
366-
367-
Returns:
368-
random sample: array
358+
Parameters
359+
----------
360+
p : array
361+
Probability of each class. If p.ndim > 1, the last axis is
362+
interpreted as the probability of each class, and numpy.random.choice
363+
is iterated for every other axis element.
364+
size : int or tuple
365+
Shape of the desired output array. If p is multidimensional, size
366+
should broadcast with p.shape[:-1].
367+
368+
Returns
369+
-------
370+
random_sample : array
369371
370372
"""
371373
k = p.shape[-1]

pymc/distributions/distribution.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def _get_measurable_outputs_symbolic_random_variable(op, node):
413413
@node_rewriter([SymbolicRandomVariable])
414414
def inline_symbolic_random_variable(fgraph, node):
415415
"""
416-
This optimization expands the internal graph of a SymbolicRV when obtaining the logp
416+
Optimization that expands the internal graph of a SymbolicRV when obtaining the logp
417417
graph, if the flag `inline_logprob` is True.
418418
"""
419419
op = node.op
@@ -828,7 +828,6 @@ class CustomDist:
828828
829829
Examples
830830
--------
831-
832831
Create a CustomDist that wraps a black-box logp function. This variable cannot be
833832
used in prior or posterior predictive sampling because no random function was provided
834833

pymc/distributions/multivariate.py

-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ class OrderedMultinomial:
796796
797797
Examples
798798
--------
799-
800799
.. code-block:: python
801800
802801
# Generate data for a simple 1 dimensional example problem

pymc/distributions/transforms.py

-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ class Interval(IntervalTransform):
240240
241241
Examples
242242
--------
243-
244243
Create an interval transform between -1 and +1
245244
246245
.. code-block:: python

pymc/distributions/truncated.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030

3131

3232
class TruncatedRV(SymbolicRandomVariable):
33-
"""An `Op` constructed from an PyTensor graph that represents a truncated univariate
34-
random variable."""
33+
"""
34+
An `Op` constructed from an PyTensor graph
35+
that represents a truncated univariate random variable.
36+
"""
3537

3638
default_output = 1
3739
base_rv_op = None

pymc/gp/util.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def plot_gp_dist(
188188
):
189189
"""A helper function for plotting 1D GP posteriors from trace
190190
191-
Parameters
191+
Parameters
192192
----------
193193
ax: axes
194194
Matplotlib axes.
@@ -213,7 +213,6 @@ def plot_gp_dist(
213213
214214
Returns
215215
-------
216-
217216
ax: Matplotlib axes
218217
"""
219218
import matplotlib.pyplot as plt

pymc/logprob/abstract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def assign_custom_measurable_outputs(
194194
`factorized_joint_logprob`.
195195
196196
Parameters
197-
==========
197+
----------
198198
node
199199
The node to recreate with a new cloned `Op`.
200200
measurable_outputs_fn

pymc/logprob/joint_logprob.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def factorized_joint_logprob(
9595
9696
9797
Parameters
98-
==========
98+
----------
9999
rv_values
100100
A ``dict`` of variables that maps stochastic elements
101101
(e.g. `RandomVariable`\s) to symbolic `Variable`\s representing their
@@ -111,7 +111,7 @@ def factorized_joint_logprob(
111111
etc.)
112112
113113
Returns
114-
=======
114+
-------
115115
A ``dict`` that maps each value variable to the log-probability factor derived
116116
from the respective `RandomVariable`.
117117

pymc/logprob/rewriting.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868

6969
class NoCallbackEquilibriumDB(EquilibriumDB):
70-
r"""This `EquilibriumDB` doesn't hide its exceptions.
70+
r"""An `EquilibriumDB` that doesn't hide its exceptions.
7171
7272
By setting `failure_callback` to ``None`` in the `EquilibriumGraphRewriter`\s
7373
that `EquilibriumDB` generates, we're able to directly emit the desired
@@ -102,7 +102,7 @@ class PreserveRVMappings(Feature):
102102
def __init__(self, rv_values: Dict[TensorVariable, TensorVariable]):
103103
"""
104104
Parameters
105-
==========
105+
----------
106106
rv_values
107107
Mappings between random variables and their value variables.
108108
The keys of this map are what this `Feature` keeps updated.
@@ -130,7 +130,7 @@ def update_rv_maps(
130130
original value variables.
131131
132132
Parameters
133-
==========
133+
----------
134134
old_rv
135135
The random variable whose mappings will be updated.
136136
new_value

pymc/logprob/scan.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def convert_outer_out_to_in(
7979
r"""Convert outer-graph outputs into outer-graph inputs.
8080
8181
Parameters
82-
==========
82+
----------
8383
input_scan_args:
8484
The source `Scan` arguments.
8585
outer_out_vars:
@@ -253,7 +253,7 @@ def get_random_outer_outputs(
253253
"""Get the `MeasurableVariable` outputs of a `Scan` (well, its `ScanArgs`).
254254
255255
Returns
256-
=======
256+
-------
257257
A tuple of tuples containing the index of each outer-output variable, the
258258
outer-output variable itself, and the inner-output variable that
259259
is an instance of `MeasurableVariable`.
@@ -329,7 +329,7 @@ def create_inner_out_logp(value_map: Dict[TensorVariable, TensorVariable]) -> Te
329329

330330
@node_rewriter([Scan])
331331
def find_measurable_scans(fgraph, node):
332-
r"""Finds `Scan`\s for which a `logprob` can be computed.
332+
r"""Find `Scan`\s for which a `logprob` can be computed.
333333
334334
This will convert said `Scan`\s into `MeasurableScan`\s. It also updates
335335
random variable and value variable mappings that have been specified for

pymc/logprob/transforms.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def __init__(
295295
):
296296
"""
297297
Parameters
298-
==========
298+
----------
299299
values_to_transforms
300300
Mapping between value variables and their transformations. Each
301301
value variable can be assigned one of `RVTransform`, or ``None``.
@@ -514,7 +514,7 @@ def __init__(self, args_fn: Callable[..., Tuple[Optional[Variable], Optional[Var
514514
"""
515515
516516
Parameters
517-
==========
517+
----------
518518
args_fn
519519
Function that expects inputs of RandomVariable and returns the lower
520520
and upper bounds for the interval transformation. If one of these is
@@ -660,7 +660,7 @@ def _create_transformed_rv_op(
660660
also behaving exactly as it did before.
661661
662662
Parameters
663-
==========
663+
----------
664664
rv_op
665665
The `RandomVariable` for which we want to construct a `TransformedRV`.
666666
transform

pymc/logprob/utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def walk_model(
6262
By default, these walks will not go past ``MeasurableVariable`` nodes.
6363
6464
Parameters
65-
==========
65+
----------
6666
graphs
6767
The graphs to walk.
6868
walk_past_rvs
@@ -104,12 +104,12 @@ def replace_rvs_in_graphs(
104104
This will *not* recompute test values.
105105
106106
Parameters
107-
==========
107+
----------
108108
graphs
109109
The graphs in which random variables are to be replaced.
110110
111111
Returns
112-
=======
112+
-------
113113
A ``tuple`` containing the transformed graphs and a ``dict`` of the
114114
replacements that were made.
115115
"""
@@ -154,7 +154,7 @@ def rvs_to_value_vars(
154154
This will *not* recompute test values in the resulting graphs.
155155
156156
Parameters
157-
==========
157+
----------
158158
graphs
159159
The graphs in which to perform the replacements.
160160
initial_replacements

pymc/math.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def kron_matrix_op(krons, m, op):
196196
r"""Apply op to krons and m in a way that reproduces ``op(kronecker(*krons), m)``
197197
198198
Parameters
199-
-----------
199+
----------
200200
krons : list of square 2D array-like objects
201201
D square matrices :math:`[A_1, A_2, ..., A_D]` to be Kronecker'ed
202202
:math:`A = A_1 \otimes A_2 \otimes ... \otimes A_D`

pymc/model.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class ContextMeta(type):
153153
"""
154154

155155
def __new__(cls, name, bases, dct, **kwargs): # pylint: disable=unused-argument
156-
"Add __enter__ and __exit__ methods to the class."
156+
"""Add __enter__ and __exit__ methods to the class."""
157157

158158
def __enter__(self):
159159
self.__class__.context_class.get_contexts().append(self)
@@ -457,7 +457,6 @@ class Model(WithMemoization, metaclass=ContextMeta):
457457
458458
Examples
459459
--------
460-
461460
How to define a custom model
462461
463462
.. code-block:: python
@@ -1356,7 +1355,7 @@ def make_obs_var(
13561355
"""Create a `TensorVariable` for an observed random variable.
13571356
13581357
Parameters
1359-
==========
1358+
----------
13601359
rv_var
13611360
The random variable that is observed.
13621361
Its dimensionality must be compatible with the data already.
@@ -1808,7 +1807,7 @@ def point_logps(self, point=None, round_vals=2):
18081807

18091808

18101809
class BlockModelAccess(Model):
1811-
"""This class can be used to prevent user access to Model contexts"""
1810+
"""Can be used to prevent user access to Model contexts"""
18121811

18131812
def __init__(self, *args, error_msg_on_access="Model access is blocked", **kwargs):
18141813
self.error_msg_on_access = error_msg_on_access
@@ -1829,7 +1828,6 @@ def set_data(new_data, model=None, *, coords=None):
18291828
18301829
Examples
18311830
--------
1832-
18331831
This example shows how to change the shape of the likelihood to correspond automatically with
18341832
`x`, the predictor in a regression model.
18351833

pymc/model_graph.py

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def get_plates(self, var_names: Optional[Iterable[VarName]] = None) -> Dict[str,
199199
200200
Just groups by the shape of the underlying distribution. Will be wrong
201201
if there are two plates with the same shape.
202+
202203
Returns
203204
-------
204205
dict

pymc/ode/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
This submodule contains tools used to perform inference on ordinary differential equations.
2+
Contains tools used to perform inference on ordinary differential equations.
33
44
Due to the nature of the model (as well as included solvers), ODE solution may perform slowly.
55
Another library based on PyMC--sunode--has implemented Adams' method and BDF (backward differentation formula) using the very fast SUNDIALS suite of ODE and PDE solvers.

pymc/ode/ode.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class DifferentialEquation(Op):
4242
4343
Parameters
4444
----------
45-
4645
func : callable
4746
Function specifying the differential equation. Must take arguments y (n_states,), t (scalar), p (n_theta,)
4847
times : array
@@ -57,7 +56,6 @@ class DifferentialEquation(Op):
5756
5857
Examples
5958
--------
60-
6159
.. code-block:: python
6260
6361
def odefunc(y, t, p):
@@ -108,7 +106,7 @@ def __init__(self, func, times, *, n_states, n_theta, t0=0):
108106
self._output_sensitivities = {}
109107

110108
def _system(self, Y, t, p):
111-
r"""This is the function that will be passed to odeint. Solves both ODE and sensitivities.
109+
r"""The function that will be passed to odeint. Solves both ODE and sensitivities.
112110
113111
Parameters
114112
----------

pymc/pytensorf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def walk_model(
203203
"""Walk model graphs and yield their nodes.
204204
205205
Parameters
206-
==========
206+
----------
207207
graphs
208208
The graphs to walk.
209209
stop_at_vars
@@ -235,12 +235,12 @@ def _replace_rvs_in_graphs(
235235
This will *not* recompute test values.
236236
237237
Parameters
238-
==========
238+
----------
239239
graphs
240240
The graphs in which random variables are to be replaced.
241241
242242
Returns
243-
=======
243+
-------
244244
Tuple containing the transformed graphs and a ``dict`` of the replacements
245245
that were made.
246246
"""
@@ -296,7 +296,7 @@ def rvs_to_value_vars(
296296
This will *not* recompute test values in the resulting graphs.
297297
298298
Parameters
299-
==========
299+
----------
300300
graphs
301301
The graphs in which to perform the replacements.
302302
apply_transforms

0 commit comments

Comments
 (0)